Skip to content

Commit

Permalink
feat: add default = true for highlight groups definition. (#541)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
xieyonn and boltlessengineer authored Mar 8, 2025
1 parent 7ca9204 commit 54ee52a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
15 changes: 14 additions & 1 deletion doc/rest-nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ rest.nvim *rest-nvim*


==============================================================================
Table of Contents *rocks-contents*
Table of Contents *rest-contents*

rest.nvim ·························································· |rest-nvim|
rest.nvim user commands ··································· |rest-nvim.commands|
rest.nvim user events ······································· |rest-nvim.events|
rest.nvim configuration ····································· |rest-nvim.config|
rest.nvim highlight groups ························ |rest-nvim.highlight-groups|

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


==============================================================================
rest.nvim highlight groups *rest-nvim.highlight-groups*


rest.nvim result UI implementation
Highlight Group Default Description
-------------------- -------------------------------- --------------------
RestText Comment winbar text
RestPaneTitleNC Statement winbar text in non-current pane
RestPaneTitle Statement + bold + underline winbar Text in current pane


vim:tw=78:ts=8:noet:ft=help:norl:
33 changes: 33 additions & 0 deletions lua/rest-nvim/ui/highlights.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---@mod rest-nvim.highlight-groups rest.nvim highlight groups
---
---@brief [[
---
--- rest.nvim result UI implementation
--- Highlight Group Default Description
--- -------------------- -------------------------------- --------------------
--- RestText Comment winbar text
--- RestPaneTitleNC Statement winbar text in non-current pane
--- RestPaneTitle Statement + bold + underline winbar Text in current pane
---
---@brief ]]

---Get the foreground value of a highlighting group
---@param name string Highlighting group name
---@return string
local function get_hl_group_fg(name)
-- This will still error out if the highlight doesn't exist
return string.format("#%06X", vim.api.nvim_get_hl(0, { name = name, link = false }).fg)
end

vim.api.nvim_set_hl(0, "RestText", { fg = get_hl_group_fg("Comment"), default = true })
vim.api.nvim_set_hl(0, "RestPaneTitleNC", { fg = get_hl_group_fg("Statement"), default = true })
vim.api.nvim_set_hl(0, "RestPaneTitle", {
fg = get_hl_group_fg("Statement"),
bold = true,
underline = true,
default = true,
})

---@comment HACK: to generate documnet with vimcats
local M = {}
return M
16 changes: 0 additions & 16 deletions lua/rest-nvim/ui/result.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,6 @@ local group = paneui.create_pane_group("rest_nvim_result", panes, {
end,
})

---Get the foreground value of a highlighting group
---@param name string Highlighting group name
---@return string
local function get_hl_group_fg(name)
-- This will still error out if the highlight doesn't exist
return string.format("#%06X", vim.api.nvim_get_hl(0, { name = name, link = false }).fg)
end

vim.api.nvim_set_hl(0, "RestText", { fg = get_hl_group_fg("Comment") })
vim.api.nvim_set_hl(0, "RestPaneTitleNC", { fg = get_hl_group_fg("Statement") })
vim.api.nvim_set_hl(0, "RestPaneTitle", {
fg = get_hl_group_fg("Statement"),
bold = true,
underline = true,
})

---Check if UI window is shown in current tabpage
---@return boolean
function ui.is_open()
Expand Down
2 changes: 1 addition & 1 deletion nix/test-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ in {
];
text = /* bash */ ''
mkdir -p doc
vimcats lua/rest-nvim/{init,commands,autocmds,config/init}.lua > doc/rest-nvim.txt
vimcats lua/rest-nvim/{init,commands,autocmds,config/init,ui/highlights}.lua > doc/rest-nvim.txt
vimcats lua/rest-nvim/{api,client/init,parser/init,script/init,cookie_jar,utils,logger}.lua > doc/rest-nvim-api.txt
vimcats lua/rest-nvim/client/curl/{cli,utils}.lua > doc/rest-nvim-client-curl.txt
'';
Expand Down
3 changes: 3 additions & 0 deletions plugin/rest-nvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ require("rest-nvim.autocmds").setup()
require("rest-nvim.commands").setup()
vim.treesitter.language.register("http", "rest_nvim_result")

-- setup highlight groups
require("rest-nvim.ui.highlights")

vim.g.loaded_rest_nvim = true

0 comments on commit 54ee52a

Please sign in to comment.