From 6f5174ff60a153a5dbf6ddff13dee30b56df6c5e Mon Sep 17 00:00:00 2001 From: yorik1984 Date: Wed, 11 Jan 2023 01:17:54 +0200 Subject: [PATCH 1/6] 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. --- lua/lazygit/window.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lua/lazygit/window.lua b/lua/lazygit/window.lua index e02dde9..56655d3 100644 --- a/lua/lazygit/window.lua +++ b/lua/lazygit/window.lua @@ -1,6 +1,5 @@ local api = vim.api - --- open floating window with nice borders local function open_floating_window() 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 topleft, topright, botleft, botright - local corner_chars = vim.g.lazygit_floating_window_corner_chars - if type(corner_chars) == 'table' and #corner_chars == 4 then - topleft, topright, botleft, botright = unpack(corner_chars) + local topleft, top, topright, right, botright, bot, botleft, left + local window_chars = vim.g.lazygit_floating_window_chars + if type(window_chars) == 'table' and #window_chars == 8 then + topleft, top, topright, right, botright, bot, botleft, left = unpack(window_chars) else - topleft, topright, botleft, botright = '╭', '╮', '╰', '╯' + topleft, top, topright, right, botright, bot, botleft, left = '╭','─', '╮', '│', '╯','─', '╰', '│' end - local border_lines = { topleft .. string.rep('─', width) .. topright } - local middle_line = '│' .. string.rep(' ', width) .. '│' - for i = 1, height do + local border_lines = { topleft .. string.rep(top, width) .. topright } + local middle_line = left .. string.rep(' ', width) .. right + for _ = 1, height do table.insert(border_lines, middle_line) 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 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) -- create border window 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 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 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) -- use autocommand to ensure that the border_buffer closes at the same time as the main buffer From 9c4dc0b3c4b02baf0c9fc9fb6593c12ab2f2d29e Mon Sep 17 00:00:00 2001 From: yorik1984 Date: Wed, 11 Jan 2023 01:54:10 +0200 Subject: [PATCH 2/6] add install by lazy and info about highlighting --- README.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 405d05e..4a47657 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,38 @@ See [akinsho/nvim-toggleterm](https://github.com/akinsho/nvim-toggleterm.lua#cus Install using [`vim-plug`](https://github.com/junegunn/vim-plug): ```vim -" nvim v0.5.0 +" nvim v0.7.2 Plug 'kdheepak/lazygit.nvim' ``` +Install using [`packer.nvim`](https://github.com/wbthomason/packer.nvim): + +```lua +-- nvim v0.7.2 +use({ + "kdheepak/lazygit.nvim", + -- optional for floating window border decoration + requires = { + "nvim-lua/plenary.nvim", + }, +}) +``` + +Install using [`lazy.nvim`](https://github.com/folke/lazy.nvim): + +```lua +-- nvim v0.8.0 +require("lazy").setup({ + { + "kdheepak/lazygit.nvim", + -- optional for floating window border decoration + dependencies = { + "nvim-lua/plenary.nvim", + }, + }, +}) +``` + Feel free to use any plugin manager. Just remember that if you are not using the latest neovim release, you will need to use [the `nvim-v0.4.3` branch](https://github.com/kdheepak/lazygit.vim/tree/nvim-v0.4.3). Integration with `nvr` works better on the `main` branch. @@ -32,7 +60,7 @@ The following are configuration options and their defaults. ```vim let g:lazygit_floating_window_winblend = 0 " transparency of floating window let g:lazygit_floating_window_scaling_factor = 0.9 " scaling factor for floating window -let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯'] " customize lazygit popup window corner characters +let g:lazygit_floating_window_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] " customize lazygit popup window corner characters let g:lazygit_floating_window_use_plenary = 0 " use plenary.nvim to manage floating window if available let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed @@ -40,6 +68,17 @@ let g:lazygit_use_custom_config_file_path = 0 " config file path is evaluated if let g:lazygit_config_file_path = '' " custom config file path ``` +```lua +vim.g.lazygit_floating_window_winblend = 0 -- transparency of floating window +vim.g.lazygit_floating_window_scaling_factor = 0.9 -- scaling factor for floating window +vim.g.lazygit_floating_window_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] -- customize lazygit popup window corner characters +vim.g.lazygit_floating_window_use_plenary = 0 -- use plenary.nvim to manage floating window if available +vim.g.lazygit_use_neovim_remote = 1 -- fallback to 0 if neovim-remote is not installed + +vim.g.lazygit_use_custom_config_file_path = 0 -- config file path is evaluated if this value is 1 +vim.g.lazygit_config_file_path = '' -- custom config file path +``` + Call `:LazyGit` to start a floating window with `lazygit` in the current working directory. And set up a mapping to call `:LazyGit`: @@ -138,18 +177,40 @@ Instead, you can open it with telescope. **How to use** -Install the plugin using: +Install using [`packer.nvim`](https://github.com/wbthomason/packer.nvim): -``` +```lua +-- nvim v0.7.2 use({ - "nvim-telescope/telescope.nvim", - requires = { { "nvim-lua/plenary.nvim" }, { "kdheepak/lazygit.nvim" } }, + "kdheepak/lazygit.nvim", + requires = { + "nvim-telescope/telescope.nvim", + "nvim-lua/plenary.nvim", + }, config = function() require("telescope").load_extension("lazygit") end, }) ``` +Install using [`lazy.nvim`](https://github.com/folke/lazy.nvim): + +```lua +-- nvim v0.8.0 +require("lazy").setup({ + { + "kdheepak/lazygit.nvim", + dependencies = { + "nvim-telescope/telescope.nvim", + "nvim-lua/plenary.nvim" + }, + config = function() + require("telescope").load_extension("lazygit") + end, + }, +}) +``` + Lazy loading `lazygit.nvim` for telescope functionality is not supported. Open an issue if you wish to have this feature. If you are not using Packer, to load the telescope extension, you have to add this line to your configuration: @@ -172,3 +233,10 @@ Once you have loaded the extension, you can invoke the plugin using: ```lua lua require("telescope").extensions.lazygit.lazygit() ``` + +### Highlighting groups + +| Highlight Group | Default Group | Description | +| ------------------| --------------| -----------------------------------------| +| **LazyGitFloat** | **_Normal_** | Float terminal foreground and background | +| **LazyGitBorder** | **_Normal_** | Float terminal border | From 096bef1ec65394af9c32c1eea73b1887154499e7 Mon Sep 17 00:00:00 2001 From: yorik1984 Date: Wed, 11 Jan 2023 02:04:50 +0200 Subject: [PATCH 3/6] change border chars --- plugin/lazygit.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 5e5c154..6bdabf1 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -19,8 +19,8 @@ if !exists('g:lazygit_use_neovim_remote') let g:lazygit_use_neovim_remote = executable('nvr') ? 1 : 0 endif -if !exists('g:lazygit_floating_window_corner_chars') - let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯'] +if !exists('g:lazygit_floating_window_chars') + let g:lazygit_floating_window_corner_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] endif " if lazygit_use_custom_config_file_path is set to 1 the From 41c617f2dae8888d826160dae77f532b8eb84d25 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 20 May 2023 17:26:27 -0400 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20Add=20deprecation=20message=20for?= =?UTF-8?q?=20old=20option=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/lazygit.vim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 6bdabf1..6dce40d 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -19,8 +19,17 @@ if !exists('g:lazygit_use_neovim_remote') let g:lazygit_use_neovim_remote = executable('nvr') ? 1 : 0 endif +if exists('g:lazygit_floating_window_corner_chars') + echohl WarningMsg + echomsg "`g:lazygit_floating_window_corner_chars` is deprecated. Please use `g:lazygit_floating_window_chars` instead." + echohl None + if !exists('g:lazygit_floating_window_chars') + let g:lazygit_floating_window_chars = g:lazygit_floating_window_corner_chars + endif +endif + if !exists('g:lazygit_floating_window_chars') - let g:lazygit_floating_window_corner_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] + let g:lazygit_floating_window_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] endif " if lazygit_use_custom_config_file_path is set to 1 the From e90f0ee657021c29c91f560c92d6aaef4da5fa21 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 20 May 2023 17:30:30 -0400 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20Change=20option=20to=20lazygit=5Ffl?= =?UTF-8?q?oating=5Fwindow=5Fborder=5Fchars=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- lua/lazygit/window.lua | 2 +- plugin/lazygit.vim | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4a47657..4b73962 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ The following are configuration options and their defaults. ```vim let g:lazygit_floating_window_winblend = 0 " transparency of floating window let g:lazygit_floating_window_scaling_factor = 0.9 " scaling factor for floating window -let g:lazygit_floating_window_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] " customize lazygit popup window corner characters +let g:lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] " customize lazygit popup window corner characters let g:lazygit_floating_window_use_plenary = 0 " use plenary.nvim to manage floating window if available let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed @@ -71,7 +71,7 @@ let g:lazygit_config_file_path = '' " custom config file path ```lua vim.g.lazygit_floating_window_winblend = 0 -- transparency of floating window vim.g.lazygit_floating_window_scaling_factor = 0.9 -- scaling factor for floating window -vim.g.lazygit_floating_window_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] -- customize lazygit popup window corner characters +vim.g.lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] -- customize lazygit popup window corner characters vim.g.lazygit_floating_window_use_plenary = 0 -- use plenary.nvim to manage floating window if available vim.g.lazygit_use_neovim_remote = 1 -- fallback to 0 if neovim-remote is not installed diff --git a/lua/lazygit/window.lua b/lua/lazygit/window.lua index 56655d3..ff33200 100644 --- a/lua/lazygit/window.lua +++ b/lua/lazygit/window.lua @@ -34,7 +34,7 @@ local function open_floating_window() local opts = { style = 'minimal', relative = 'editor', row = row, col = col, width = width, height = height } local topleft, top, topright, right, botright, bot, botleft, left - local window_chars = vim.g.lazygit_floating_window_chars + local window_chars = vim.g.lazygit_floating_window_border_chars if type(window_chars) == 'table' and #window_chars == 8 then topleft, top, topright, right, botright, bot, botleft, left = unpack(window_chars) else diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 6dce40d..44c93be 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -21,15 +21,15 @@ endif if exists('g:lazygit_floating_window_corner_chars') echohl WarningMsg - echomsg "`g:lazygit_floating_window_corner_chars` is deprecated. Please use `g:lazygit_floating_window_chars` instead." + echomsg "`g:lazygit_floating_window_corner_chars` is deprecated. Please use `g:lazygit_floating_window_border_chars` instead." echohl None - if !exists('g:lazygit_floating_window_chars') - let g:lazygit_floating_window_chars = g:lazygit_floating_window_corner_chars + if !exists('g:lazygit_floating_window_border_chars') + let g:lazygit_floating_window_border_chars = g:lazygit_floating_window_corner_chars endif endif -if !exists('g:lazygit_floating_window_chars') - let g:lazygit_floating_window_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] +if !exists('g:lazygit_floating_window_border_chars') + let g:lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] endif " if lazygit_use_custom_config_file_path is set to 1 the From e1f4ee5697630aa9df42d1afeb7905c727128c77 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Sat, 20 May 2023 17:31:43 -0400 Subject: [PATCH 6/6] =?UTF-8?q?docs:=20Update=20README.md=20=F0=9F=93=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b73962..3033059 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ The following are configuration options and their defaults. ```vim let g:lazygit_floating_window_winblend = 0 " transparency of floating window let g:lazygit_floating_window_scaling_factor = 0.9 " scaling factor for floating window -let g:lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] " customize lazygit popup window corner characters +let g:lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] " customize lazygit popup window border characters let g:lazygit_floating_window_use_plenary = 0 " use plenary.nvim to manage floating window if available let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed @@ -71,7 +71,7 @@ let g:lazygit_config_file_path = '' " custom config file path ```lua vim.g.lazygit_floating_window_winblend = 0 -- transparency of floating window vim.g.lazygit_floating_window_scaling_factor = 0.9 -- scaling factor for floating window -vim.g.lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] -- customize lazygit popup window corner characters +vim.g.lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] -- customize lazygit popup window border characters vim.g.lazygit_floating_window_use_plenary = 0 -- use plenary.nvim to manage floating window if available vim.g.lazygit_use_neovim_remote = 1 -- fallback to 0 if neovim-remote is not installed