diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-05-17 20:52:45 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-05-17 20:52:45 +0200 |
commit | c4c9f7e43e7229c78919a5618003ce8aac3e1785 (patch) | |
tree | 14762fba1482375785517d5f23871b0abdf7a078 /src/libvterm | |
parent | df1643a6a7886b9363c2a98438e61cbe1c803d41 (diff) | |
download | vim-git-c4c9f7e43e7229c78919a5618003ce8aac3e1785.tar.gz |
patch 8.2.0783: libvterm code lags behind the upstream versionv8.2.0783
Problem: Libvterm code lags behind the upstream version.
Solution: Include revisions 728 - 729.
Diffstat (limited to 'src/libvterm')
-rw-r--r-- | src/libvterm/src/keyboard.c | 8 | ||||
-rw-r--r-- | src/libvterm/src/vterm.c | 88 | ||||
-rw-r--r-- | src/libvterm/src/vterm_internal.h | 3 | ||||
-rw-r--r-- | src/libvterm/t/25state_input.test | 12 | ||||
-rw-r--r-- | src/libvterm/t/26state_query.test | 2 | ||||
-rw-r--r-- | src/libvterm/t/harness.c | 1 |
6 files changed, 62 insertions, 52 deletions
diff --git a/src/libvterm/src/keyboard.c b/src/libvterm/src/keyboard.c index 95b962ed6..9c2a53d7b 100644 --- a/src/libvterm/src/keyboard.c +++ b/src/libvterm/src/keyboard.c @@ -102,10 +102,10 @@ static keycodes_s keycodes[] = { static keycodes_s keycodes_fn[] = { { KEYCODE_NONE, 0, 0 }, // F0 - shouldn't happen - { KEYCODE_CSI_CURSOR, 'P', 0 }, // F1 - { KEYCODE_CSI_CURSOR, 'Q', 0 }, // F2 - { KEYCODE_CSI_CURSOR, 'R', 0 }, // F3 - { KEYCODE_CSI_CURSOR, 'S', 0 }, // F4 + { KEYCODE_SS3, 'P', 0 }, // F1 + { KEYCODE_SS3, 'Q', 0 }, // F2 + { KEYCODE_SS3, 'R', 0 }, // F3 + { KEYCODE_SS3, 'S', 0 }, // F4 { KEYCODE_CSINUM, '~', 15 }, // F5 { KEYCODE_CSINUM, '~', 17 }, // F6 { KEYCODE_CSINUM, '~', 18 }, // F7 diff --git a/src/libvterm/src/vterm.c b/src/libvterm/src/vterm.c index 1d6a977f1..56c4e28d9 100644 --- a/src/libvterm/src/vterm.c +++ b/src/libvterm/src/vterm.c @@ -74,6 +74,9 @@ VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *fun return NULL; } + vt->tmpbuffer_len = 64; + vt->tmpbuffer = vterm_allocator_malloc(vt, vt->tmpbuffer_len); + return vt; } @@ -135,67 +138,46 @@ void vterm_set_utf8(VTerm *vt, int is_utf8) INTERNAL void vterm_push_output_bytes(VTerm *vt, const char *bytes, size_t len) { if(len > vt->outbuffer_len - vt->outbuffer_cur) { - DEBUG_LOG("vterm_push_output(): buffer overflow; truncating output\n"); - len = vt->outbuffer_len - vt->outbuffer_cur; + DEBUG_LOG("vterm_push_output_bytes(): buffer overflow; dropping output\n"); + return; } memcpy(vt->outbuffer + vt->outbuffer_cur, bytes, len); vt->outbuffer_cur += len; } -static int outbuffer_is_full(VTerm *vt) -{ - return vt->outbuffer_cur >= vt->outbuffer_len - 1; -} - #if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500) \ || defined(_ISOC99_SOURCE) || defined(_BSD_SOURCE) # undef VSNPRINTF # define VSNPRINTF vsnprintf +# undef SNPRINTF +# define SNPRINTF snprintf #else # ifdef VSNPRINTF // Use a provided vsnprintf() function. int VSNPRINTF(char *str, size_t str_m, const char *fmt, va_list ap); # endif +# ifdef SNPRINTF +// Use a provided snprintf() function. +int SNPRINTF(char *str, size_t str_m, const char *fmt, ...); +# endif #endif INTERNAL void vterm_push_output_vsprintf(VTerm *vt, const char *format, va_list args) { - int written; + size_t len; #ifndef VSNPRINTF // When vsnprintf() is not available (C90) fall back to vsprintf(). char buffer[1024]; // 1Kbyte is enough for everybody, right? #endif - if(outbuffer_is_full(vt)) { - DEBUG_LOG("vterm_push_output(): buffer overflow; truncating output\n"); - return; - } - #ifdef VSNPRINTF - written = VSNPRINTF(vt->outbuffer + vt->outbuffer_cur, - vt->outbuffer_len - vt->outbuffer_cur, - format, args); - - if(written == (int)(vt->outbuffer_len - vt->outbuffer_cur)) { - // output was truncated - vt->outbuffer_cur = vt->outbuffer_len - 1; - } - else - vt->outbuffer_cur += written; + len = VSNPRINTF(vt->tmpbuffer, vt->tmpbuffer_len, format, args); + vterm_push_output_bytes(vt, vt->tmpbuffer, len); #else - written = vsprintf(buffer, format, args); - - if(written >= (int)(vt->outbuffer_len - vt->outbuffer_cur - 1)) { - // output was truncated - written = vt->outbuffer_len - vt->outbuffer_cur - 1; - } - if (written > 0) - { - strncpy(vt->outbuffer + vt->outbuffer_cur, buffer, written + 1); - vt->outbuffer_cur += written; - } + len = vsprintf(buffer, format, args); + vterm_push_output_bytes(vt, buffer, len); #endif } @@ -209,40 +191,52 @@ INTERNAL void vterm_push_output_sprintf(VTerm *vt, const char *format, ...) INTERNAL void vterm_push_output_sprintf_ctrl(VTerm *vt, unsigned char ctrl, const char *fmt, ...) { - size_t orig_cur = vt->outbuffer_cur; + size_t cur; va_list args; if(ctrl >= 0x80 && !vt->mode.ctrl8bit) - vterm_push_output_sprintf(vt, ESC_S "%c", ctrl - 0x40); + cur = SNPRINTF(vt->tmpbuffer, vt->tmpbuffer_len, + ESC_S "%c", ctrl - 0x40); else - vterm_push_output_sprintf(vt, "%c", ctrl); + cur = SNPRINTF(vt->tmpbuffer, vt->tmpbuffer_len, + "%c", ctrl); + if(cur >= vt->tmpbuffer_len) + return; + vterm_push_output_bytes(vt, vt->tmpbuffer, cur); va_start(args, fmt); vterm_push_output_vsprintf(vt, fmt, args); va_end(args); - - if(outbuffer_is_full(vt)) - vt->outbuffer_cur = orig_cur; } INTERNAL void vterm_push_output_sprintf_dcs(VTerm *vt, const char *fmt, ...) { - size_t orig_cur = vt->outbuffer_cur; + size_t cur; va_list args; if(!vt->mode.ctrl8bit) - vterm_push_output_sprintf(vt, ESC_S "%c", C1_DCS - 0x40); + cur = SNPRINTF(vt->tmpbuffer, vt->tmpbuffer_len, + ESC_S "%c", C1_DCS - 0x40); else - vterm_push_output_sprintf(vt, "%c", C1_DCS); + cur = SNPRINTF(vt->tmpbuffer, vt->tmpbuffer_len, + "%c", C1_DCS); + if(cur >= vt->tmpbuffer_len) + return; + vterm_push_output_bytes(vt, vt->tmpbuffer, cur); va_start(args, fmt); vterm_push_output_vsprintf(vt, fmt, args); va_end(args); - vterm_push_output_sprintf_ctrl(vt, C1_ST, ""); - - if(outbuffer_is_full(vt)) - vt->outbuffer_cur = orig_cur; + if(!vt->mode.ctrl8bit) + cur = SNPRINTF(vt->tmpbuffer, vt->tmpbuffer_len, + ESC_S "%c", C1_ST - 0x40); + else + cur = SNPRINTF(vt->tmpbuffer, vt->tmpbuffer_len, + "%c", C1_ST); + if(cur >= vt->tmpbuffer_len) + return; + vterm_push_output_bytes(vt, vt->tmpbuffer, cur); } size_t vterm_output_get_buffer_size(const VTerm *vt) diff --git a/src/libvterm/src/vterm_internal.h b/src/libvterm/src/vterm_internal.h index e2b8b159b..6aa1e9cc4 100644 --- a/src/libvterm/src/vterm_internal.h +++ b/src/libvterm/src/vterm_internal.h @@ -211,6 +211,9 @@ struct VTerm size_t outbuffer_len; size_t outbuffer_cur; + char *tmpbuffer; + size_t tmpbuffer_len; + VTermState *state; VTermScreen *screen; diff --git a/src/libvterm/t/25state_input.test b/src/libvterm/t/25state_input.test index a5119fbd8..4eb4c6abd 100644 --- a/src/libvterm/t/25state_input.test +++ b/src/libvterm/t/25state_input.test @@ -111,6 +111,18 @@ PUSH "\e[20h" INKEY 0 Enter output "\x0d\x0a" +!Unmodified F1 is SS3 P +INKEY 0 F1 + output "\eOP" + +!Modified F1 is CSI P +INKEY S F1 + output "\e[1;2P" +INKEY A F1 + output "\e[1;3P" +INKEY C F1 + output "\e[1;5P" + !Keypad in DECKPNM INKEY 0 KP0 output "0" diff --git a/src/libvterm/t/26state_query.test b/src/libvterm/t/26state_query.test index 3ace2d532..c6be90b61 100644 --- a/src/libvterm/t/26state_query.test +++ b/src/libvterm/t/26state_query.test @@ -59,4 +59,4 @@ PUSH "\e F" !Truncation on attempted buffer overflow PUSH "\e[6n" x 30 - output "\e[10;10R" x 24 + output "\e[10;10R" x 25 diff --git a/src/libvterm/t/harness.c b/src/libvterm/t/harness.c index 75869d756..e28bb7d30 100644 --- a/src/libvterm/t/harness.c +++ b/src/libvterm/t/harness.c @@ -47,6 +47,7 @@ static VTermKey strp_key(char *str) { "Tab", VTERM_KEY_TAB }, { "Enter", VTERM_KEY_ENTER }, { "KP0", VTERM_KEY_KP_0 }, + { "F1", VTERM_KEY_FUNCTION(1) }, { NULL, VTERM_KEY_NONE }, }; int i; |