Add LazyGit highlighting groups and new border
Add `LazyGitBorder` and `LazyGitFloat` highlighting groups using nvim(>=0.7.2) function `vim.api.nvim_set_hl`. Add full list of window border for useful customize.
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
|
|
||||||
--- open floating window with nice borders
|
--- open floating window with nice borders
|
||||||
local function open_floating_window()
|
local function open_floating_window()
|
||||||
local floating_window_scaling_factor = vim.g.lazygit_floating_window_scaling_factor
|
local floating_window_scaling_factor = vim.g.lazygit_floating_window_scaling_factor
|
||||||
@@ -34,20 +33,20 @@ local function open_floating_window()
|
|||||||
|
|
||||||
local opts = { style = 'minimal', relative = 'editor', row = row, col = col, width = width, height = height }
|
local opts = { style = 'minimal', relative = 'editor', row = row, col = col, width = width, height = height }
|
||||||
|
|
||||||
local topleft, topright, botleft, botright
|
local topleft, top, topright, right, botright, bot, botleft, left
|
||||||
local corner_chars = vim.g.lazygit_floating_window_corner_chars
|
local window_chars = vim.g.lazygit_floating_window_chars
|
||||||
if type(corner_chars) == 'table' and #corner_chars == 4 then
|
if type(window_chars) == 'table' and #window_chars == 8 then
|
||||||
topleft, topright, botleft, botright = unpack(corner_chars)
|
topleft, top, topright, right, botright, bot, botleft, left = unpack(window_chars)
|
||||||
else
|
else
|
||||||
topleft, topright, botleft, botright = '╭', '╮', '╰', '╯'
|
topleft, top, topright, right, botright, bot, botleft, left = '╭','─', '╮', '│', '╯','─', '╰', '│'
|
||||||
end
|
end
|
||||||
|
|
||||||
local border_lines = { topleft .. string.rep('─', width) .. topright }
|
local border_lines = { topleft .. string.rep(top, width) .. topright }
|
||||||
local middle_line = '│' .. string.rep(' ', width) .. '│'
|
local middle_line = left .. string.rep(' ', width) .. right
|
||||||
for i = 1, height do
|
for _ = 1, height do
|
||||||
table.insert(border_lines, middle_line)
|
table.insert(border_lines, middle_line)
|
||||||
end
|
end
|
||||||
table.insert(border_lines, botleft .. string.rep('─', width) .. botright)
|
table.insert(border_lines, botleft .. string.rep(bot, width) .. botright)
|
||||||
|
|
||||||
-- create a unlisted scratch buffer for the border
|
-- create a unlisted scratch buffer for the border
|
||||||
local border_buffer = api.nvim_create_buf(false, true)
|
local border_buffer = api.nvim_create_buf(false, true)
|
||||||
@@ -56,7 +55,8 @@ local function open_floating_window()
|
|||||||
api.nvim_buf_set_lines(border_buffer, 0, -1, true, border_lines)
|
api.nvim_buf_set_lines(border_buffer, 0, -1, true, border_lines)
|
||||||
-- create border window
|
-- create border window
|
||||||
local border_window = api.nvim_open_win(border_buffer, true, border_opts)
|
local border_window = api.nvim_open_win(border_buffer, true, border_opts)
|
||||||
vim.cmd('set winhl=NormalFloat:Normal')
|
vim.api.nvim_set_hl(0, "LazyGitBorder", { link = "Normal", default = true })
|
||||||
|
vim.cmd('set winhl=NormalFloat:LazyGitBorder')
|
||||||
|
|
||||||
-- create a unlisted scratch buffer
|
-- create a unlisted scratch buffer
|
||||||
if LAZYGIT_BUFFER == nil or vim.fn.bufwinnr(LAZYGIT_BUFFER) == -1 then
|
if LAZYGIT_BUFFER == nil or vim.fn.bufwinnr(LAZYGIT_BUFFER) == -1 then
|
||||||
@@ -71,6 +71,8 @@ local function open_floating_window()
|
|||||||
|
|
||||||
vim.cmd('setlocal bufhidden=hide')
|
vim.cmd('setlocal bufhidden=hide')
|
||||||
vim.cmd('setlocal nocursorcolumn')
|
vim.cmd('setlocal nocursorcolumn')
|
||||||
|
vim.api.nvim_set_hl(0, "LazyGitFloat", { link = "Normal", default = true })
|
||||||
|
vim.cmd('setlocal winhl=NormalFloat:LazyGitFloat')
|
||||||
vim.cmd('set winblend=' .. vim.g.lazygit_floating_window_winblend)
|
vim.cmd('set winblend=' .. vim.g.lazygit_floating_window_winblend)
|
||||||
|
|
||||||
-- use autocommand to ensure that the border_buffer closes at the same time as the main buffer
|
-- use autocommand to ensure that the border_buffer closes at the same time as the main buffer
|
||||||
|
|||||||
Reference in New Issue
Block a user