vte: implement backspace control

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>
This commit is contained in:
David Herrmann 2012-02-05 16:02:21 +01:00
parent 5f0d151bb7
commit cdb3d112a6
3 changed files with 17 additions and 0 deletions

View 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)
{

View 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,

View File

@ -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 */