diff --git a/README.md b/README.md index 515eecf..8342765 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_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 @@ -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_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 + +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`: @@ -156,18 +195,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: @@ -190,3 +251,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 | diff --git a/lua/lazygit/window.lua b/lua/lazygit/window.lua index e02dde9..ff33200 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_border_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 diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 5e5c154..44c93be 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') - let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯'] +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_border_chars` instead." + echohl None + 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_border_chars') + let g:lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] endif " if lazygit_use_custom_config_file_path is set to 1 the