Using rlwrap with Node.js REPL, how does node '.break' (Ctrl-C) not be interpreted as SIGINT by rlwrap?

After this discussion on how to save command line history between sessions , I defined the following alias:

alias node='env NODE_NO_READLINE=1 rlwrap node'

It works great for saving history, but now, every time I do Ctrl-C to send the node '.break' command, rlwrap takes it too, but like SIGINT: it clears everything and suicides (as described in its man page ) that made me restart the node session (I need to call my var, funcs, require, etc.), and I just wanted ".break" ...

How to return classic node behavior?

  • Ctrl-C: breaks
  • Ctrl-C again (or on an empty line): exit
+3
source share
1 answer

SIGINT Avoidance

nodechanges the value CTRL-Cby disabling the interruptVINTR character (usually CTRL-C) to avoid the interrupt signal that it might receive.

After you start rlwrapgoing to sleep all the time, until something happens to your terminal or pseudo ( ptys) used, for example node. This "something" can be a keystroke or displayed with node.

Each time this happens, it rlwrapwill copy the terminal settings nodes(including VINTR)) to its own tty.

, node , rlwrap, , , . : CTRL-C rlwrap, SIGINT, node .break.

, pty (EXTPROC), pty (rlwrap) , . , 0.41, rlwrap --polling, 40 .

CTRL-C

0.43, rlwrap , readline rlwrap-direct-keypress ~/.inputrc:

$if node
   "\C-c": rlwrap-direct-keypress
$endif

node CTRL+C, readline ( NODE_NO_READLINE=1 node, CTRL-C), , )

(.. ), rlwrap :

$ rlwrap --always-readline node

, , keypresses (Continue? Y/N) extra Enter.

, : , node CTRL-C ( SIGINT)

. :

stty intr undef # disable interrupt character
rlwrap --always-readline node
stty intr '^c'  # re-enable CTRL-C

 rlwrap --polling --always-readline node # --polling means: continually wake up and wacth  node interrupt character

:

  • "\C-c": rlwrap-direct-keypress inputc
  • rlwrap --polling --always-readline,
  • Enter
+3

All Articles