1

I am building a Node.js App. I'm trying to read STDIN buffer, parse it and then start my blessed program, but if I trying to read STDIN my blessed program closed instantly. Also, input doesn't work.

Here is an example:

// Read stdin into buff
const stdin = process.stdin
stdin.setEncoding('utf8')

let buff = ''
function read() {
  let chunk

  while ((chunk = stdin.read())) {
    buff += chunk
  }
}

stdin.on('readable', read)

stdin.on('end', () => {
  input = buff
})

Create some app:

const program = blessed.program()
const screen = blessed.screen({
  program: program,
  smartCSR: true,
})

// Add box with mouse and keys events, etc.

Run program echo something | node index.js. App is closing instantly.

Anton Medvedev
  • 3,393
  • 3
  • 28
  • 40

1 Answers1

4

Found solution myself:

const ttyFd = fs.openSync('/dev/tty', 'r+')

  const program = blessed.program({
    input: tty.ReadStream(ttyFd),
    output: tty.WriteStream(ttyFd),
  })

  const screen = blessed.screen({
    program: program,
    smartCSR: true,
  })
Anton Medvedev
  • 3,393
  • 3
  • 28
  • 40