diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-10 01:10:33 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-10 01:10:33 +0200 |
commit | 5c03486f86e32a0ca735bfb06cebd32f4ecd19e2 (patch) | |
tree | 2e1723e55af65a1e3e0826efb43fdf480f554eaa | |
parent | Add support for cursor position and device status reports (diff) | |
download | libterminput-5c03486f86e32a0ca735bfb06cebd32f4ecd19e2.tar.gz libterminput-5c03486f86e32a0ca735bfb06cebd32f4ecd19e2.tar.bz2 libterminput-5c03486f86e32a0ca735bfb06cebd32f4ecd19e2.tar.xz |
Fix cursor pos report and update interactive test
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | interactive-test.c | 12 | ||||
-rw-r--r-- | libterminput.c | 18 | ||||
-rw-r--r-- | libterminput_read.3 | 4 | ||||
-rw-r--r-- | libterminput_set_flags.3 | 5 |
4 files changed, 27 insertions, 12 deletions
diff --git a/interactive-test.c b/interactive-test.c index 57bb20c..1eb3531 100644 --- a/interactive-test.c +++ b/interactive-test.c @@ -42,6 +42,10 @@ main(void) fprintf(stderr, "LIBTERMINPUT_ESC_ON_BLOCK set\n"); libterminput_set_flags(&ctx, LIBTERMINPUT_ESC_ON_BLOCK); } + if (getenv("TEST_LIBTERMINPUT_AWAITING_CURSOR_POSITION")) { + fprintf(stderr, "LIBTERMINPUT_AWAITING_CURSOR_POSITION set\n"); + libterminput_set_flags(&ctx, LIBTERMINPUT_AWAITING_CURSOR_POSITION); + } if (tcgetattr(STDERR_FILENO, &stty)) { perror("tcgetattr STDERR_FILENO"); @@ -167,6 +171,14 @@ main(void) printf("\033[1;4;4;10;10T"); fflush(stdout); } + } else if (input.type == LIBTERMINPUT_TERMINAL_IS_OK) { + printf("terminal ok\n"); + } else if (input.type == LIBTERMINPUT_TERMINAL_IS_NOT_OK) { + printf("terminal not ok\n"); + } else if (input.type == LIBTERMINPUT_CURSOR_POSITION) { + printf("cursor position:\n"); + printf("\tx: %zu\n", input.position.x); + printf("\ty: %zu\n", input.position.y); } else { printf("other\n"); } diff --git a/libterminput.c b/libterminput.c index 5d6f401..ed2415f 100644 --- a/libterminput.c +++ b/libterminput.c @@ -398,19 +398,25 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx) } break; case 'P': + input->keypress.key = LIBTERMINPUT_F1; + if (ctx->flags & LIBTERMINPUT_PAUSE_ON_CSI_P) + input->keypress.key = LIBTERMINPUT_PAUSE; + break; + case 'Q': + input->keypress.key = LIBTERMINPUT_F2; + break; + case 'R': if ((ctx->flags & LIBTERMINPUT_AWAITING_CURSOR_POSITION) && nnums == 2) { input->position.type = LIBTERMINPUT_CURSOR_POSITION; input->position.y = (size_t)nums[0] + (size_t)!nums[0]; input->position.x = (size_t)nums[1] + (size_t)!nums[1]; } else { - input->keypress.key = LIBTERMINPUT_F1; - if (ctx->flags & LIBTERMINPUT_PAUSE_ON_CSI_P) - input->keypress.key = LIBTERMINPUT_PAUSE; + input->keypress.key = LIBTERMINPUT_F3; } break; - case 'Q': input->keypress.key = LIBTERMINPUT_F2; break; - case 'R': input->keypress.key = LIBTERMINPUT_F3; break; - case 'S': input->keypress.key = LIBTERMINPUT_F4; break; + case 'S': + input->keypress.key = LIBTERMINPUT_F4; + break; case 'T': /* Parsing output for legacy mouse highlight tracking output. (\e[?1001h) */ ctx->mouse_tracking = 0; diff --git a/libterminput_read.3 b/libterminput_read.3 index 09f0212..b92eddc 100644 --- a/libterminput_read.3 +++ b/libterminput_read.3 @@ -419,8 +419,8 @@ and the column (indexed starting with 1 at the left edge) will be stored in .I input->position.x -This event can conflict with both F1 and pause -key processes, therefore the +This event can conflict with F3 key presses, +therefore the .B LIBTERMINPUT_AWAITING_CURSOR_POSITION flag must be set with the .BR libterminput_set_flags (3) diff --git a/libterminput_set_flags.3 b/libterminput_set_flags.3 index 4560971..af1908a 100644 --- a/libterminput_set_flags.3 +++ b/libterminput_set_flags.3 @@ -87,10 +87,7 @@ does not support (yes, this is a real world issue). The sequence .BI "CSI " Ps " ; " Rs " R" shall be parsed as a cursor position report rather -than as an F1 or pause key press. This flag takes -precedence over the -.B LIBTERMINPUT_PAUSE_ON_CSI_P -flag. +than as an F3 key press. .PP .I ctx must have been zero-initialised, e.g. with |