vte: implement backspace control
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 5 Feb 2012 15:02:21 +0000 (16:02 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 5 Feb 2012 15:02:21 +0000 (16:02 +0100)
Add new helper to console subsystem which performs a backspace
operation. We must take care of auto-wrap mode so we cannot simply use
the *_move_left() function.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/console.c
src/console.h
src/vte.c

index dccba24..eff706b 100644 (file)
@@ -289,6 +289,21 @@ void kmscon_console_newline(struct kmscon_console *con)
        }
 }
 
+void kmscon_console_backspace(struct kmscon_console *con)
+{
+       if (!con)
+               return;
+
+       if (con->cursor_x >= con->cells_x) {
+               con->cursor_x = con->cells_x - 2;
+       } else if (con->cursor_x > 0) {
+               con->cursor_x--;
+       } else if (con->auto_wrap) {
+               con->cursor_x = con->cells_x - 1;
+               kmscon_console_move_up(con, 1, true);
+       }
+}
+
 void kmscon_console_move_to(struct kmscon_console *con, unsigned int x,
                                                        unsigned int y)
 {
index 17e6af4..9ed297f 100644 (file)
@@ -91,6 +91,7 @@ void kmscon_console_map(struct kmscon_console *con);
 
 void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch);
 void kmscon_console_newline(struct kmscon_console *con);
+void kmscon_console_backspace(struct kmscon_console *con);
 void kmscon_console_move_to(struct kmscon_console *con, unsigned int x,
                                                        unsigned int y);
 void kmscon_console_move_up(struct kmscon_console *con, unsigned int num,
index 48a7b27..4792846 100644 (file)
--- a/src/vte.c
+++ b/src/vte.c
@@ -152,6 +152,7 @@ static void parse_control(struct kmscon_vte *vte, uint32_t ctrl)
                        break;
                case 0x08: /* BS */
                        /* Move cursor one position left */
+                       kmscon_console_backspace(vte->con);
                        break;
                case 0x09: /* HT */
                        /* Move to next tab stop or end of line */