简体   繁体   English

如何在终端中输入/输入特殊字符 ETB(ASCII 23)作为字符?

[英]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?如何在 Linux 终端中输入/输入 EOT(End of Trans)(ASCII 23)?

Every time, when I use the alt + 23 to input, all the char I put before will be clean.每次当我用alt + 23输入时,我之前输入的所有字符都会是干净的。

For example, after inputing ikl , if input EOT by the method above, all the string is clean.比如输入ikl ,如果按照上面的方法输入 EOT,那么所有的字符串都是干净的。

ASCII 23 is CTRL-W, which is "delete word" in many contexts. ASCII 23 是 CTRL-W,在许多情况下是“删除单词”。

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.如果它处于熟模式,或者在其后面带有典型外壳(如 bash)的原始模式,则在输入前加上 CTRL-V(或任何stty -a报告lnext )应该可以解决问题。

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.在终端窗口或文本控制台中输入的字符在到达提示输入的 C 代码之前要经过多层解释。

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() .如果您使用getc()从用户那里读取字符,或更准确地说bytes ,则它们经过的最后一步是缓冲,可以使用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 - \\ ...).当这些字节来自终端时,终端设备处理程序会执行一个额外的缓冲步骤,从简单的退格处理到更复杂的行编辑功能,以及处理信号( Ctrl - CCtrl - ZCtrl - \\ ...)。 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.大多数终端将处理emacs的行编辑绑定: Ctrl - A行首, Ctrl - E行尾, Ctrl - K杀行结束, Ctrl - Y猛拉(粘贴)...尽管不是 emacs 绑定Ctrl - W用于kill-word-backward。

Hence you cannot type Ctrl - W to enter ASCII 23 (EOT) at the terminal prompt without some specific work-around:因此,如果没有一些特定的解决方法,您不能在终端提示符下键入Ctrl - W来输入 ASCII 23 (EOT):

  • 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.您可以使用tcsetattr()将终端设置为原始模式,使用户输入的每个字节都可用于程序,无论是否在标准流中缓冲。
  • 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.用户可以在Ctrl - W之前键入Ctrl - V以告诉终端设备驱动程序绕过Ctrl - W组合键的处理。

In both cases, a newline may be required for the characters typed in the terminal window to become available for a pending getc() .在这两种情况下,在终端窗口中键入的字符可能需要换行符才能用于挂起的getc()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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