api: include border in nvim_win_get_config

This commit is contained in:
Corey Williamson 2021-04-19 18:47:42 -05:00 committed by Björn Linse
parent 21645e603c
commit 8021c5a531
2 changed files with 60 additions and 6 deletions

View File

@ -6,20 +6,21 @@
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include "nvim/ascii.h"
#include "nvim/globals.h"
#include "nvim/api/window.h"
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/lua/executor.h" #include "nvim/lua/executor.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/api/window.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/option.h" #include "nvim/globals.h"
#include "nvim/window.h"
#include "nvim/screen.h"
#include "nvim/move.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 /// 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, "row", FLOAT_OBJ(config->row));
PUT(rv, "col", FLOAT_OBJ(config->col)); 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 const char *rel = (wp->w_floating && !config->external

View File

@ -401,4 +401,36 @@ describe('API/win', function()
eq(1, funcs.exists('g:fired')) eq(1, funcs.exists('g:fired'))
end) end)
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) end)