Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mini.icons support #186

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,785 changes: 1,000 additions & 785 deletions README.md

Large diffs are not rendered by default.

653 changes: 328 additions & 325 deletions doc/dropbar.txt

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions lua/dropbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ local function setup(opts)
for _, win in ipairs(vim.api.nvim_list_wins()) do
utils.bar.attach(vim.api.nvim_win_get_buf(win), win)
end
if not vim.tbl_isempty(configs.opts.general.attach_events) then
vim.api.nvim_create_autocmd(configs.opts.general.attach_events, {
if not vim.tbl_isempty(configs.opts.bar.attach_events) then
vim.api.nvim_create_autocmd(configs.opts.bar.attach_events, {
group = groupid,
callback = function(info)
-- Try attaching dropbar to all windows containing the buffer
Expand All @@ -80,8 +80,8 @@ local function setup(opts)
end,
desc = 'Remove dropbar from cache on buffer delete/unload/wipeout.',
})
if not vim.tbl_isempty(configs.opts.general.update_events.win) then
vim.api.nvim_create_autocmd(configs.opts.general.update_events.win, {
if not vim.tbl_isempty(configs.opts.bar.update_events.win) then
vim.api.nvim_create_autocmd(configs.opts.bar.update_events.win, {
group = groupid,
callback = function(info)
if info.event == 'WinResized' then
Expand All @@ -98,17 +98,17 @@ local function setup(opts)
desc = 'Update a single winbar.',
})
end
if not vim.tbl_isempty(configs.opts.general.update_events.buf) then
vim.api.nvim_create_autocmd(configs.opts.general.update_events.buf, {
if not vim.tbl_isempty(configs.opts.bar.update_events.buf) then
vim.api.nvim_create_autocmd(configs.opts.bar.update_events.buf, {
group = groupid,
callback = function(info)
utils.bar.exec('update', { buf = info.buf })
end,
desc = 'Update all winbars associated with buf.',
})
end
if not vim.tbl_isempty(configs.opts.general.update_events.global) then
vim.api.nvim_create_autocmd(configs.opts.general.update_events.global, {
if not vim.tbl_isempty(configs.opts.bar.update_events.global) then
vim.api.nvim_create_autocmd(configs.opts.bar.update_events.global, {
group = groupid,
callback = function(info)
if vim.tbl_isempty(utils.bar.get({ buf = info.buf })) then
Expand Down
2 changes: 1 addition & 1 deletion lua/dropbar/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function M.goto_context_start(count)
end
current_sym = prev_sym
end
current_sym:jump()
current_sym:jump(false)
end

---Open the menu of current context to select the next context
Expand Down
40 changes: 12 additions & 28 deletions lua/dropbar/bar.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
local configs = require('dropbar.configs')
local utils = require('dropbar.utils')

---Add highlight to a string
---@param str string
---@param hlgroup string?
---@return string
local function hl(str, hlgroup)
if not hlgroup then
return str
end
return string.format('%%#%s#%s%%*', hlgroup, str or '')
end

---Make a dropbar string clickable
---@param str string
---@param callback string
---@return string
local function make_clickable(str, callback)
return string.format('%%@%s@%s%%X', callback, str)
end

---@alias dropbar_symbol_range_t lsp_range_t

---@class dropbar_symbol_t
Expand Down Expand Up @@ -242,10 +223,10 @@ function dropbar_symbol_t:cat(plain)
-- Escape `%` characters to prevent unintended statusline evaluation
local icon_escaped = self.icon:gsub('%%', '%%%%')
local name_escaped = self.name:gsub('%%', '%%%%')
local icon_highlighted = hl(icon_escaped, self.icon_hl)
local name_highlighted = hl(name_escaped, self.name_hl)
local icon_highlighted = utils.bar.hl(icon_escaped, self.icon_hl)
local name_highlighted = utils.bar.hl(name_escaped, self.name_hl)
if self.on_click and self.bar_idx then
self.cache.decorated_str = make_clickable(
self.cache.decorated_str = utils.bar.make_clickable(
icon_highlighted .. name_highlighted,
string.format(
'v:lua.dropbar.callbacks.buf%s.win%s.fn%s',
Expand Down Expand Up @@ -281,8 +262,9 @@ function dropbar_symbol_t:bytewidth()
end

---Jump to the start of the symbol associated with the winbar symbol
---@param reorient boolean? whether to set view after jumping, default true
---@return nil
function dropbar_symbol_t:jump()
function dropbar_symbol_t:jump(reorient)
if not self.range or not self.win then
return
end
Expand All @@ -291,9 +273,11 @@ function dropbar_symbol_t:jump()
self.range.start.line + 1,
self.range.start.character,
})
vim.api.nvim_win_call(self.win, function()
configs.opts.symbol.jump.reorient(self.win, self.range)
end)
if reorient ~= false then
vim.api.nvim_win_call(self.win, function()
configs.opts.symbol.jump.reorient(self.win, self.range)
end)
end
end

---Preview the symbol in the source window
Expand Down Expand Up @@ -511,7 +495,7 @@ function dropbar_t:cat(plain)
result = result and padding_left .. result .. padding_right or ''
-- Must add highlights to padding when `plain` is false, else nvim will
-- automatically truncate it
return plain and result or hl(result, '')
return plain and result or utils.bar.hl(result, '')
end

---Reevaluate dropbar string from components and redraw dropbar
Expand Down Expand Up @@ -590,7 +574,7 @@ function dropbar_t:update()
end
end
self:redraw()
end, configs.opts.general.update_interval)
end, configs.opts.bar.update_debounce)
end

---Execute a function in pick mode
Expand Down
Loading