title: C++ noncanonical terminal read() specific keys
body: <p>I have the following code:</p>
  <pre><code>int setmode(int vtime, int vmin, int echo, int sigint)
  {
      termios attr;
      tcgetattr(STDIN_FILENO, &amp;attr);
  
      attr.c_lflag &amp;= ~ICANON;
      if (echo)
          attr.c_lflag |= ECHO;
      else
          attr.c_lflag &amp;= ~ECHO;
      if (sigint)
          attr.c_lflag |= ISIG;
      else
          attr.c_lflag &amp;= ~ISIG;
      attr.c_cc[VMIN] = vmin;
      attr.c_cc[VTIME] = vtime;
      tcsetattr(STDIN_FILENO, TCSAFLUSH, &amp;attr);
      return 0;
  }
  
  int main()
  {
      setmode(0, 1, false, true);
      while (true)
      {
          char c;
          read(0, &amp;c, 1);
          cout &lt;&lt; c;
          fflush(stdout);
      }
      return 0;
  }
  </code></pre>
  <p>This correctly echoes keys (while removing <code>cout &lt;&lt; c;</code> stops echoing, so I assume reading works correct and <code>c</code> contains correct char). Now I want to test if some specific keys like arrows, enter or backspace are pressed. For keys I've tried something like</p>
  <p><code>if (c == '\[A') cout &lt;&lt; &quot;smth&quot;;</code>
  instead of <code>cout &lt;&lt; c;</code> but this prints nothing. Also from infocmp I found that arrow-keys have following esc-sequences:</p>
  <p><code>kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA</code> and also tested them, but neither work. So in this code how do I test for arrows, enter, backspace, some F-keys?
  Also, is it possible to simplify setmode's if-else statements to a single bit-expression assignment?</p>