Skip to content
This repository

readline completions after Control-Z #3295

Closed
josher19 opened this Issue · 2 comments

4 participants

josher19 Bert Belder Ben Noordhuis Nathan Rajlich
josher19

Sending a script to the background with CTRL-Z (SIGTSTP) and bringing it back to the foreground will result in readline completions behaving strangely.

Related: #2757

There is a simple work-around for node v6.7 :

var tty=require('tty');
tty.setRawMode(false); 
tty.setRawMode(true);

Need to do both. Just doing tty.setRawMode(true) does not fix the problem.

Hopefully this simple fix will also work on node v7.

However, this sometimes results in characters getting echoed to the terminal twice
in some libraries that rely on readline (such as CoffeeScript and LiveScript).

Example of problem & solution:

joshua@jsw-desktop:~$ node
> var tty=require('tty')
undefined
> reset = function() { tty.setRawMode(false); tty.setRawMode(true); }
[Function]
> // hit Ctrl-Z
undefined
> 
[1]+  Stopped                 node
joshua@jsw-desktop:~$ # resume process
joshua@jsw-desktop:~$ fg
node


undefined
> ^P
> // hit Ctrl-Z^N
> ^P^P^P
> // hit Ctrl-Z^P^P
> reset = function() { tty.setRawMode(false); tty.setRawMode(true); }^N
> // hit Ctrl-Z^N
> reset()
reset()
undefined
> // now ^N (next line) and ^P (previous line) work normally
Bert Belder
Collaborator
Ben Noordhuis

Confirmed. Happens with master, too.

It's kind of expected: suspending the process and returning control to the shell clobbers the terminal settings. The problem is that SIGSTP and SIGCONT cannot be caught or (reliably) detected.

A workaround is to have the REPL install a check watcher that resets the terminal after each tick of the event loop. That's kind of hackish, though.

Nathan Rajlich TooTallNate referenced this issue from a commit in TooTallNate/node
Nathan Rajlich TooTallNate repl: preserve the cursor when redisplaying the prompt on SIGCONT
Otherwise the cursor position was being reset to 0, even when there was
already part of a line, which was strange.

Part of #3295.
e770f09
Nathan Rajlich TooTallNate referenced this issue from a commit
Nathan Rajlich TooTallNate repl: preserve the cursor when redisplaying the prompt on SIGCONT
Otherwise the cursor position was being reset to 0, even when there was
already part of a line, which was strange.

Part of #3295.
a608f65
josher19 josher19 referenced this issue in gkz/LiveScript
Closed

null === null thows TypeError #155

Matt Ginzton metamatt referenced this issue in fish-shell/fish-shell
Closed

cat: stdin: Resource temporarily unavailable #176

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.