You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/10/17 11:47:28 UTC

[mynewt-core] 20/21: sys/console: Add software cursor in prompt area

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 8aab3bdd8b09481451395fe2c6b692ca53e15628
Author: Jerzy Kasenberg <ka...@users.noreply.github.com>
AuthorDate: Wed Oct 16 00:25:00 2019 +0200

    sys/console: Add software cursor in prompt area
    
    For massive log output it can be difficult to see
    cursor position in prompt area.
    In that case software rendered cursor is useful.
    This adds such functionality.
    Cursor is rendered inverse by default which is suitable
    for black and white only terminal.
    For color terminal escape sequence can be set to make
    software cursor matching with hardware one.
---
 sys/console/full/src/console.c | 30 ++++++++++++++++++++++++++++++
 sys/console/full/syscfg.yml    | 11 +++++++++++
 2 files changed, 41 insertions(+)

diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index f311fc8..829b8ed 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -358,6 +358,9 @@ console_init_terminal(void)
 static void
 console_switch_to_prompt(void)
 {
+    struct console_input *input;
+    char c;
+
     console_init_terminal();
     /* If terminal size is not known yet, try asking terminal first */
     if (MYNEWT_VAL(CONSOLE_STICKY_PROMPT) &&
@@ -374,6 +377,17 @@ console_switch_to_prompt(void)
         cursor_save();
         prompt_has_focus = true;
         console_cursor_set(max_row, prompt_len + cur + 1);
+        if (MYNEWT_VAL(CONSOLE_PROMPT_SOFT_CURSOR)) {
+            if (trailing_chars && current_line_ev && current_line_ev->ev_arg) {
+                input = (struct console_input *)current_line_ev->ev_arg;
+                c = input->line[cur];
+            } else {
+                c = ' ';
+            }
+            console_write_str(CSI "0m");
+            console_out_nolock(c);
+            console_out_nolock('\b');
+        }
     }
 }
 
@@ -384,11 +398,27 @@ console_switch_to_prompt(void)
 static void
 console_switch_to_logs(void)
 {
+    struct console_input *input;
+    char c;
+
     if (g_is_output_nlip) {
         return;
     }
+
     console_init_terminal();
     if (MYNEWT_VAL(CONSOLE_STICKY_PROMPT) && prompt_has_focus) {
+        if (MYNEWT_VAL(CONSOLE_PROMPT_SOFT_CURSOR)) {
+            console_write_str(CSI);
+            console_write_str(MYNEWT_VAL(CONSOLE_PROMPT_SOFT_CURSOR_ATTR));
+            if (trailing_chars && current_line_ev && current_line_ev->ev_arg) {
+                input = (struct console_input *)current_line_ev->ev_arg;
+                c = input->line[cur];
+            } else {
+                c = ' ';
+            }
+            console_out_nolock(c);
+            console_write_str(CSI "0m\b");
+        }
         cursor_restore();
         prompt_has_focus = false;
     }
diff --git a/sys/console/full/syscfg.yml b/sys/console/full/syscfg.yml
index 3ccdeec..e8334b9 100644
--- a/sys/console/full/syscfg.yml
+++ b/sys/console/full/syscfg.yml
@@ -54,6 +54,17 @@ syscfg.defs:
             If set to 1 prompt will be visble all the time at the
             bottom of terminal if terminal was detected.
         value: 0
+    CONSOLE_PROMPT_SOFT_CURSOR:
+        description: >
+            Set this to 1 for VT102 like terminals in case of volume of
+            log prints makes it difficult to see cursor in prompt line.
+        value: 0
+    CONSOLE_PROMPT_SOFT_CURSOR_ATTR:
+        description: >
+            Terminal escape sequence for cursor graphics mode.
+            For black and white (minicom) use "7m" - inverse
+            For color (putty) use "30;42m" - black/green
+        value: '"7m"'
 
     CONSOLE_UART_BAUD:
         description: 'Console UART baud rate.'