Skip to content

Commit

Permalink
feat: pinned buffers only show file icon by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Iron-E committed Apr 1, 2023
1 parent f39a606 commit 66982f4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
9 changes: 7 additions & 2 deletions doc/barbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ icons ~
bufferline.
- `icon`, which controls what icon accompanies the number of diagnostics.

*barbar-setup.icons.filename*
icons.filename ~
`boolean` (default: `true`)
If `true`, show the name of the file.

*barbar-setup.icons.filetype.custom_colors*
icons.filetype.custom_colors ~
`boolean` (default: `false`)
Expand Down Expand Up @@ -287,15 +292,15 @@ icons ~

*barbar-setup.icons.pinned*
icons.pinned ~
`table` (default: `{button = ''}`)
`table` (default: `{button = false, filename = false}`)
The icons which should be used for a pinned buffer.
Supports all the base options (e.g. `buffer_index`, `filetype.enabled`,
etc)

Example: >
require'barbar'.setup {icons = {
modified = {separator = '⋄'},
pinned = {button = '車'},
pinned = {button = '車', filename = true},
}}
<

Expand Down
4 changes: 2 additions & 2 deletions lua/barbar/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ local buffer = {

--- For each severity in `diagnostics`: if it is enabled, and there are diagnostics associated with it in the `buffer_number` provided, call `f`.
--- @param buffer_number integer the buffer number to count diagnostics in
--- @param diagnostics barbar.config.options.icons.diagnostics the user configuration for diagnostics
--- @param f fun(count: integer, severity_idx: integer, severity_option: barbar.config.options.icons.diagnostics.severity) the function to run when diagnostics of a specific severity are enabled and present in the `buffer_number`
--- @param diagnostics barbar.config.options.icons.buffer.diagnostics the user configuration for diagnostics
--- @param f fun(count: integer, severity_idx: integer, option: barbar.config.options.icons.diagnostics.severity) the function to run when diagnostics of a specific severity are enabled and present in the `buffer_number`
--- @return nil
for_each_counted_enabled_diagnostic = function(buffer_number, diagnostics, f)
local count
Expand Down
17 changes: 9 additions & 8 deletions lua/barbar/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ local DEPRECATE_PREFIX = '\nThe barbar.nvim option '
--- @class barbar.config.options.hide
--- @field alternate? boolean
--- @field current? boolean
--- @field extensions? boolean
--- @field inactive? boolean
--- @field visible? boolean

--- @class barbar.config.options.icons.diagnostics.severity
--- @field enabled boolean
--- @field icon string

--- @class barbar.config.options.icons.diagnostics
--- @class barbar.config.options.icons.buffer.diagnostics
--- @field [1] barbar.config.options.icons.diagnostics.severity
--- @field [2] barbar.config.options.icons.diagnostics.severity
--- @field [3] barbar.config.options.icons.diagnostics.severity
Expand All @@ -30,21 +29,22 @@ local DEFAULT_DIAGNOSTIC_ICONS = {
[vim.diagnostic.severity.WARN] = {enabled = false, icon = '⚠️ '},
}

--- @class barbar.config.options.icons.filetype
--- @class barbar.config.options.icons.buffer.filetype
--- @field custom_color? boolean if present, this color will be used for ALL filetype icons
--- @field enabled? boolean iff `true`, show the `devicons` for the associated buffer's `filetype`.

--- @class barbar.config.options.icons.separator
--- @class barbar.config.options.icons.buffer.separator
--- @field left? string a buffer's left separator
--- @field right? string a buffer's right separator

--- @class barbar.config.options.icons.buffer
--- @field buffer_index? boolean iff `true`, show the index of the associated buffer with respect to the ordering of the buffers in the tabline.
--- @field buffer_number? boolean iff `true`, show the `bufnr` for the associated buffer.
--- @field filename? boolean iff `true`, show the filename
--- @field button? false|string the button which is clicked to close / save a buffer, or indicate that it is pinned.
--- @field diagnostics? barbar.config.options.icons.diagnostics the diagnostic icons
--- @field filetype? barbar.config.options.icons.filetype filetype icon options
--- @field separator? barbar.config.options.icons.separator the left-hand separator between buffers in the tabline
--- @field diagnostics? barbar.config.options.icons.buffer.diagnostics the diagnostic icons
--- @field filetype? barbar.config.options.icons.buffer.filetype filetype icon options
--- @field separator? barbar.config.options.icons.buffer.separator the left-hand separator between buffers in the tabline

--- @class barbar.config.options.icons.state: barbar.config.options.icons.buffer
--- @field modified? barbar.config.options.icons.buffer the icons used for an modified buffer
Expand Down Expand Up @@ -201,10 +201,11 @@ function config.setup(user_config)
buffer_number = false,
button = '',
diagnostics = {},
filename = true,
filetype = {enabled = true},
inactive = {separator = {left = '', right = ''}},
modified = {button = ''},
pinned = {button = ''},
pinned = {button = false, filename = false},
separator = {left = '', right = ''},
},
insert_at_end = false,
Expand Down
16 changes: 12 additions & 4 deletions lua/barbar/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ function Layout.calculate_buffer_width(bufnr, index)
else
local icons_option = state.icons(bufnr, buffer_activity)

width = strwidth(icons_option.separator.left) + strwidth(buffer_name) -- separator + name
width = strwidth(icons_option.separator.left)

if icons_option.filename then
width = width + strwidth(buffer_name)
end

if icons_option.buffer_index then
width = width + #tostring(index) + SPACE_LEN
Expand All @@ -88,16 +92,20 @@ function Layout.calculate_buffer_width(bufnr, index)
end

if icons_option.filetype.enabled then
--- @diagnostic disable-next-line:param-type-mismatch
local file_icon = icons.get_icon(bufnr, '')
local file_icon = icons.get_icon(bufnr, buffer_activity)
width = width + strwidth(file_icon) + SPACE_LEN
end

Buffer.for_each_counted_enabled_diagnostic(bufnr, icons_option.diagnostics, function(count, _, option)
width = width + SPACE_LEN + strwidth(option.icon) + #tostring(count)
end)

width = width + strwidth(icons_option.button or '') + SPACE_LEN + strwidth(icons_option.separator.right)
local button = icons_option.button
if button then
width = width + strwidth(button) + SPACE_LEN
end

width = width + strwidth(icons_option.separator.right)
end

return width or 0
Expand Down
15 changes: 9 additions & 6 deletions lua/barbar/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ local function generate_tabline(bufnrs, refocus)

--- The name of the buffer
--- @type barbar.render.group.item
local name = {hl = clickable .. buffer_hl, text = buffer_name}
local name = {hl = clickable .. buffer_hl, text = icons_option.filename and buffer_name or ''}

--- The buffer index
--- @type barbar.render.group.item
Expand All @@ -564,13 +564,16 @@ local function generate_tabline(bufnrs, refocus)
buffer_number.text = bufnr .. ' '
end

local button = icons_option.button or ''

--- The close icon
--- @type barbar.render.group.item
local close = {hl = buffer_hl, text = button .. ' '}
if click_enabled and #button > 0 then
close.hl = '%' .. bufnr .. '@barbar#events#close_click_handler@' .. close.hl
local close = {hl = buffer_hl, text = ''}

if icons_option.button then
close.text = icons_option.button .. ' '

if click_enabled then
close.hl = '%' .. bufnr .. '@barbar#events#close_click_handler@' .. close.hl
end
end

--- The jump letter
Expand Down

0 comments on commit 66982f4

Please sign in to comment.