xiaoxiang781216 commented on code in PR #3657:
URL: https://github.com/apache/nuttx-apps/pull/3657#discussion_r3652543996


##########
system/readline/readline_common.c:
##########
@@ -670,55 +1350,175 @@ ssize_t readline_common(FAR struct rl_common_s *vtbl, 
FAR char *buf,
 
       else if (ch == '\n')
         {
-#ifdef CONFIG_READLINE_CMD_HISTORY
-          /* Save history of command, only if there was something
-           * typed besides return character.
-           */
+          return submit_line(buf, nch);
+        }
 
-          if (nch >= 1)
-            {
-              /* If this command is the one at the top of the circular
-               * buffer, don't save it again.
-               */
+      /* Emacs-style control keys */
 
-              if (strncmp(buf, g_cmdhist.buf[g_cmdhist.head], nch + 1) != 0)
+#ifdef CONFIG_READLINE_EDIT_EMACS
+      else if (ch == CTRL_A)        /* Ctrl+A = Home */
+        {
+          cursor = 0;
+          redraw_line(vtbl, buf, nch, cursor);
+        }
+      else if (ch == CTRL_B)            /* Ctrl+B = Left */
+        {
+          if (cursor > 0)
+            {
+              cursor--;
+              RL_WRITE(vtbl, g_curleft, sizeof(g_curleft));
+            }
+        }
+      else if (ch == CTRL_D)            /* Ctrl+D = Delete at cursor */
+        {
+          if (cursor < nch)
+            {
+              int k;
+              for (k = cursor + 1; k < nch; k++)
+                buf[k - 1] = buf[k];
+              nch--;
+              RL_WRITE(vtbl, g_erasetoeol, sizeof(g_erasetoeol));
+              if (cursor < nch)
                 {
-                  g_cmdhist.head = (g_cmdhist.head + 1) % RL_CMDHIST_LEN;
-
-                  for (i = 0; (i < nch) && i < (RL_CMDHIST_LINELEN - 1); i++)
-                    {
-                      g_cmdhist.buf[g_cmdhist.head][i] = buf[i];
-                    }
+                  RL_WRITE(vtbl, buf + cursor, nch - cursor);
+                  for (k = nch; k > cursor; k--)
+                    RL_WRITE(vtbl, g_curleft, sizeof(g_curleft));
+                }
+            }
+        }
+      else if (ch == CTRL_E)            /* Ctrl+E = End */
+        {
+          while (cursor < nch)
+            {
+              cursor++;
+              RL_WRITE(vtbl, g_curright, sizeof(g_curright));
+            }
+        }
+      else if (ch == CTRL_F)            /* Ctrl+F = Right */
+        {
+          if (cursor < nch)
+            {
+              cursor++;
+              RL_WRITE(vtbl, g_curright, sizeof(g_curright));
+            }
+        }
+      else if (ch == CTRL_K)           /* Ctrl+K = Kill to EOL */
+        {
+          nch = cursor;
+          buf[nch] = '\0';
+          RL_WRITE(vtbl, g_erasetoeol, sizeof(g_erasetoeol));
+        }
+      else if (ch == CTRL_U)           /* Ctrl+U = Kill to BOL */
+        {
+          int j;
+          for (j = cursor; j < nch; j++)
+            buf[j - cursor] = buf[j];
+          nch -= cursor;
+          cursor = 0;
+          buf[nch] = '\0';
+          redraw_line(vtbl, buf, nch, cursor);
+        }
+      else if (ch == CTRL_W)           /* Ctrl+W = Kill word backward (FIXME) 
*/
+        {
+          int start, k;
+          start = cursor;
+          while (start > 0 && buf[start - 1] == ' ')
+            start--;
+          while (start > 0 && buf[start - 1] != ' ')
+            start--;

Review Comment:
   add {}



##########
system/readline/readline_common.c:
##########
@@ -670,55 +1350,175 @@ ssize_t readline_common(FAR struct rl_common_s *vtbl, 
FAR char *buf,
 
       else if (ch == '\n')
         {
-#ifdef CONFIG_READLINE_CMD_HISTORY
-          /* Save history of command, only if there was something
-           * typed besides return character.
-           */
+          return submit_line(buf, nch);
+        }
 
-          if (nch >= 1)
-            {
-              /* If this command is the one at the top of the circular
-               * buffer, don't save it again.
-               */
+      /* Emacs-style control keys */
 
-              if (strncmp(buf, g_cmdhist.buf[g_cmdhist.head], nch + 1) != 0)
+#ifdef CONFIG_READLINE_EDIT_EMACS
+      else if (ch == CTRL_A)        /* Ctrl+A = Home */
+        {
+          cursor = 0;
+          redraw_line(vtbl, buf, nch, cursor);
+        }
+      else if (ch == CTRL_B)            /* Ctrl+B = Left */
+        {
+          if (cursor > 0)
+            {
+              cursor--;
+              RL_WRITE(vtbl, g_curleft, sizeof(g_curleft));
+            }
+        }
+      else if (ch == CTRL_D)            /* Ctrl+D = Delete at cursor */
+        {
+          if (cursor < nch)
+            {
+              int k;
+              for (k = cursor + 1; k < nch; k++)
+                buf[k - 1] = buf[k];
+              nch--;
+              RL_WRITE(vtbl, g_erasetoeol, sizeof(g_erasetoeol));
+              if (cursor < nch)
                 {
-                  g_cmdhist.head = (g_cmdhist.head + 1) % RL_CMDHIST_LEN;
-
-                  for (i = 0; (i < nch) && i < (RL_CMDHIST_LINELEN - 1); i++)
-                    {
-                      g_cmdhist.buf[g_cmdhist.head][i] = buf[i];
-                    }
+                  RL_WRITE(vtbl, buf + cursor, nch - cursor);
+                  for (k = nch; k > cursor; k--)
+                    RL_WRITE(vtbl, g_curleft, sizeof(g_curleft));

Review Comment:
   add {}



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to