console: support INSERT mode

When INSERT mode is enabled, we move all following characters to the right
and drop all characters that are moved beyond the margin.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-05-29 16:57:04 +02:00
parent 5f8ca1fd78
commit 860e7ff509
3 changed files with 28 additions and 7 deletions

View File

@ -775,7 +775,8 @@ static void kmscon_buffer_draw(struct kmscon_buffer *buf,
static void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,
unsigned int y, kmscon_symbol_t ch,
const struct font_char_attr *attr)
const struct font_char_attr *attr,
unsigned int flags)
{
struct line *line, **slot;
int ret;
@ -816,7 +817,7 @@ static void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,
buf->scroll_fill = y + 1;
}
if (x >= line->size) {
if (line->size < buf->size_x) {
ret = resize_line(line, buf->size_x);
if (ret) {
log_warn("cannot resize line (%d); dropping input", ret);
@ -824,6 +825,9 @@ static void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,
}
}
if ((flags & KMSCON_CONSOLE_INSERT) && x < (buf->size_x - 1))
memmove(&line->cells[x + 1], &line->cells[x],
sizeof(struct cell) * (buf->size_x - 1 - x));
line->cells[x].ch = ch;
memcpy(&line->cells[x].attr, attr, sizeof(*attr));
}
@ -1052,7 +1056,8 @@ void kmscon_console_draw(struct kmscon_console *con, struct font_screen *fscr)
}
void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch,
const struct font_char_attr *attr)
const struct font_char_attr *attr,
unsigned int flags)
{
unsigned int last;
@ -1074,7 +1079,8 @@ void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch,
}
}
kmscon_buffer_write(con->cells, con->cursor_x, con->cursor_y, ch, attr);
kmscon_buffer_write(con->cells, con->cursor_x, con->cursor_y, ch, attr,
flags);
con->cursor_x++;
}

View File

@ -44,6 +44,8 @@ struct kmscon_console;
/* console objects */
#define KMSCON_CONSOLE_INSERT 0x01
int kmscon_console_new(struct kmscon_console **out);
void kmscon_console_ref(struct kmscon_console *con);
void kmscon_console_unref(struct kmscon_console *con);
@ -57,7 +59,8 @@ void kmscon_console_reset(struct kmscon_console *con);
void kmscon_console_draw(struct kmscon_console *con, struct font_screen *fscr);
void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch,
const struct font_char_attr *attr);
const struct font_char_attr *attr,
unsigned int flags);
void kmscon_console_newline(struct kmscon_console *con);
void kmscon_console_move_to(struct kmscon_console *con, unsigned int x,
unsigned int y);

View File

@ -261,6 +261,18 @@ static void vte_write_debug(struct kmscon_vte *vte, const char *u8, size_t len,
#define vte_write_raw(_vte, _u8, _len) \
vte_write_debug((_vte), (_u8), (_len), true, __FILE__, __LINE__)
/* write to console */
static void write_console(struct kmscon_vte *vte, kmscon_symbol_t sym)
{
unsigned int flags;
flags = 0;
if (vte->flags & FLAG_INSERT_REPLACE_MODE)
flags |= KMSCON_CONSOLE_INSERT;
kmscon_console_write(vte->con, sym, &vte->cattr, flags);
}
/*
* Reset VTE state
* This performs a soft reset of the VTE. That is, everything is reset to the
@ -361,7 +373,7 @@ static void do_execute(struct kmscon_vte *vte, uint32_t ctrl)
break;
case 0x1a: /* SUB */
/* Discard current escape sequence and show err-sym */
kmscon_console_write(vte->con, 0xbf, &vte->cattr);
write_console(vte, 0xbf);
break;
case 0x1b: /* ESC */
/* Invokes an escape sequence */
@ -1026,7 +1038,7 @@ static void do_action(struct kmscon_vte *vte, uint32_t data, int action)
break;
case ACTION_PRINT:
sym = kmscon_symbol_make(vte_map(vte, data));
kmscon_console_write(vte->con, sym, &vte->cattr);
write_console(vte, sym);
break;
case ACTION_EXECUTE:
do_execute(vte, data);