title: Implementing Serial CLI on Arduino
body: <p>I'm trying to implement a serial cli where you can type and edit a command using a console like screen/minicom. In my testing, I'm using screen to connect to the serial interface. In trying to implement a delete character option, I'm not seeing the results I'm expecting.</p>
  <p>I've been reading online on how to use ANSI escape sequences, which I'm finding that some such as <code>ESC c</code> to clear screen, and <code>ESC[?25l</code> to hide the cursor are working with my tests. But when I try to use <code>ESC[1D</code> to move the cursor to the left by 1, or any other cursor escape sequences, it isn't working as I would expect.</p>
  <p>I've read through <a href="https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html" rel="nofollow noreferrer">https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html</a> and <a href="https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797" rel="nofollow noreferrer">https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797</a> for help on how to do this right.</p>
  <p>For an example of some test code I'm using:</p>
  <pre><code>void SendESC(const char *code) {
      Serial.write(27);
      Serial.print(code);
  }
  
  void loop() {
      char byteRead = Serial.read();
      if (byteRead==8) {
          if (m_buffer_read!=0) {
              m_buffer_read--;
              m_buffer[m_buffer_read] = '\0';
              SendESC(&quot;[1000D&quot;);
              SendESC(&quot;[0K&quot;);
              Serial.print(m_line_indicator);
              Serial.print(m_buffer);
              size_t lineLen = strlen(m_line_indicator)+m_buffer_read;
              char buf[7];
              SendESC(&quot;[1000D&quot;);
              sprintf(buf, &quot;[%dC&quot;, lineLen);
              SendESC(buf);
          }
      }
  }
  </code></pre>
  <p>In running the above test, it seems like screen does not know the escape sequences are over and it does not pick up on the updated information. I can however confirm with a hex view of the serial data received that the escape sequences are being sent exactly as I expect.</p>
  <p>Am I missing something?</p>