diff options
Diffstat (limited to 'src/nvim/tui')
-rw-r--r-- | src/nvim/tui/input.c | 42 | ||||
-rw-r--r-- | src/nvim/tui/input.h | 8 | ||||
-rw-r--r-- | src/nvim/tui/terminfo.c | 6 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 47 |
4 files changed, 41 insertions, 62 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index b837a380d5..733aa25f03 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -8,31 +8,27 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/vim.h" #include "nvim/ascii.h" -#include "nvim/autocmd.h" #include "nvim/charset.h" #include "nvim/event/defs.h" -#include "nvim/event/multiqueue.h" -#include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" #include "nvim/main.h" #include "nvim/map.h" #include "nvim/memory.h" -#include "nvim/message.h" #include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/tui/input.h" #include "nvim/tui/input_defs.h" #include "nvim/tui/tui.h" +#include "nvim/types.h" +#include "nvim/ui_client.h" #ifdef MSWIN # include "nvim/os/os_win_console.h" #endif #include "nvim/event/rstream.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/ui.h" #define KEY_BUFFER_SIZE 0xfff @@ -121,14 +117,6 @@ static const struct kitty_key_map_entry { static Map(KittyKey, cstr_t) kitty_key_map = MAP_INIT; -#ifndef UNIT_TESTING -typedef enum { - kIncomplete = -1, - kNotApplicable = 0, - kComplete = 1, -} HandleState; -#endif - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "tui/input.c.generated.h" #endif @@ -153,19 +141,7 @@ void tinput_init(TermInput *input, Loop *loop) kitty_key_map_entry[i].name); } - // If stdin is not a pty, switch to stderr. For cases like: - // echo q | nvim -es - // ls *.md | xargs nvim -#ifdef MSWIN - if (!os_isatty(input->in_fd)) { - input->in_fd = os_get_conin_fd(); - } -#else - if (!os_isatty(input->in_fd) && os_isatty(STDERR_FILENO)) { - input->in_fd = STDERR_FILENO; - } -#endif - input_global_fd_init(input->in_fd); + input->in_fd = STDIN_FILENO; const char *term = os_getenv("TERM"); if (!term) { @@ -174,7 +150,7 @@ void tinput_init(TermInput *input, Loop *loop) input->tk = termkey_new_abstract(term, TERMKEY_FLAG_UTF8 | TERMKEY_FLAG_NOSTART); - termkey_hook_terminfo_getstr(input->tk, input->tk_ti_hook_fn, NULL); + termkey_hook_terminfo_getstr(input->tk, input->tk_ti_hook_fn, input); termkey_start(input->tk); int curflags = termkey_get_canonflags(input->tk); @@ -600,7 +576,7 @@ static void set_bg(char *bgvalue) // ignored in the calculations. // // [1] https://en.wikipedia.org/wiki/Luma_%28video%29 -static HandleState handle_background_color(TermInput *input) +HandleState handle_background_color(TermInput *input) { if (input->waiting_for_bg_response <= 0) { return kNotApplicable; @@ -671,7 +647,7 @@ static HandleState handle_background_color(TermInput *input) bool is_dark = luminance < 0.5; char *bgvalue = is_dark ? "dark" : "light"; DLOG("bg response: %s", bgvalue); - ui_client_bg_respose = is_dark ? kTrue : kFalse; + ui_client_bg_response = is_dark ? kTrue : kFalse; set_bg(bgvalue); input->waiting_for_bg_response = 0; } else if (!done && !bad) { @@ -685,12 +661,6 @@ static HandleState handle_background_color(TermInput *input) } return kComplete; } -#ifdef UNIT_TESTING -HandleState ut_handle_background_color(TermInput *input) -{ - return handle_background_color(input); -} -#endif static void handle_raw_buffer(TermInput *input, bool force) { diff --git a/src/nvim/tui/input.h b/src/nvim/tui/input.h index 5df108b107..d33cea6383 100644 --- a/src/nvim/tui/input.h +++ b/src/nvim/tui/input.h @@ -40,18 +40,14 @@ typedef struct term_input { TUIData *tui_data; } TermInput; -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "tui/input.h.generated.h" -#endif - -#ifdef UNIT_TESTING typedef enum { kIncomplete = -1, kNotApplicable = 0, kComplete = 1, } HandleState; -HandleState ut_handle_background_color(TermInput *input); +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "tui/input.h.generated.h" #endif #endif // NVIM_TUI_INPUT_H diff --git a/src/nvim/tui/terminfo.c b/src/nvim/tui/terminfo.c index 507e9df21e..d630a34ce2 100644 --- a/src/nvim/tui/terminfo.c +++ b/src/nvim/tui/terminfo.c @@ -7,12 +7,12 @@ #include <string.h> #include <unibilium.h> +#include "klib/kvec.h" +#include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" +#include "nvim/ascii.h" #include "nvim/charset.h" -#include "nvim/globals.h" #include "nvim/memory.h" -#include "nvim/message.h" -#include "nvim/option.h" #include "nvim/strings.h" #include "nvim/tui/terminfo.h" #include "nvim/tui/terminfo_defs.h" diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 44f6718039..ceda3b2076 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -16,7 +16,6 @@ #include "klib/kvec.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/vim.h" #include "nvim/ascii.h" #include "nvim/cursor_shape.h" #include "nvim/event/defs.h" @@ -32,12 +31,10 @@ #include "nvim/main.h" #include "nvim/mbyte.h" #include "nvim/memory.h" -#include "nvim/message.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/os.h" -#include "nvim/os/signal.h" +#include "nvim/ui_client.h" #ifdef MSWIN # include "nvim/os/os_win_console.h" #endif @@ -46,7 +43,6 @@ #include "nvim/tui/tui.h" #include "nvim/ugrid.h" #include "nvim/ui.h" -#include "nvim/vim.h" // Space reserved in two output buffers to make the cursor normal or invisible // when flushing. No existing terminal will require 32 bytes to do that. @@ -141,6 +137,7 @@ struct TUIData { int enable_bracketed_paste, disable_bracketed_paste; int enable_lr_margin, disable_lr_margin; int enter_strikethrough_mode; + int enter_altfont_mode; int set_rgb_foreground, set_rgb_background; int set_cursor_color; int reset_cursor_color; @@ -255,6 +252,7 @@ static void terminfo_start(TUIData *tui) tui->unibi_ext.enable_bracketed_paste = -1; tui->unibi_ext.disable_bracketed_paste = -1; tui->unibi_ext.enter_strikethrough_mode = -1; + tui->unibi_ext.enter_altfont_mode = -1; tui->unibi_ext.enable_lr_margin = -1; tui->unibi_ext.disable_lr_margin = -1; tui->unibi_ext.enable_focus_reporting = -1; @@ -460,7 +458,11 @@ static void tui_terminal_stop(TUIData *tui) void tui_stop(TUIData *tui) { + if (tui->stopped) { + return; + } tui_terminal_stop(tui); + stream_set_blocking(tui->input.in_fd, true); // normalize stream (#2598) tinput_destroy(&tui->input); tui->stopped = true; signal_watcher_close(&tui->winch_handle, NULL); @@ -515,7 +517,7 @@ static bool attrs_differ(TUIData *tui, int id1, int id2, bool rgb) return a1.cterm_fg_color != a2.cterm_fg_color || a1.cterm_bg_color != a2.cterm_bg_color || a1.cterm_ae_attr != a2.cterm_ae_attr - || (a1.cterm_ae_attr & HL_ANY_UNDERLINE + || (a1.cterm_ae_attr & HL_UNDERLINE_MASK && a1.rgb_sp_color != a2.rgb_sp_color); } } @@ -535,6 +537,7 @@ static void update_attrs(TUIData *tui, int attr_id) bool reverse = attr & HL_INVERSE; bool standout = attr & HL_STANDOUT; bool strikethrough = attr & HL_STRIKETHROUGH; + bool altfont = attr & HL_ALTFONT; bool underline; bool undercurl; @@ -542,13 +545,14 @@ static void update_attrs(TUIData *tui, int attr_id) bool underdotted; bool underdashed; if (tui->unibi_ext.set_underline_style != -1) { - underline = attr & HL_UNDERLINE; - undercurl = attr & HL_UNDERCURL; - underdouble = attr & HL_UNDERDOUBLE; - underdashed = attr & HL_UNDERDASHED; - underdotted = attr & HL_UNDERDOTTED; + int ul = attr & HL_UNDERLINE_MASK; + underline = ul == HL_UNDERLINE; + undercurl = ul == HL_UNDERCURL; + underdouble = ul == HL_UNDERDOUBLE; + underdashed = ul == HL_UNDERDASHED; + underdotted = ul == HL_UNDERDOTTED; } else { - underline = attr & HL_ANY_UNDERLINE; + underline = attr & HL_UNDERLINE_MASK; undercurl = false; underdouble = false; underdotted = false; @@ -593,6 +597,9 @@ static void update_attrs(TUIData *tui, int attr_id) if (italic) { unibi_out(tui, unibi_enter_italics_mode); } + if (altfont && tui->unibi_ext.enter_altfont_mode != -1) { + unibi_out_ext(tui, tui->unibi_ext.enter_altfont_mode); + } if (strikethrough && tui->unibi_ext.enter_strikethrough_mode != -1) { unibi_out_ext(tui, tui->unibi_ext.enter_strikethrough_mode); } @@ -1342,7 +1349,7 @@ static void suspend_event(void **argv) TUIData *tui = argv[0]; bool enable_mouse = tui->mouse_enabled; tui_terminal_stop(tui); - stream_set_blocking(input_global_fd(), true); // normalize stream (#2598) + stream_set_blocking(tui->input.in_fd, true); // normalize stream (#2598) kill(0, SIGTSTP); @@ -1351,7 +1358,7 @@ static void suspend_event(void **argv) if (enable_mouse) { tui_mouse_on(tui); } - stream_set_blocking(input_global_fd(), false); // libuv expects this + stream_set_blocking(tui->input.in_fd, false); // libuv expects this } #endif @@ -2041,6 +2048,11 @@ static void augment_terminfo(TUIData *tui, const char *term, long vte_version, l // to the ECMA-48 strikeout/crossed-out attributes. tui->unibi_ext.enter_strikethrough_mode = unibi_find_ext_str(ut, "smxx"); + // It should be pretty safe to always enable this, as terminals will ignore + // unrecognised SGR numbers. + tui->unibi_ext.enter_altfont_mode = (int)unibi_add_ext_str(ut, "ext.enter_altfont_mode", + "\x1b[11m"); + // Dickey ncurses terminfo does not include the setrgbf and setrgbb // capabilities, proposed by RĂ¼diger Sonderfeld on 2013-10-15. Adding // them here when terminfo lacks them is an augmentation, not a fixup. @@ -2238,12 +2250,12 @@ static void flush_buf(TUIData *tui) /// /// @see tmux/tty-keys.c fe4e9470bb504357d073320f5d305b22663ee3fd /// @see https://bugzilla.redhat.com/show_bug.cgi?id=142659 -static const char *tui_get_stty_erase(void) +static const char *tui_get_stty_erase(int fd) { static char stty_erase[2] = { 0 }; #if defined(HAVE_TERMIOS_H) struct termios t; - if (tcgetattr(input_global_fd(), &t) != -1) { + if (tcgetattr(fd, &t) != -1) { stty_erase[0] = (char)t.c_cc[VERASE]; stty_erase[1] = '\0'; DLOG("stty/termios:erase=%s", stty_erase); @@ -2256,9 +2268,10 @@ static const char *tui_get_stty_erase(void) /// @see TermInput.tk_ti_hook_fn static const char *tui_tk_ti_getstr(const char *name, const char *value, void *data) { + TermInput *input = data; static const char *stty_erase = NULL; if (stty_erase == NULL) { - stty_erase = tui_get_stty_erase(); + stty_erase = tui_get_stty_erase(input->in_fd); } if (strequal(name, "key_backspace")) { |