Skip to content

Commit

Permalink
feat: add editor command DashboardUpdateFooter (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-schemoul authored Apr 3, 2024
1 parent 39f308a commit 04369ff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ dashboard will use default highlight group like `DashboardKey/Icon/Desc` instead

- `Dashboard` open dashboard
- `DbProjectDelete count` delete project in cache works for hyper theme. count is number
- `DashboardUpdateFooter` updates the content of the Footer

### Highlight

Expand Down
2 changes: 2 additions & 0 deletions lua/dashboard/theme/doom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ local function generate_footer(config)
for i = 1, #footer do
api.nvim_buf_add_highlight(config.bufnr, 0, 'DashboardFooter', first_line + i - 1, 0, -1)
end

utils.add_update_footer_command(config.bufnr, footer)
end

---@private
Expand Down
2 changes: 2 additions & 0 deletions lua/dashboard/theme/hyper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ local function gen_footer(config)
for i, _ in pairs(footer) do
api.nvim_buf_add_highlight(config.bufnr, 0, 'DashboardFooter', first_line + i - 1, 0, -1)
end

utils.add_update_footer_command(config.bufnr, footer)
end

local function project_delete()
Expand Down
21 changes: 21 additions & 0 deletions lua/dashboard/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,25 @@ function utils.buf_is_empty(bufnr)
and vim.api.nvim_buf_get_lines(0, 0, -1, false)[1] == ''
end

local last_footer_size = nil
function utils.add_update_footer_command(bufnr, footer)
vim.api.nvim_create_user_command('DashboardUpdateFooter', function(args)
if last_footer_size == nil then
last_footer_size = #footer
end

local first_line = vim.api.nvim_buf_line_count(bufnr)
vim.api.nvim_buf_set_lines(
bufnr,
first_line - last_footer_size,
-1,
false,
utils.center_align(args.fargs)
)
vim.bo[bufnr].modified = false

last_footer_size = #args.fargs -- For future calculation of size
end, { nargs = '*' })
end

return utils

0 comments on commit 04369ff

Please sign in to comment.