Skip to content

Commit 54ee52a

Browse files
feat: add default = true for highlight groups definition. (#541)
* feat: add default = true for highlight groups definition. 1. Add `default = true` for highlight groups, allow user to custom style. 2. Add descriptions for highlight groups in doc `rest-nvim.txt` * fix: move highlight documents to luaCAT comments --------- Co-authored-by: Seongmin Lee <[email protected]>
1 parent 7ca9204 commit 54ee52a

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

doc/rest-nvim.txt

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ rest.nvim *rest-nvim*
66

77

88
==============================================================================
9-
Table of Contents *rocks-contents*
9+
Table of Contents *rest-contents*
1010

1111
rest.nvim ·························································· |rest-nvim|
1212
rest.nvim user commands ··································· |rest-nvim.commands|
1313
rest.nvim user events ······································· |rest-nvim.events|
1414
rest.nvim configuration ····································· |rest-nvim.config|
15+
rest.nvim highlight groups ························ |rest-nvim.highlight-groups|
1516

1617
rest.setup({user_configs?}) *rest.setup*
1718
@deprecated use `vim.g.rest_nvim` instead
@@ -247,4 +248,16 @@ rest.Opts.Highlight *rest.Opts.Highlight*
247248
{timeout?} (number) Duration time of the request highlighting in milliseconds (Default: `750`)
248249

249250

251+
==============================================================================
252+
rest.nvim highlight groups *rest-nvim.highlight-groups*
253+
254+
255+
rest.nvim result UI implementation
256+
Highlight Group Default Description
257+
-------------------- -------------------------------- --------------------
258+
RestText Comment winbar text
259+
RestPaneTitleNC Statement winbar text in non-current pane
260+
RestPaneTitle Statement + bold + underline winbar Text in current pane
261+
262+
250263
vim:tw=78:ts=8:noet:ft=help:norl:

lua/rest-nvim/ui/highlights.lua

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---@mod rest-nvim.highlight-groups rest.nvim highlight groups
2+
---
3+
---@brief [[
4+
---
5+
--- rest.nvim result UI implementation
6+
--- Highlight Group Default Description
7+
--- -------------------- -------------------------------- --------------------
8+
--- RestText Comment winbar text
9+
--- RestPaneTitleNC Statement winbar text in non-current pane
10+
--- RestPaneTitle Statement + bold + underline winbar Text in current pane
11+
---
12+
---@brief ]]
13+
14+
---Get the foreground value of a highlighting group
15+
---@param name string Highlighting group name
16+
---@return string
17+
local function get_hl_group_fg(name)
18+
-- This will still error out if the highlight doesn't exist
19+
return string.format("#%06X", vim.api.nvim_get_hl(0, { name = name, link = false }).fg)
20+
end
21+
22+
vim.api.nvim_set_hl(0, "RestText", { fg = get_hl_group_fg("Comment"), default = true })
23+
vim.api.nvim_set_hl(0, "RestPaneTitleNC", { fg = get_hl_group_fg("Statement"), default = true })
24+
vim.api.nvim_set_hl(0, "RestPaneTitle", {
25+
fg = get_hl_group_fg("Statement"),
26+
bold = true,
27+
underline = true,
28+
default = true,
29+
})
30+
31+
---@comment HACK: to generate documnet with vimcats
32+
local M = {}
33+
return M

lua/rest-nvim/ui/result.lua

-16
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,6 @@ local group = paneui.create_pane_group("rest_nvim_result", panes, {
225225
end,
226226
})
227227

228-
---Get the foreground value of a highlighting group
229-
---@param name string Highlighting group name
230-
---@return string
231-
local function get_hl_group_fg(name)
232-
-- This will still error out if the highlight doesn't exist
233-
return string.format("#%06X", vim.api.nvim_get_hl(0, { name = name, link = false }).fg)
234-
end
235-
236-
vim.api.nvim_set_hl(0, "RestText", { fg = get_hl_group_fg("Comment") })
237-
vim.api.nvim_set_hl(0, "RestPaneTitleNC", { fg = get_hl_group_fg("Statement") })
238-
vim.api.nvim_set_hl(0, "RestPaneTitle", {
239-
fg = get_hl_group_fg("Statement"),
240-
bold = true,
241-
underline = true,
242-
})
243-
244228
---Check if UI window is shown in current tabpage
245229
---@return boolean
246230
function ui.is_open()

nix/test-overlay.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ in {
3535
];
3636
text = /* bash */ ''
3737
mkdir -p doc
38-
vimcats lua/rest-nvim/{init,commands,autocmds,config/init}.lua > doc/rest-nvim.txt
38+
vimcats lua/rest-nvim/{init,commands,autocmds,config/init,ui/highlights}.lua > doc/rest-nvim.txt
3939
vimcats lua/rest-nvim/{api,client/init,parser/init,script/init,cookie_jar,utils,logger}.lua > doc/rest-nvim-api.txt
4040
vimcats lua/rest-nvim/client/curl/{cli,utils}.lua > doc/rest-nvim-client-curl.txt
4141
'';

plugin/rest-nvim.lua

+3
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,7 @@ require("rest-nvim.autocmds").setup()
7474
require("rest-nvim.commands").setup()
7575
vim.treesitter.language.register("http", "rest_nvim_result")
7676

77+
-- setup highlight groups
78+
require("rest-nvim.ui.highlights")
79+
7780
vim.g.loaded_rest_nvim = true

0 commit comments

Comments
 (0)