Skip to content

Commit

Permalink
feat(title): add title configuration for window (#4)
Browse files Browse the repository at this point in the history
* feat(title): add title configuration for window

The title can now be configured in the `setup` or when toggling the
window.

* fix: toggle_gitpad called without opts
  • Loading branch information
sudo-tee authored May 14, 2024
1 parent 0b66fe1 commit 02c2d77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ using [lazy.nvim](https://github.com/folke/lazy.nvim):
{
'<leader>pp',
function()
require('gitpad').toggle_gitpad()
require('gitpad').toggle_gitpad() -- or require('gitpad').toggle_gitpad({ title = 'Project notes' })
end,
desc = 'gitpad project',
},
{
'<leader>pb',
function()
require('gitpad').toggle_gitpad_branch()
require('gitpad').toggle_gitpad_branch() -- or require('gitpad').toggle_gitpad_branch({ title = 'Branch notes' })
end,
desc = 'gitpad branch',
},
Expand All @@ -53,7 +53,7 @@ using [lazy.nvim](https://github.com/folke/lazy.nvim):
'<leader>pd',
function()
local date_filename = 'daily-' .. os.date('%Y-%m-%d.md')
require('gitpad').toggle_gitpad({ filename = date_filename })
require('gitpad').toggle_gitpad({ filename = date_filename }) -- or require('gitpad').toggle_gitpad({ filename = date_filename, title = 'Daily notes' })
end,
desc = 'gitpad daily notes',
},
Expand All @@ -67,7 +67,7 @@ using [lazy.nvim](https://github.com/folke/lazy.nvim):
return
end
filename = vim.fn.pathshorten(filename, 2) .. '.md'
require('gitpad').toggle_gitpad({ filename = filename })
require('gitpad').toggle_gitpad({ filename = filename }) -- or require('gitpad').toggle_gitpad({ filename = filename, title = 'Current file notes' })
end,
desc = 'gitpad per file notes',
},
Expand All @@ -84,6 +84,7 @@ gitpad.nvim comes with the following defaults:

```lua
{
title = 'gitpad', -- The title of the floating window
border = 'single', -- The border style of the floating window. Possible values are `'single'`, `'double'`, `'shadow'`, `'rounded'`, and `''` (no border).
style = '', -- The style of the floating window. Possible values are `'minimal'` (no line numbers, statusline, or sign column. See :help nvim_open_win() '), and `''` (default Neovim style).
dir = vim.fn.stdpath('data') .. '/gitpad', -- The directory where the notes are stored. Possible value is a valid path ie '~/notes'
Expand Down
13 changes: 8 additions & 5 deletions lua/gitpad/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local uv = vim.uv or vim.loop
local gitpad_win_id = nil

M.config = {
title = 'gitpad',
border = 'single',
dir = vim.fs.normalize(vim.fn.stdpath('data') .. '/gitpad'),
style = '',
Expand Down Expand Up @@ -125,7 +126,7 @@ end

function M.open_window(opts)
local path = opts.path
local title = ' gitpad '
local title = opts.title or M.config.title

local ui = vim.api.nvim_list_uis()[1]
local width = math.floor((ui.width * 0.5) + 0.5)
Expand All @@ -142,7 +143,7 @@ function M.open_window(opts)
}

if vim.fn.has('nvim-0.9.0') == 1 then
win_opts.title = title
win_opts.title = ' ' .. title .. ' '
win_opts.title_pos = 'left'
end

Expand Down Expand Up @@ -191,11 +192,13 @@ end
function M.toggle_gitpad(opts)
opts = opts or {}
local path = M.init_gitpad_file(opts)
M.toggle_window { path = path }

M.toggle_window(vim.tbl_deep_extend('force', opts, { path = path }))
end

function M.toggle_gitpad_branch()
M.toggle_gitpad { filename = H.get_branch_filename() }
function M.toggle_gitpad_branch(opts)
opts = vim.tbl_deep_extend('force', opts or {}, { filename = H.get_branch_filename() })
M.toggle_gitpad(opts)
end

M.setup = function(opts)
Expand Down

0 comments on commit 02c2d77

Please sign in to comment.