简体   繁体   中英

How to enter/input special char ETB(ASCII 23) as a char in terminal?

How to enter/input the EOT(End of Trans)(ASCII 23) in the Linux terminal?

Every time, when I use the alt + 23 to input, all the char I put before will be clean.

For example, after inputing ikl , if input EOT by the method above, all the string is clean.

ASCII 23 is CTRL-W, which is "delete word" in many contexts.

An exact answer depends on exactly what input mode the terminal is in and, if it's in raw mode, which program is ultimately interpreting the input. If it's in cooked mode, or in raw mode with a typical shell (like bash) behind it, prefixing the input with CTRL-V (or whatever stty -a reports for lnext ) should do the trick.

Characters entered in the terminal window or the text console go though many layers of interpretation before they reach the C code that prompted the input.

If you read characters, or more precisely bytes , from the user with getc() , the last step they go through is buffering, which can be controlled with setvbuf() .

When these bytes come from the terminal, an extra buffering step is performed by the terminal device handler from simple backspace handling to more elaborate line editing features, and process signalling ( Ctrl - C , Ctrl - Z , Ctrl - \\ ...). Most terminals will handle the line editing bindings of emacs : Ctrl - A beginning-of-line, Ctrl - E end-of-line, Ctrl - K kill-end-of-line, Ctrl - Y yank (paste)... and albeit not an emacs binding Ctrl - W for kill-word-backward.

Hence you cannot type Ctrl - W to enter ASCII 23 (EOT) at the terminal prompt without some specific work-around:

  • you can set the terminal in raw mode with tcsetattr() , making each byte available to the program as it is typed by the user, with or without buffering in the standard stream.
  • the user can type Ctrl - V before the Ctrl - W to tell the terminal device driver to bypass handling of the Ctrl - W key combination.

In both cases, a newline may be required for the characters typed in the terminal window to become available for a pending getc() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM