From 7f424e2b65779c59fc0cac3cc7508ba2ec07f200 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 23 Feb 2023 18:29:36 +0100 Subject: feat(api): more fields in nvim_list_uis Problem: nvim_list_uis does not report all ":help ui-option" fields. Solution: Store ":help ui-option" fields on the `UI` object and update ui_array. --- src/nvim/ui.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 73545441d3..6c95579b47 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -598,6 +598,15 @@ Array ui_array(void) PUT(info, "height", INTEGER_OBJ(ui->height)); PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb)); PUT(info, "override", BOOLEAN_OBJ(ui->override)); + + // TUI fields. + PUT(info, "term_name", STRING_OBJ(cstr_to_string(ui->term_name))); + PUT(info, "term_background", STRING_OBJ(cstr_to_string(ui->term_background))); + PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors)); + PUT(info, "stdin_fd", INTEGER_OBJ(ui->stdin_fd)); + PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty)); + PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty)); + for (UIExtension j = 0; j < kUIExtCount; j++) { if (ui_ext_names[j][0] != '_' || ui->ui_ext[j]) { PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j])); -- cgit From ce597235a26839826de88ecd8b949ec54c310fbd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Feb 2023 16:31:05 +0100 Subject: feat(ui): restore has('gui_running') Problem: has('gui_running') is still common in the wild and our answer has changed over time, causing frustration. https://github.com/vimpostor/vim-tpipeline/commit/95a6ccbe9f33bc42dd4cee45731d8bc3fbcd92d1 Solution: Use stdin_tty/stdout_tty to decide if a UI is (not) a GUI. --- src/nvim/ui.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 6c95579b47..ce1a57350a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -134,6 +134,7 @@ void ui_free_all_mem(void) } #endif +/// Returns true if any `rgb=true` UI is attached. bool ui_rgb_attached(void) { if (!headless_mode && p_tgc) { @@ -147,6 +148,18 @@ bool ui_rgb_attached(void) return false; } +/// Returns true if a GUI is attached. +bool ui_gui_attached(void) +{ + for (size_t i = 0; i < ui_count; i++) { + bool tui = uis[i]->stdin_tty || uis[i]->stdout_tty; + if (!tui) { + return true; + } + } + return false; +} + /// Returns true if any UI requested `override=true`. bool ui_override(void) { @@ -599,11 +612,10 @@ Array ui_array(void) PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb)); PUT(info, "override", BOOLEAN_OBJ(ui->override)); - // TUI fields. + // TUI fields. (`stdin_fd` is intentionally omitted.) PUT(info, "term_name", STRING_OBJ(cstr_to_string(ui->term_name))); PUT(info, "term_background", STRING_OBJ(cstr_to_string(ui->term_background))); PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors)); - PUT(info, "stdin_fd", INTEGER_OBJ(ui->stdin_fd)); PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty)); PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty)); -- cgit