2009-01-12 00:31:46 +01:00
|
|
|
/* $Id: input.c,v 1.73 2009-01-11 23:31:46 nicm Exp $ */
|
2007-07-09 21:04:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2007-09-29 00:47:22 +02:00
|
|
|
#include <stdlib.h>
|
2007-09-29 00:54:21 +02:00
|
|
|
#include <string.h>
|
2007-07-09 21:04:12 +02:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
#define INPUT_C0CONTROL(ch) (ch <= 0x1f)
|
|
|
|
#define INPUT_INTERMEDIATE(ch) (ch == 0xa0 || (ch >= 0x20 && ch <= 0x2f))
|
|
|
|
#define INPUT_PARAMETER(ch) (ch >= 0x30 && ch <= 0x3f)
|
|
|
|
#define INPUT_UPPERCASE(ch) (ch >= 0x40 && ch <= 0x5f)
|
|
|
|
#define INPUT_LOWERCASE(ch) (ch >= 0x60 && ch <= 0x7e)
|
|
|
|
#define INPUT_DELETE(ch) (ch == 0x7f)
|
|
|
|
#define INPUT_C1CONTROL(ch) (ch >= 0x80 && ch <= 0x9f)
|
|
|
|
#define INPUT_G1DISPLAYABLE(ch) (ch >= 0xa1 && ch <= 0xfe)
|
|
|
|
#define INPUT_SPECIAL(ch) (ch == 0xff)
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
int input_get_argument(struct input_ctx *, u_int, uint16_t *, uint16_t);
|
2007-09-29 16:25:49 +02:00
|
|
|
int input_new_argument(struct input_ctx *);
|
2007-11-27 20:23:34 +01:00
|
|
|
int input_add_argument(struct input_ctx *, u_char);
|
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void input_start_string(struct input_ctx *, int);
|
|
|
|
void input_abort_string(struct input_ctx *);
|
|
|
|
int input_add_string(struct input_ctx *, u_char);
|
|
|
|
char *input_get_string(struct input_ctx *);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void input_state(struct input_ctx *, void *);
|
|
|
|
|
|
|
|
void input_state_first(u_char, struct input_ctx *);
|
|
|
|
void input_state_escape(u_char, struct input_ctx *);
|
|
|
|
void input_state_intermediate(u_char, struct input_ctx *);
|
|
|
|
void input_state_sequence_first(u_char, struct input_ctx *);
|
|
|
|
void input_state_sequence_next(u_char, struct input_ctx *);
|
|
|
|
void input_state_sequence_intermediate(u_char, struct input_ctx *);
|
|
|
|
void input_state_string_next(u_char, struct input_ctx *);
|
|
|
|
void input_state_string_escape(u_char, struct input_ctx *);
|
2008-09-10 00:16:37 +02:00
|
|
|
void input_state_utf8(u_char, struct input_ctx *);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
void input_handle_character(u_char, struct input_ctx *);
|
|
|
|
void input_handle_c0_control(u_char, struct input_ctx *);
|
|
|
|
void input_handle_c1_control(u_char, struct input_ctx *);
|
|
|
|
void input_handle_private_two(u_char, struct input_ctx *);
|
|
|
|
void input_handle_standard_two(u_char, struct input_ctx *);
|
|
|
|
void input_handle_sequence(u_char, struct input_ctx *);
|
|
|
|
|
|
|
|
void input_handle_sequence_cuu(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cud(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cuf(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cub(struct input_ctx *);
|
|
|
|
void input_handle_sequence_dch(struct input_ctx *);
|
|
|
|
void input_handle_sequence_dl(struct input_ctx *);
|
|
|
|
void input_handle_sequence_ich(struct input_ctx *);
|
|
|
|
void input_handle_sequence_il(struct input_ctx *);
|
|
|
|
void input_handle_sequence_vpa(struct input_ctx *);
|
|
|
|
void input_handle_sequence_hpa(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cup(struct input_ctx *);
|
|
|
|
void input_handle_sequence_cup(struct input_ctx *);
|
|
|
|
void input_handle_sequence_ed(struct input_ctx *);
|
|
|
|
void input_handle_sequence_el(struct input_ctx *);
|
|
|
|
void input_handle_sequence_sm(struct input_ctx *);
|
|
|
|
void input_handle_sequence_rm(struct input_ctx *);
|
|
|
|
void input_handle_sequence_decstbm(struct input_ctx *);
|
|
|
|
void input_handle_sequence_sgr(struct input_ctx *);
|
2007-10-24 17:29:29 +02:00
|
|
|
void input_handle_sequence_dsr(struct input_ctx *);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2009-01-07 23:52:33 +01:00
|
|
|
int input_sequence_cmp(const void *, const void *);
|
|
|
|
|
|
|
|
struct input_sequence_entry {
|
|
|
|
u_char ch;
|
|
|
|
void (*fn)(struct input_ctx *);
|
|
|
|
};
|
|
|
|
const struct input_sequence_entry input_sequence_table[] = {
|
|
|
|
{ '@', input_handle_sequence_ich },
|
|
|
|
{ 'A', input_handle_sequence_cuu },
|
|
|
|
{ 'B', input_handle_sequence_cud },
|
|
|
|
{ 'C', input_handle_sequence_cuf },
|
|
|
|
{ 'D', input_handle_sequence_cub },
|
|
|
|
{ 'G', input_handle_sequence_hpa },
|
|
|
|
{ 'H', input_handle_sequence_cup },
|
|
|
|
{ 'J', input_handle_sequence_ed },
|
|
|
|
{ 'K', input_handle_sequence_el },
|
|
|
|
{ 'L', input_handle_sequence_il },
|
|
|
|
{ 'M', input_handle_sequence_dl },
|
|
|
|
{ 'P', input_handle_sequence_dch },
|
|
|
|
{ 'd', input_handle_sequence_vpa },
|
|
|
|
{ 'f', input_handle_sequence_cup },
|
|
|
|
{ 'h', input_handle_sequence_sm },
|
|
|
|
{ 'l', input_handle_sequence_rm },
|
|
|
|
{ 'm', input_handle_sequence_sgr },
|
|
|
|
{ 'n', input_handle_sequence_dsr },
|
|
|
|
{ 'r', input_handle_sequence_decstbm },
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
input_sequence_cmp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
int ai = ((const struct input_sequence_entry *) a)->ch;
|
|
|
|
int bi = ((const struct input_sequence_entry *) b)->ch;
|
|
|
|
|
|
|
|
return (ai - bi);
|
|
|
|
}
|
|
|
|
|
2007-09-29 16:25:49 +02:00
|
|
|
int
|
|
|
|
input_new_argument(struct input_ctx *ictx)
|
|
|
|
{
|
|
|
|
struct input_arg *arg;
|
|
|
|
|
|
|
|
ARRAY_EXPAND(&ictx->args, 1);
|
|
|
|
|
|
|
|
arg = &ARRAY_LAST(&ictx->args);
|
|
|
|
arg->used = 0;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
input_add_argument(struct input_ctx *ictx, u_char ch)
|
|
|
|
{
|
|
|
|
struct input_arg *arg;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
arg = &ARRAY_LAST(&ictx->args);
|
|
|
|
if (arg->used > (sizeof arg->data) - 1)
|
|
|
|
return (-1);
|
|
|
|
arg->data[arg->used++] = ch;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
int
|
|
|
|
input_get_argument(struct input_ctx *ictx, u_int i, uint16_t *n, uint16_t d)
|
|
|
|
{
|
|
|
|
struct input_arg *arg;
|
|
|
|
const char *errstr;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
*n = d;
|
|
|
|
if (i >= ARRAY_LENGTH(&ictx->args))
|
|
|
|
return (0);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
arg = &ARRAY_ITEM(&ictx->args, i);
|
2007-09-29 16:25:49 +02:00
|
|
|
if (*arg->data == '\0')
|
2007-09-29 00:47:22 +02:00
|
|
|
return (0);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 16:25:49 +02:00
|
|
|
*n = strtonum(arg->data, 0, UINT16_MAX, &errstr);
|
2007-09-29 00:47:22 +02:00
|
|
|
if (errstr != NULL)
|
|
|
|
return (-1);
|
2007-07-09 21:04:12 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
|
|
|
input_start_string(struct input_ctx *ictx, int type)
|
|
|
|
{
|
|
|
|
ictx->string_type = type;
|
|
|
|
ictx->string_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_abort_string(struct input_ctx *ictx)
|
|
|
|
{
|
2008-06-18 21:06:51 +02:00
|
|
|
if (ictx->string_buf != NULL)
|
|
|
|
xfree(ictx->string_buf);
|
2007-11-30 12:08:35 +01:00
|
|
|
ictx->string_buf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
input_add_string(struct input_ctx *ictx, u_char ch)
|
|
|
|
{
|
|
|
|
ictx->string_buf = xrealloc(ictx->string_buf, 1, ictx->string_len + 1);
|
|
|
|
ictx->string_buf[ictx->string_len++] = ch;
|
|
|
|
|
|
|
|
if (ictx->string_len >= MAXSTRINGLEN) {
|
|
|
|
input_abort_string(ictx);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
input_get_string(struct input_ctx *ictx)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
2009-01-08 22:22:01 +01:00
|
|
|
if (ictx->string_buf == NULL || input_add_string(ictx, '\0') != 0)
|
2007-11-30 12:08:35 +01:00
|
|
|
return (xstrdup(""));
|
|
|
|
|
|
|
|
s = ictx->string_buf;
|
|
|
|
ictx->string_buf = NULL;
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_state(struct input_ctx *ictx, void *state)
|
|
|
|
{
|
|
|
|
ictx->state = state;
|
|
|
|
}
|
|
|
|
|
2007-07-09 21:04:12 +02:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
input_init(struct window_pane *wp)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct input_ctx *ictx = &wp->ictx;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
ARRAY_INIT(&ictx->args);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
ictx->string_len = 0;
|
|
|
|
ictx->string_buf = NULL;
|
2007-11-30 12:08:35 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell);
|
|
|
|
|
|
|
|
memcpy(&ictx->saved_cell, &grid_default_cell, sizeof ictx->saved_cell);
|
|
|
|
ictx->saved_cx = 0;
|
|
|
|
ictx->saved_cy = 0;
|
|
|
|
|
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
input_free(struct window_pane *wp)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
if (wp->ictx.string_buf != NULL)
|
|
|
|
xfree(wp->ictx.string_buf);
|
2007-11-30 12:08:35 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
ARRAY_FREE(&wp->ictx.args);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 11:15:49 +02:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
input_parse(struct window_pane *wp)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct input_ctx *ictx = &wp->ictx;
|
2007-10-24 17:29:29 +02:00
|
|
|
u_char ch;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (BUFFER_USED(wp->in) == 0)
|
2007-10-24 17:29:29 +02:00
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
ictx->buf = BUFFER_OUT(wp->in);
|
|
|
|
ictx->len = BUFFER_USED(wp->in);
|
2007-09-29 00:47:22 +02:00
|
|
|
ictx->off = 0;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
ictx->wp = wp;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
log_debug2("entry; buffer=%zu", ictx->len);
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (wp->mode == NULL)
|
|
|
|
screen_write_start(&ictx->ctx, wp, &wp->base);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ictx->ctx, NULL, &wp->base);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-06-04 21:20:10 +02:00
|
|
|
if (ictx->off != ictx->len)
|
2009-01-12 00:31:46 +01:00
|
|
|
wp->window->flags |= WINDOW_ACTIVITY;
|
2007-09-29 00:47:22 +02:00
|
|
|
while (ictx->off < ictx->len) {
|
|
|
|
ch = ictx->buf[ictx->off++];
|
2007-11-30 12:08:35 +01:00
|
|
|
ictx->state(ch, ictx);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
2007-10-24 17:29:29 +02:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ictx->ctx);
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
buffer_remove(wp->in, ictx->len);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_first(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2008-11-04 21:41:10 +01:00
|
|
|
ictx->intermediate = '\0';
|
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_C0CONTROL(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch == 0x1b)
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_escape);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2007-11-30 12:08:35 +01:00
|
|
|
input_handle_c0_control(ch, ictx);
|
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
2008-09-10 00:16:37 +02:00
|
|
|
#if 0
|
2007-11-30 12:08:35 +01:00
|
|
|
if (INPUT_C1CONTROL(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
ch -= 0x40;
|
|
|
|
if (ch == '[')
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_sequence_first);
|
2008-10-09 23:22:16 +02:00
|
|
|
else if (ch == ']') {
|
|
|
|
input_start_string(ictx, STRING_SYSTEM);
|
|
|
|
input_state(ictx, input_state_string_next);
|
|
|
|
} else if (ch == '_') {
|
|
|
|
input_start_string(ictx, STRING_APPLICATION);
|
|
|
|
input_state(ictx, input_state_string_next);
|
|
|
|
} else
|
2007-11-30 12:08:35 +01:00
|
|
|
input_handle_c1_control(ch, ictx);
|
|
|
|
return;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2008-09-10 00:16:37 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (INPUT_DELETE(ch))
|
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
input_handle_character(ch, ictx);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_escape(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-10 21:45:20 +02:00
|
|
|
/* Treat C1 control and G1 displayable as 7-bit equivalent. */
|
|
|
|
if (INPUT_C1CONTROL(ch) || INPUT_G1DISPLAYABLE(ch))
|
2007-09-29 00:47:22 +02:00
|
|
|
ch &= 0x7f;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_C0CONTROL(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_c0_control(ch, ictx);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
if (INPUT_INTERMEDIATE(ch)) {
|
2008-11-04 21:41:10 +01:00
|
|
|
log_debug2(":: in1 %zu: %hhu (%c)", ictx->off, ch, ch);
|
|
|
|
ictx->intermediate = ch;
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_intermediate);
|
|
|
|
return;
|
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_private_two(ch, ictx);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_UPPERCASE(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch == '[')
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_sequence_first);
|
2008-10-09 23:22:16 +02:00
|
|
|
else if (ch == ']') {
|
|
|
|
input_start_string(ictx, STRING_SYSTEM);
|
|
|
|
input_state(ictx, input_state_string_next);
|
|
|
|
} else if (ch == '_') {
|
|
|
|
input_start_string(ictx, STRING_APPLICATION);
|
|
|
|
input_state(ictx, input_state_string_next);
|
|
|
|
} else {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
input_handle_c1_control(ch, ictx);
|
|
|
|
}
|
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_LOWERCASE(ch)) {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_standard_two(ch, ictx);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_intermediate(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2008-11-04 21:41:10 +01:00
|
|
|
if (INPUT_INTERMEDIATE(ch)) {
|
|
|
|
/* Multiple intermediates currently ignored. */
|
|
|
|
log_debug2(":: in2 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2008-11-04 21:41:10 +01:00
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_private_two(ch, ictx);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_UPPERCASE(ch) || INPUT_LOWERCASE(ch)) {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_standard_two(ch, ictx);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_sequence_first(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
|
|
|
ictx->private = '\0';
|
2007-09-29 16:25:49 +02:00
|
|
|
ARRAY_CLEAR(&ictx->args);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_sequence_next);
|
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_new_argument(ictx);
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch >= 0x3c && ch <= 0x3f) {
|
|
|
|
/* Private control sequence. */
|
|
|
|
ictx->private = ch;
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
2007-11-30 12:08:35 +01:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 16:25:49 +02:00
|
|
|
/* Pass character on directly. */
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state_sequence_next(ch, ictx);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_sequence_next(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_INTERMEDIATE(ch)) {
|
2007-09-29 16:25:49 +02:00
|
|
|
if (input_add_argument(ictx, '\0') != 0)
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2008-11-04 21:41:10 +01:00
|
|
|
else {
|
|
|
|
log_debug2(":: si1 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_sequence_intermediate);
|
2008-11-04 21:41:10 +01:00
|
|
|
}
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_PARAMETER(ch)) {
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ch == ';') {
|
2007-09-29 16:25:49 +02:00
|
|
|
if (input_add_argument(ictx, '\0') != 0)
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
else
|
|
|
|
input_new_argument(ictx);
|
|
|
|
} else if (input_add_argument(ictx, ch) != 0)
|
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (INPUT_UPPERCASE(ch) || INPUT_LOWERCASE(ch)) {
|
2007-09-29 16:25:49 +02:00
|
|
|
if (input_add_argument(ictx, '\0') != 0)
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
else {
|
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
input_handle_sequence(ch, ictx);
|
|
|
|
}
|
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
2007-10-10 21:45:20 +02:00
|
|
|
input_state_sequence_intermediate(u_char ch, struct input_ctx *ictx)
|
2007-09-29 00:47:22 +02:00
|
|
|
{
|
2008-09-08 22:51:19 +02:00
|
|
|
if (INPUT_INTERMEDIATE(ch)) {
|
2008-11-04 21:41:10 +01:00
|
|
|
log_debug2(":: si2 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2008-09-08 22:51:19 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-10-10 21:45:20 +02:00
|
|
|
if (INPUT_UPPERCASE(ch) || INPUT_LOWERCASE(ch)) {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
2007-09-29 00:47:22 +02:00
|
|
|
input_handle_sequence(ch, ictx);
|
2007-11-30 12:08:35 +01:00
|
|
|
return;
|
2007-10-10 21:45:20 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
}
|
2007-10-10 21:45:20 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
void
|
|
|
|
input_state_string_next(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
|
|
|
if (ch == 0x1b) {
|
|
|
|
input_state(ictx, input_state_string_escape);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-09 23:22:16 +02:00
|
|
|
if (ch == 0x07) {
|
|
|
|
input_state_string_escape(ch, ictx);
|
|
|
|
return;
|
|
|
|
}
|
2007-11-30 12:08:35 +01:00
|
|
|
|
|
|
|
if (ch >= 0x20 && ch != 0x7f) {
|
|
|
|
if (input_add_string(ictx, ch) != 0)
|
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_state_string_escape(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
2008-10-09 23:22:16 +02:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (ch == '\007' || ch == '\\') {
|
2007-11-30 12:08:35 +01:00
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
switch (ictx->string_type) {
|
2008-10-09 23:22:16 +02:00
|
|
|
case STRING_SYSTEM:
|
|
|
|
if (ch != '\007')
|
|
|
|
return;
|
|
|
|
s = input_get_string(ictx);
|
|
|
|
if ((s[0] != '0' && s[0] != '2') || s[1] != ';') {
|
|
|
|
xfree(s);
|
|
|
|
return;
|
|
|
|
}
|
2009-01-10 02:51:22 +01:00
|
|
|
screen_set_title(ictx->ctx.s, s + 2);
|
2009-01-12 00:31:46 +01:00
|
|
|
server_status_window(ictx->wp->window);
|
2008-10-09 23:22:16 +02:00
|
|
|
xfree(s);
|
|
|
|
break;
|
|
|
|
case STRING_APPLICATION:
|
|
|
|
if (ch != '\\')
|
|
|
|
return;
|
|
|
|
s = input_get_string(ictx);
|
|
|
|
screen_set_title(ictx->ctx.s, s);
|
2009-01-12 00:31:46 +01:00
|
|
|
server_status_window(ictx->wp->window);
|
2008-10-09 23:22:16 +02:00
|
|
|
xfree(s);
|
|
|
|
break;
|
2007-11-30 12:08:35 +01:00
|
|
|
case STRING_NAME:
|
2008-10-09 23:22:16 +02:00
|
|
|
if (ch != '\\')
|
|
|
|
return;
|
2009-01-12 00:31:46 +01:00
|
|
|
xfree(ictx->wp->window->name);
|
|
|
|
ictx->wp->window->name = input_get_string(ictx);
|
|
|
|
server_status_window(ictx->wp->window);
|
2007-11-30 12:08:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_state(ictx, input_state_string_next);
|
|
|
|
input_state_string_next(ch, ictx);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2008-09-10 00:16:37 +02:00
|
|
|
void
|
|
|
|
input_state_utf8(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
u_int value;
|
|
|
|
|
2008-09-10 00:16:37 +02:00
|
|
|
log_debug2("-- un %zu: %hhu (%c)", ictx->off, ch, ch);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
ictx->utf8_buf[ictx->utf8_off++] = ch;
|
2008-09-10 00:16:37 +02:00
|
|
|
if (--ictx->utf8_len != 0)
|
|
|
|
return;
|
|
|
|
input_state(ictx, input_state_first);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
value = utf8_combine(ictx->utf8_buf);
|
|
|
|
if (value > 0xffff) /* non-BMP not supported */
|
|
|
|
value = '_';
|
|
|
|
|
|
|
|
ictx->cell.data = value;
|
|
|
|
screen_write_cell(&ictx->ctx, &ictx->cell);
|
2008-09-10 00:16:37 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_character(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *wp = ictx->wp;
|
|
|
|
|
|
|
|
if (ch > 0x7f && options_get_number(&wp->window->options, "utf8")) {
|
2008-09-26 08:45:28 +02:00
|
|
|
/*
|
2008-09-25 22:08:57 +02:00
|
|
|
* UTF-8 sequence.
|
2008-09-10 00:16:37 +02:00
|
|
|
*
|
|
|
|
* 11000010-11011111 C2-DF start of 2-byte sequence
|
|
|
|
* 11100000-11101111 E0-EF start of 3-byte sequence
|
|
|
|
* 11110000-11110100 F0-F4 start of 4-byte sequence
|
|
|
|
*/
|
2008-09-25 22:08:57 +02:00
|
|
|
memset(ictx->utf8_buf, 0xff, sizeof ictx->utf8_buf);
|
|
|
|
ictx->utf8_buf[0] = ch;
|
2008-09-10 00:16:37 +02:00
|
|
|
ictx->utf8_off = 1;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-10 00:16:37 +02:00
|
|
|
if (ch >= 0xc2 && ch <= 0xdf) {
|
2008-09-25 22:08:57 +02:00
|
|
|
log_debug2("-- u2 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2008-09-10 00:16:37 +02:00
|
|
|
input_state(ictx, input_state_utf8);
|
|
|
|
ictx->utf8_len = 1;
|
2008-09-25 22:08:57 +02:00
|
|
|
return;
|
2008-09-10 00:16:37 +02:00
|
|
|
}
|
|
|
|
if (ch >= 0xe0 && ch <= 0xef) {
|
2008-09-25 22:08:57 +02:00
|
|
|
log_debug2("-- u3 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2008-09-10 00:16:37 +02:00
|
|
|
input_state(ictx, input_state_utf8);
|
|
|
|
ictx->utf8_len = 2;
|
2008-09-25 22:08:57 +02:00
|
|
|
return;
|
2008-09-10 00:16:37 +02:00
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
if (ch >= 0xf0 && ch <= 0xf4) {
|
2008-09-25 22:08:57 +02:00
|
|
|
log_debug2("-- u4 %zu: %hhu (%c)", ictx->off, ch, ch);
|
2008-09-10 00:16:37 +02:00
|
|
|
input_state(ictx, input_state_utf8);
|
|
|
|
ictx->utf8_len = 3;
|
2008-09-25 22:08:57 +02:00
|
|
|
return;
|
2008-09-10 00:16:37 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
log_debug2("-- ch %zu: %hhu (%c)", ictx->off, ch, ch);
|
2008-09-10 00:16:37 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
ictx->cell.data = ch;
|
|
|
|
screen_write_cell(&ictx->ctx, &ictx->cell);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_c0_control(u_char ch, struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = ictx->ctx.s;
|
2007-10-24 17:40:59 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug2("-- c0 %zu: %hhu", ictx->off, ch);
|
|
|
|
|
2007-07-09 21:04:12 +02:00
|
|
|
switch (ch) {
|
|
|
|
case '\0': /* NUL */
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
case '\n': /* LF */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_linefeed(&ictx->ctx);
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
case '\r': /* CR */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_carriagereturn(&ictx->ctx);
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
2007-09-29 11:15:49 +02:00
|
|
|
case '\007': /* BELL */
|
2009-01-12 00:31:46 +01:00
|
|
|
ictx->wp->window->flags |= WINDOW_BELL;
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
case '\010': /* BS */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursorleft(&ictx->ctx, 1);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-11-09 18:06:01 +01:00
|
|
|
case '\011': /* TAB */
|
|
|
|
s->cx = ((s->cx / 8) * 8) + 8;
|
2008-09-25 22:08:57 +02:00
|
|
|
if (s->cx > screen_size_x(s) - 1) {
|
2007-11-09 18:06:01 +01:00
|
|
|
s->cx = 0;
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursordown(&ictx->ctx, 1);
|
2007-11-09 18:06:01 +01:00
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ictx->ctx, s->cx, s->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2007-11-25 00:29:49 +01:00
|
|
|
case '\016': /* SO */
|
2008-09-25 22:08:57 +02:00
|
|
|
ictx->cell.attr |= GRID_ATTR_CHARSET;
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2007-11-25 00:29:49 +01:00
|
|
|
case '\017': /* SI */
|
2008-09-25 22:08:57 +02:00
|
|
|
ictx->cell.attr &= ~GRID_ATTR_CHARSET;
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
default:
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug("unknown c0: %hhu", ch);
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_c1_control(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
|
|
|
log_debug2("-- c1 %zu: %hhu (%c)", ictx->off, ch, ch);
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case 'M': /* RI */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_reverseindex(&ictx->ctx);
|
2007-09-29 00:47:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_debug("unknown c1: %hhu", ch);
|
|
|
|
break;
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_private_two(u_char ch, struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = ictx->ctx.s;
|
2007-10-24 17:40:59 +02:00
|
|
|
|
2008-11-04 21:41:10 +01:00
|
|
|
log_debug2(
|
|
|
|
"-- p2 %zu: %hhu (%c) %hhu", ictx->off, ch, ch, ictx->intermediate);
|
2007-07-09 21:04:12 +02:00
|
|
|
|
|
|
|
switch (ch) {
|
2008-11-04 21:41:10 +01:00
|
|
|
case '0': /* Dscs (graphics) */
|
2009-01-10 02:51:22 +01:00
|
|
|
/*
|
2008-11-04 21:41:10 +01:00
|
|
|
* Not really supported, but fake it up enough for those that
|
|
|
|
* use it to switch character sets (by redefining G0 to
|
|
|
|
* graphics set, rather than switching to G1).
|
|
|
|
*/
|
|
|
|
switch (ictx->intermediate) {
|
|
|
|
case '(': /* G0 */
|
|
|
|
ictx->cell.attr |= GRID_ATTR_CHARSET;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-04 20:28:58 +01:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
case '=': /* DECKPAM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_kkeypadmode(&ictx->ctx, 1);
|
2008-07-24 01:44:50 +02:00
|
|
|
log_debug("kkeypad on (application mode)");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2008-07-24 01:44:50 +02:00
|
|
|
case '>': /* DECKPNM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_kkeypadmode(&ictx->ctx, 0);
|
2008-07-24 01:44:50 +02:00
|
|
|
log_debug("kkeypad off (number mode)");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-10-24 17:01:25 +02:00
|
|
|
case '7': /* DECSC */
|
2008-09-25 22:08:57 +02:00
|
|
|
memcpy(&ictx->saved_cell, &ictx->cell, sizeof ictx->saved_cell);
|
|
|
|
ictx->saved_cx = s->cx;
|
|
|
|
ictx->saved_cy = s->cy;
|
2007-10-24 17:01:25 +02:00
|
|
|
break;
|
|
|
|
case '8': /* DECRC */
|
2008-09-25 22:08:57 +02:00
|
|
|
memcpy(&ictx->cell, &ictx->saved_cell, sizeof ictx->cell);
|
|
|
|
screen_write_cursormove(
|
|
|
|
&ictx->ctx, ictx->saved_cx, ictx->saved_cy);
|
2007-10-24 17:01:25 +02:00
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
default:
|
2007-09-29 00:47:22 +02:00
|
|
|
log_debug("unknown p2: %hhu", ch);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_standard_two(u_char ch, struct input_ctx *ictx)
|
|
|
|
{
|
2008-11-04 21:41:10 +01:00
|
|
|
log_debug2(
|
|
|
|
"-- s2 %zu: %hhu (%c) %hhu", ictx->off, ch, ch, ictx->intermediate);
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2007-11-30 12:08:35 +01:00
|
|
|
switch (ch) {
|
2008-11-04 21:41:10 +01:00
|
|
|
case 'B': /* Dscs (ASCII) */
|
2009-01-10 02:51:22 +01:00
|
|
|
/*
|
2008-11-04 21:41:10 +01:00
|
|
|
* Not really supported, but fake it up enough for those that
|
|
|
|
* use it to switch character sets (by redefining G0 to
|
|
|
|
* graphics set, rather than switching to G1).
|
|
|
|
*/
|
|
|
|
switch (ictx->intermediate) {
|
|
|
|
case '(': /* G0 */
|
|
|
|
ictx->cell.attr &= ~GRID_ATTR_CHARSET;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-04 20:28:58 +01:00
|
|
|
break;
|
2008-09-25 22:08:57 +02:00
|
|
|
case 'c': /* RIS */
|
|
|
|
memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell);
|
|
|
|
|
|
|
|
memcpy(&ictx->saved_cell, &ictx->cell, sizeof ictx->saved_cell);
|
|
|
|
ictx->saved_cx = 0;
|
|
|
|
ictx->saved_cy = 0;
|
|
|
|
|
2008-09-26 09:34:12 +02:00
|
|
|
screen_write_scrollregion(
|
|
|
|
&ictx->ctx, 0, screen_size_y(ictx->ctx.s) - 1);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertmode(&ictx->ctx, 0);
|
|
|
|
screen_write_kcursormode(&ictx->ctx, 0);
|
|
|
|
screen_write_kkeypadmode(&ictx->ctx, 0);
|
|
|
|
screen_write_mousemode(&ictx->ctx, 0);
|
|
|
|
|
|
|
|
screen_write_clearscreen(&ictx->ctx);
|
2008-09-26 08:45:28 +02:00
|
|
|
screen_write_cursormove(&ictx->ctx, 0, 0);
|
2008-09-25 22:08:57 +02:00
|
|
|
break;
|
2007-11-30 12:08:35 +01:00
|
|
|
case 'k':
|
|
|
|
input_start_string(ictx, STRING_NAME);
|
|
|
|
input_state(ictx, input_state_string_next);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_debug("unknown s2: %hhu", ch);
|
|
|
|
break;
|
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence(u_char ch, struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2009-01-07 23:52:33 +01:00
|
|
|
struct input_sequence_entry *entry, find;
|
|
|
|
struct screen *s = ictx->ctx.s;
|
|
|
|
u_int i;
|
|
|
|
struct input_arg *iarg;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-11-23 23:51:13 +01:00
|
|
|
log_debug2("-- sq %zu: %hhu (%c): %u [sx=%u, sy=%u, cx=%u, cy=%u, "
|
|
|
|
"ru=%u, rl=%u]", ictx->off, ch, ch, ARRAY_LENGTH(&ictx->args),
|
|
|
|
screen_size_x(s), screen_size_y(s), s->cx, s->cy, s->rupper,
|
|
|
|
s->rlower);
|
2007-09-29 00:47:22 +02:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(&ictx->args); i++) {
|
|
|
|
iarg = &ARRAY_ITEM(&ictx->args, i);
|
2007-09-29 16:25:49 +02:00
|
|
|
if (*iarg->data != '\0')
|
|
|
|
log_debug2(" ++ %u: %s", i, iarg->data);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2009-01-10 02:51:22 +01:00
|
|
|
|
2009-01-07 23:52:33 +01:00
|
|
|
find.ch = ch;
|
2009-01-10 02:51:22 +01:00
|
|
|
entry = bsearch(&find,
|
2009-01-07 23:52:33 +01:00
|
|
|
input_sequence_table, nitems(input_sequence_table),
|
|
|
|
sizeof input_sequence_table[0], input_sequence_cmp);
|
|
|
|
if (entry != NULL)
|
|
|
|
entry->fn(ictx);
|
|
|
|
else
|
|
|
|
log_debug("unknown sq: %c (%hhu %hhu)", ch, ch, ictx->private);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_cuu(struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
if (n == 0)
|
|
|
|
n = 1;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursorup(&ictx->ctx, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_cud(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursordown(&ictx->ctx, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_cuf(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursorright(&ictx->ctx, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_cub(struct input_ctx *ictx)
|
2007-07-09 21:04:12 +02:00
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
if (n == 0)
|
|
|
|
n = 1;
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursorleft(&ictx->ctx, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
2007-07-09 21:04:12 +02:00
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_dch(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_deletecharacter(&ictx->ctx, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_dl(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_deleteline(&ictx->ctx, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_ich(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertcharacter(&ictx->ctx, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_il(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-11-20 22:42:29 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertline(&ictx->ctx, n);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_vpa(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = ictx->ctx.s;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ictx->ctx, s->cx, n - 1);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_hpa(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = ictx->ctx.s;
|
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
2007-11-20 22:42:29 +01:00
|
|
|
if (n == 0)
|
2007-12-06 10:46:23 +01:00
|
|
|
n = 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ictx->ctx, n - 1, s->cy);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_cup(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n, m;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 2)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 1) != 0)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 1, &m, 1) != 0)
|
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
if (n == 0)
|
|
|
|
n = 1;
|
|
|
|
if (m == 0)
|
|
|
|
m = 1;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ictx->ctx, m - 1, n - 1);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_ed(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
if (n > 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearendofscreen(&ictx->ctx);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
screen_write_clearstartofscreen(&ictx->ctx);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 2:
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearscreen(&ictx->ctx);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_el(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
if (n > 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearendofline(&ictx->ctx);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 1:
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearstartofline(&ictx->ctx);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 2:
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearline(&ictx->ctx);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_sm(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ictx->private == '?') {
|
|
|
|
switch (n) {
|
|
|
|
case 1: /* GATM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_kcursormode(&ictx->ctx, 1);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("kcursor on");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 25: /* TCEM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormode(&ictx->ctx, 1);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("cursor on");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-11-28 00:28:51 +01:00
|
|
|
case 1000:
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_mousemode(&ictx->ctx, 1);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("mouse on");
|
2007-11-28 00:28:51 +01:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown SM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (n) {
|
|
|
|
case 4: /* IRM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertmode(&ictx->ctx, 1);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("insert on");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 34:
|
|
|
|
/* Cursor high visibility not supported. */
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown SM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_rm(struct input_ctx *ictx)
|
|
|
|
{
|
2007-10-24 17:40:59 +02:00
|
|
|
uint16_t n;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ictx->private == '?') {
|
|
|
|
switch (n) {
|
|
|
|
case 1: /* GATM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_kcursormode(&ictx->ctx, 0);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("kcursor off");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 25: /* TCEM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormode(&ictx->ctx, 0);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("cursor off");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-11-28 00:28:51 +01:00
|
|
|
case 1000:
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_mousemode(&ictx->ctx, 0);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("mouse off");
|
2007-11-28 00:28:51 +01:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown RM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
} else if (ictx->private == '\0') {
|
|
|
|
switch (n) {
|
|
|
|
case 4: /* IRM */
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertmode(&ictx->ctx, 0);
|
2008-01-03 22:32:11 +01:00
|
|
|
log_debug("insert off");
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
case 34:
|
|
|
|
/* Cursor high visibility not supported. */
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
2007-09-29 00:47:22 +02:00
|
|
|
default:
|
|
|
|
log_debug("unknown RM [%hhu]: %u", ictx->private, n);
|
2007-07-09 21:04:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:29:29 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_dsr(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = ictx->ctx.s;
|
|
|
|
uint16_t n;
|
|
|
|
char reply[32];
|
2007-10-24 17:29:29 +02:00
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 1)
|
|
|
|
return;
|
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ictx->private == '\0') {
|
|
|
|
switch (n) {
|
|
|
|
case 6: /* cursor position */
|
|
|
|
xsnprintf(reply, sizeof reply,
|
2007-10-24 17:40:59 +02:00
|
|
|
"\033[%u;%uR", s->cy + 1, s->cx + 1);
|
2007-10-24 17:29:29 +02:00
|
|
|
log_debug("cursor request, reply: %s", reply);
|
2009-01-12 00:31:46 +01:00
|
|
|
buffer_write(ictx->wp->out, reply, strlen(reply));
|
2007-10-24 17:29:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:47:22 +02:00
|
|
|
void
|
|
|
|
input_handle_sequence_decstbm(struct input_ctx *ictx)
|
|
|
|
{
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = ictx->ctx.s;
|
|
|
|
uint16_t n, m;
|
2007-09-29 00:47:22 +02:00
|
|
|
|
|
|
|
if (ictx->private != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ARRAY_LENGTH(&ictx->args) > 2)
|
|
|
|
return;
|
2007-10-24 17:01:25 +02:00
|
|
|
if (input_get_argument(ictx, 0, &n, 0) != 0)
|
2007-09-29 00:47:22 +02:00
|
|
|
return;
|
2007-10-24 17:01:25 +02:00
|
|
|
if (input_get_argument(ictx, 1, &m, 0) != 0)
|
2007-09-29 00:47:22 +02:00
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
if (n == 0)
|
2007-10-24 17:01:25 +02:00
|
|
|
n = 1;
|
2007-12-06 10:46:23 +01:00
|
|
|
if (m == 0)
|
2007-11-20 22:42:29 +01:00
|
|
|
m = screen_size_y(s);
|
2007-10-24 17:01:25 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_scrollregion(&ictx->ctx, n - 1, m - 1);
|
2007-09-29 00:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_handle_sequence_sgr(struct input_ctx *ictx)
|
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct grid_cell *gc = &ictx->cell;
|
|
|
|
u_int i;
|
|
|
|
uint16_t m, o;
|
2008-09-26 09:41:01 +02:00
|
|
|
u_char attr;
|
2008-09-09 19:35:04 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ARRAY_LENGTH(&ictx->args) == 0) {
|
2008-09-26 09:41:01 +02:00
|
|
|
attr = gc->attr;
|
2008-09-25 22:08:57 +02:00
|
|
|
memcpy(gc, &grid_default_cell, sizeof *gc);
|
2008-09-26 09:41:01 +02:00
|
|
|
gc->attr |= (attr & GRID_ATTR_CHARSET);
|
2008-09-25 22:08:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(&ictx->args); i++) {
|
|
|
|
if (input_get_argument(ictx, i, &m, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m == 38 || m == 48) {
|
|
|
|
i++;
|
|
|
|
if (input_get_argument(ictx, i, &o, 0) != 0)
|
|
|
|
return;
|
|
|
|
if (o != 5)
|
2008-09-09 19:35:04 +02:00
|
|
|
continue;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
i++;
|
|
|
|
if (input_get_argument(ictx, i, &o, 0) != 0)
|
|
|
|
return;
|
|
|
|
if (m == 38) {
|
|
|
|
gc->flags |= GRID_FLAG_FG256;
|
|
|
|
gc->fg = o;
|
|
|
|
} else if (m == 48) {
|
|
|
|
gc->flags |= GRID_FLAG_BG256;
|
|
|
|
gc->bg = o;
|
2008-09-09 19:35:04 +02:00
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
switch (m) {
|
|
|
|
case 0:
|
|
|
|
case 10:
|
2008-09-26 09:41:01 +02:00
|
|
|
attr = gc->attr;
|
2008-09-25 22:08:57 +02:00
|
|
|
memcpy(gc, &grid_default_cell, sizeof *gc);
|
2008-09-26 09:41:01 +02:00
|
|
|
gc->attr |= (attr & GRID_ATTR_CHARSET);
|
2008-09-25 22:08:57 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
gc->attr |= GRID_ATTR_BRIGHT;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gc->attr |= GRID_ATTR_DIM;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
gc->attr |= GRID_ATTR_ITALICS;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
gc->attr |= GRID_ATTR_UNDERSCORE;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
gc->attr |= GRID_ATTR_BLINK;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
gc->attr |= GRID_ATTR_REVERSE;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
gc->attr |= GRID_ATTR_HIDDEN;
|
|
|
|
break;
|
2008-11-04 21:41:10 +01:00
|
|
|
case 22:
|
|
|
|
gc->attr &= ~(GRID_ATTR_BRIGHT|GRID_ATTR_DIM);
|
|
|
|
break;
|
2008-09-25 22:08:57 +02:00
|
|
|
case 23:
|
|
|
|
gc->attr &= ~GRID_ATTR_ITALICS;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
gc->attr &= ~GRID_ATTR_UNDERSCORE;
|
|
|
|
break;
|
2008-11-04 21:41:10 +01:00
|
|
|
case 25:
|
|
|
|
gc->attr &= ~GRID_ATTR_BLINK;
|
|
|
|
break;
|
|
|
|
case 27:
|
|
|
|
gc->attr &= ~GRID_ATTR_REVERSE;
|
|
|
|
break;
|
2008-09-25 22:08:57 +02:00
|
|
|
case 30:
|
|
|
|
case 31:
|
|
|
|
case 32:
|
|
|
|
case 33:
|
|
|
|
case 34:
|
|
|
|
case 35:
|
|
|
|
case 36:
|
|
|
|
case 37:
|
|
|
|
gc->flags &= ~GRID_FLAG_FG256;
|
|
|
|
gc->fg = m - 30;
|
|
|
|
break;
|
|
|
|
case 39:
|
|
|
|
gc->flags &= ~GRID_FLAG_FG256;
|
|
|
|
gc->fg = 8;
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
case 41:
|
|
|
|
case 42:
|
|
|
|
case 43:
|
|
|
|
case 44:
|
|
|
|
case 45:
|
|
|
|
case 46:
|
2008-09-26 08:45:28 +02:00
|
|
|
case 47:
|
2008-09-25 22:08:57 +02:00
|
|
|
gc->flags &= ~GRID_FLAG_BG256;
|
|
|
|
gc->bg = m - 40;
|
|
|
|
break;
|
|
|
|
case 49:
|
|
|
|
gc->flags &= ~GRID_FLAG_BG256;
|
|
|
|
gc->bg = 8;
|
|
|
|
break;
|
2007-07-09 21:04:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|