vte: move long csi-handlers into separate function

Avoid making do_csi() too big. So put long csi-handlers into separate
functions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-05-29 12:43:58 +02:00
parent 2ad5600d60
commit 30c1c20876

152
src/vte.c
View File

@ -489,66 +489,10 @@ static void do_esc(struct kmscon_vte *vte, uint32_t data)
} }
} }
static void csi_soft_reset(struct kmscon_vte *vte) static void csi_attribute(struct kmscon_vte *vte)
{ {
kmscon_vte_reset(vte); unsigned int i;
}
static void do_csi(struct kmscon_vte *vte, uint32_t data)
{
int num, i;
if (vte->csi_argc < CSI_ARG_MAX)
vte->csi_argc++;
switch (data) {
case 'A':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_up(vte->con, num, false);
break;
case 'B':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_down(vte->con, num, false);
break;
case 'C':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_right(vte->con, num);
break;
case 'D':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_left(vte->con, num);
break;
case 'J':
if (vte->csi_argv[0] <= 0)
kmscon_console_erase_cursor_to_screen(vte->con);
else if (vte->csi_argv[0] == 1)
kmscon_console_erase_screen_to_cursor(vte->con);
else if (vte->csi_argv[0] == 2)
kmscon_console_erase_screen(vte->con);
else
log_debug("unknown parameter to CSI-J: %d",
vte->csi_argv[0]);
break;
case 'K':
if (vte->csi_argv[0] <= 0)
kmscon_console_erase_cursor_to_end(vte->con);
else if (vte->csi_argv[0] == 1)
kmscon_console_erase_home_to_cursor(vte->con);
else if (vte->csi_argv[0] == 2)
kmscon_console_erase_current_line(vte->con);
else
log_debug("unknown parameter to CSI-K: %d",
vte->csi_argv[0]);
break;
case 'm':
for (i = 0; i < CSI_ARG_MAX; ++i) { for (i = 0; i < CSI_ARG_MAX; ++i) {
switch (vte->csi_argv[i]) { switch (vte->csi_argv[i]) {
case -1: case -1:
@ -627,18 +571,15 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data)
vte->csi_argv[i]); vte->csi_argv[i]);
} }
} }
break; }
case 'p':
if (vte->csi_flags & CSI_GT) { static void csi_soft_reset(struct kmscon_vte *vte)
/* xterm: select X11 visual cursor mode */ {
} else if (vte->csi_flags & CSI_BANG) { kmscon_vte_reset(vte);
/* DECSTR: Soft Reset */ }
csi_soft_reset(vte);
} else if (vte->csi_flags & CSI_CASH) { static void csi_compat_mode(struct kmscon_vte *vte)
/* DECRQM: Request DEC Private Mode */ {
/* If CSI_WHAT is set, then enable,
* otherwise disable */
} else {
/* DECSCL: Compatibility Level */ /* DECSCL: Compatibility Level */
/* Sometimes CSI_DQUOTE is set here, too */ /* Sometimes CSI_DQUOTE is set here, too */
if (vte->csi_argv[0] == 61) { if (vte->csi_argv[0] == 61) {
@ -683,6 +624,77 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data)
kmscon_utf8_mach_reset(vte->mach); kmscon_utf8_mach_reset(vte->mach);
} }
} }
static void do_csi(struct kmscon_vte *vte, uint32_t data)
{
int num;
if (vte->csi_argc < CSI_ARG_MAX)
vte->csi_argc++;
switch (data) {
case 'A':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_up(vte->con, num, false);
break;
case 'B':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_down(vte->con, num, false);
break;
case 'C':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_right(vte->con, num);
break;
case 'D':
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
kmscon_console_move_left(vte->con, num);
break;
case 'J':
if (vte->csi_argv[0] <= 0)
kmscon_console_erase_cursor_to_screen(vte->con);
else if (vte->csi_argv[0] == 1)
kmscon_console_erase_screen_to_cursor(vte->con);
else if (vte->csi_argv[0] == 2)
kmscon_console_erase_screen(vte->con);
else
log_debug("unknown parameter to CSI-J: %d",
vte->csi_argv[0]);
break;
case 'K':
if (vte->csi_argv[0] <= 0)
kmscon_console_erase_cursor_to_end(vte->con);
else if (vte->csi_argv[0] == 1)
kmscon_console_erase_home_to_cursor(vte->con);
else if (vte->csi_argv[0] == 2)
kmscon_console_erase_current_line(vte->con);
else
log_debug("unknown parameter to CSI-K: %d",
vte->csi_argv[0]);
break;
case 'm':
csi_attribute(vte);
break;
case 'p':
if (vte->csi_flags & CSI_GT) {
/* xterm: select X11 visual cursor mode */
} else if (vte->csi_flags & CSI_BANG) {
/* DECSTR: Soft Reset */
csi_soft_reset(vte);
} else if (vte->csi_flags & CSI_CASH) {
/* DECRQM: Request DEC Private Mode */
/* If CSI_WHAT is set, then enable,
* otherwise disable */
} else {
csi_compat_mode(vte);
}
break; break;
default: default:
log_debug("unhandled CSI sequence %c", data); log_debug("unhandled CSI sequence %c", data);