From 8021c5a5311a322fec12b4b188ad96d8465ea94c Mon Sep 17 00:00:00 2001 From: Corey Williamson Date: Mon, 19 Apr 2021 18:47:42 -0500 Subject: [PATCH 1/3] api: include border in nvim_win_get_config --- src/nvim/api/window.c | 34 ++++++++++++++++++++++++----- test/functional/api/window_spec.lua | 32 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 178375d7f1..8514ac6b5f 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -6,20 +6,21 @@ #include #include -#include "nvim/ascii.h" -#include "nvim/globals.h" -#include "nvim/api/window.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/lua/executor.h" #include "nvim/ex_docmd.h" #include "nvim/vim.h" +#include "nvim/api/window.h" +#include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/cursor.h" -#include "nvim/option.h" -#include "nvim/window.h" -#include "nvim/screen.h" +#include "nvim/globals.h" #include "nvim/move.h" +#include "nvim/option.h" +#include "nvim/screen.h" +#include "nvim/syntax.h" +#include "nvim/window.h" /// Gets the current buffer in a window /// @@ -456,6 +457,27 @@ Dictionary nvim_win_get_config(Window window, Error *err) PUT(rv, "row", FLOAT_OBJ(config->row)); PUT(rv, "col", FLOAT_OBJ(config->col)); } + if (config->border) { + Array border = ARRAY_DICT_INIT; + for (size_t i = 0; i < 8; i++) { + Array tuple = ARRAY_DICT_INIT; + + String s = cstrn_to_string((const char *)config->border_chars[i], sizeof(schar_T)); + + int hi_id = config->border_hl_ids[i]; + char_u *hi_name = syn_id2name(hi_id); + if (hi_name[0]) { + ADD(tuple, STRING_OBJ(s)); + ADD(tuple, STRING_OBJ(cstr_to_string((const char *)hi_name))); + ADD(border, ARRAY_OBJ(tuple)); + } else { + ADD(border, STRING_OBJ(s)); + } + } + PUT(rv, "border", ARRAY_OBJ(border)); + } else { + PUT(rv, "border", STRING_OBJ(cstr_to_string("none"))); + } } const char *rel = (wp->w_floating && !config->external diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index a57826f7e7..bb72b63b6c 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -401,4 +401,36 @@ describe('API/win', function() eq(1, funcs.exists('g:fired')) end) end) + + describe('get_config', function() + it('includes border', function() + local b = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' } + local win = meths.open_win(0, true, { + relative='win', row=3, col=3, width=12, height=3, + border = b, + }) + + local cfg = meths.win_get_config(win) + eq(b, cfg.border) + end) + it('includes border with highlight group', function() + local b = { + {'a', 'Normal'}, + {'b', 'Special'}, + {'c', 'String'}, + {'d', 'Comment'}, + {'e', 'Visual'}, + {'f', 'Error'}, + {'g', 'Constant'}, + {'h', 'PreProc'}, + } + local win = meths.open_win(0, true, { + relative='win', row=3, col=3, width=12, height=3, + border = b, + }) + + local cfg = meths.win_get_config(win) + eq(b, cfg.border) + end) + end) end) From 38d6452899630d3ad4e42eb2ae635473a1fe2d67 Mon Sep 17 00:00:00 2001 From: Corey Williamson Date: Tue, 20 Apr 2021 16:05:20 -0500 Subject: [PATCH 2/3] fix linter errors --- src/nvim/api/window.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 8514ac6b5f..0e96effb64 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -462,7 +462,8 @@ Dictionary nvim_win_get_config(Window window, Error *err) for (size_t i = 0; i < 8; i++) { Array tuple = ARRAY_DICT_INIT; - String s = cstrn_to_string((const char *)config->border_chars[i], sizeof(schar_T)); + String s = cstrn_to_string( + (const char *)config->border_chars[i], sizeof(schar_T)); int hi_id = config->border_hl_ids[i]; char_u *hi_name = syn_id2name(hi_id); From 7b519cd11cee564813067a818c11fbc7a29e08c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Thu, 10 Jun 2021 10:08:23 +0200 Subject: [PATCH 3/3] api:get_config: don't add border="none" (inactive default) --- src/nvim/api/window.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 0e96effb64..0729024b45 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -476,8 +476,6 @@ Dictionary nvim_win_get_config(Window window, Error *err) } } PUT(rv, "border", ARRAY_OBJ(border)); - } else { - PUT(rv, "border", STRING_OBJ(cstr_to_string("none"))); } }