0

~(ICANON) モードに設定された端末があり、バックスペース用に取得したデータ (^?) をどのように使用できるか疑問に思っているので、コンソールに putchar('\b') を送信して移動できます1 スペース戻ります。

編集:

struct termios new;
newt.c_lflag &= ~(ICANON);
tcsetattr(STDIN_FILENO, TCSANOW, &newt); // Set the console to send each char straight away.

char c;
while ((c = getchar()) != '\n){
   // If the backspace key is pressed, the symbols ^? appear on the screen. How do I
   // Interpret the backspace to send back a '\b' char to the screen. I don't want the ^?
   // to appear on the screen when the backspace is pressed but rather the cursor move one
   // space to the left.
}

ありがとう

4

1 に答える 1

1

ターミナルが raw モード ( ~ICANON) の場合、BkSpキーは byte を出力しますが0x7f、これはターミナルによってバックスペースとして解釈されません。(これは、キーストロークと区別できるようにするため^Hです。) このキーストロークを端末でバックスペースとして解釈する場合は、次のようにする必要があります。

  1. ~ECHO端末 ( ) でエコーを無効にしてから、
  2. ほとんどの文字は入力時にエコー バックしますが、( )0x7fとしてエコーします。(おそらく echo asも必要になるでしょう。)0x08\b\n\r\n
于 2014-03-22T06:51:17.860 に答える