This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 861a7f991862d0d2957675dfc2497df704588037
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Fri Oct 4 13:01:53 2019 +0200

    sys/console: del_char function reworked
    
    Function usage was not very clear.
    Unlike matching insert_char() this function did not modified
    cur nor trailing_chars. It expected them do be set correctly
    beforehand.
    Moreover actual state of cur and trailing_chars did not match
    what was on the screen, that is why function started with
    console_out('\b').
    
    Now last argument is removed to match insert_char().
    Function modifies cur/trailing_chars accordingly.
    cursor save/restore pair is also removed in favor of cursor_backward.
---
 sys/console/full/src/console.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index 022622a..4d3e550 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -348,28 +348,23 @@ insert_char(char *pos, char c)
     }
 }
 
+/* Delete character at cursor position */
 static void
-del_char(char *pos, uint16_t end)
+del_char(char *pos)
 {
-    console_out('\b');
+    int left = trailing_chars;
 
-    if (end == 0) {
-        console_out(' ');
-        console_out('\b');
-        return;
-    }
-
-    cursor_save();
-
-    while (end-- > 0) {
+    while (left-- > 1) {
         *pos = *(pos + 1);
-        console_out(*(pos++));
+        console_out_nolock(*(pos++));
     }
 
-    console_out(' ');
-
     /* Move cursor back to right place */
-    cursor_restore();
+    if (trailing_chars) {
+        console_out_nolock(' ');
+        cursor_backward(trailing_chars);
+        trailing_chars--;
+    }
 }
 
 #if MYNEWT_VAL(CONSOLE_HISTORY_SIZE) > 0
@@ -656,8 +651,7 @@ ansi_cmd:
             break;
         }
 
-        cursor_forward(1);
-        del_char(&line[cur], --trailing_chars);
+        del_char(&line[cur]);
         break;
     default:
         break;
@@ -815,7 +809,10 @@ console_handle_char(uint8_t byte)
                 break;
             }
             if (cur > 0) {
-                del_char(&input->line[--cur], trailing_chars);
+                cursor_backward(1);
+                cur--;
+                trailing_chars++;
+                del_char(&input->line[cur]);
             }
             break;
         case ESC:

Reply via email to