Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

piping content to script incompatible with blessed #39

Closed
udondan opened this issue Feb 25, 2014 · 3 comments
Closed

piping content to script incompatible with blessed #39

udondan opened this issue Feb 25, 2014 · 3 comments

Comments

@udondan
Copy link

udondan commented Feb 25, 2014

I am trying to pipe content to my script

echo "foo" | ui

Which gives me this error, when I init blessed:

/path/node_modules/blessed/lib/program.js:241
    throw new Error('Not a terminal.');
          ^
Error: Not a terminal.
    at Program.listen (/path/node_modules/blessed/lib/program.js:241:11)
    at new Program (/path/node_modules/blessed/lib/program.js:89:8)
    at Program (/path/node_modules/blessed/lib/program.js:28:12)
    at new Screen (/path/node_modules/blessed/lib/widget.js:256:20)
    at Function.Screen (/path/node_modules/blessed/lib/widget.js:245:12)
    at init (/path/includes/uilib.js:17:25)
    at initUI (/path/bin/ui:25:6)
    at Object.<anonymous> (/path/bin/ui:388:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

And that makes sense, because I use the same condition to actually check if the user piped something to my script.

I tried to disable this check in program.js which brings up these lines:

TypeError: Object #<Socket> has no method 'setRawMode'
    at Program.fn (/path/node_modules/blessed/lib/program.js:288:20)
    at Program.EventEmitter.emit (events.js:117:20)
    at Program.EventEmitter.addListener (events.js:138:10)
    at Screen._listenMouse (/path/node_modules/blessed/lib/widget.js:440:16)
    at ScrollableBox.fn (/path/node_modules/blessed/lib/widget.js:1808:19)
    at ScrollableBox.EventEmitter._emit (/path/node_modules/blessed/lib/events.js:86:20)
    at ScrollableBox.EventEmitter.addListener (/path/node_modules/blessed/lib/events.js:25:8)
    at Screen.setEffects (/path/node_modules/blessed/lib/widget.js:1602:7)
    at /path/node_modules/blessed/lib/widget.js:1849:17
    at Array.forEach (native)

Removing that line as well, lets my script run w/o errors, but blessed is not able to catch any keystrokes or mouseactions correctly. Instead it shows some controll characters on top of my UI

^[[M#?=^[[M }8^[[MC}8^[[M#}8^[[Ma?B^[[Ma?B^[[Ma?B^[[Ma?B^[[M`?B^[[M`?Bafc

I have no clue about TTYs. Is this something that can be done or is there no chance getting content from pipe and then open up an interactive UI where the user can actually interact with the content he just piped? I guess (hope!) it is possible since all user actions are actually catched but simply not interpreted correctly.

@dbkaplun
Copy link
Collaborator

dbkaplun commented Jun 5, 2014

👍 I can confirm this issue.

@AdrianSchneider
Copy link

After struggling with the same problem for a little while, I've gotten this working over at jsonfui --

If you pipe in content, the stdin stream is dedicated to that input. That can't change. Instead, you want to tell blessed to read from the active terminal (/dev/tty) instead of standard input (/dev/stdin).

Blessed supports this by accepting an input option on screen. While it defaults to process.stdin, you can pass in a reference to the terminal input instead.

I found the ttys module wraps this behaviour quite nicely if you want to be able to have the same code for either case (stdin or dev/ttyl if stdin is not a tty).

Cheers

@chjj
Copy link
Owner

chjj commented Aug 4, 2015

@AdrianSchneider, blessed no longer throws an error when input/output isn't a TTY. Try the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants