Skip to content

Commit 961df85

Browse files
committed
feat(status): add bufnr provider and add to fileinfo component
1 parent c2422be commit 961df85

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lua/astroui/status/component.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function M.file_info(opts)
3434
opts = extend_tbl(vim.tbl_get(config, "components", "file_info"), opts)
3535
return M.builder(status_utils.setup_providers(opts, {
3636
"file_icon",
37+
"bufnr",
3738
"unique_path",
3839
"filename",
3940
"filetype",

lua/astroui/status/config.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171

7272
---@class AstroUIProviderFiletypeOpts: AstroUIStatusStylizeOpts
7373

74+
---@class AstroUIProviderBufnrOpts: AstroUIStatusStylizeOpts
75+
---@field suffix string? string to append after the buffer number
76+
7477
---@class AstroUIProviderFilenameOpts: AstroUIStatusStylizeOpts
7578
---@field fname (fun(bufnr: integer): string)? function for calculating the buffer name
7679
---@field modify string? modifiers to pass to `fnamemodify` on final path
@@ -133,6 +136,7 @@
133136
---@field scrollbar AstroUIProviderScrollbarOpts? default options for the `scrollbar` provider
134137
---@field close_button AstroUIProviderCloseButtonOpts? default options for the `close_button` provider
135138
---@field filetype AstroUIProviderFiletypeOpts? default options for the `filetype` provider
139+
---@field bufnr AstroUIProviderBufnrOpts? default options for the `bufnr` provider
136140
---@field filename AstroUIProviderFilenameOpts? default options for the `filename` provider
137141
---@field file_encoding AstroUIProviderFileEncodingOpts? default options for the `file_encoding` provider
138142
---@field file_format AstroUIProviderFileFormatOpts? default options for the `file_format` provider
@@ -379,6 +383,7 @@ return {
379383
hl = function(self) return require("astroui.status.hl").file_icon "statusline"(self) end,
380384
padding = { left = 1, right = 1 },
381385
},
386+
bufnr = false,
382387
filename = false,
383388
filetype = {},
384389
file_modified = {
@@ -715,6 +720,7 @@ return {
715720
ruler = { pad_ruler = { line = 3, char = 2 } },
716721
scrollbar = { chars = { "", "", "", "", "", "", "", "" } },
717722
close_button = { kind = "BufferClose" },
723+
bufnr = { suffix = "." },
718724
filename = {
719725
fallback = "Untitled",
720726
fname = function(bufnr) return vim.api.nvim_buf_get_name(bufnr) end,

lua/astroui/status/provider.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ function M.filetype(opts)
301301
return function(self) return status_utils.stylize(vim.bo[self and self.bufnr or 0].filetype, opts) end
302302
end
303303

304+
--- A provider function for showing the buffer number
305+
---@param opts? AstroUIProviderBufnrOpts provider options
306+
---@return function # the function for outputting the buffer number
307+
-- @usage local heirline_component = { provider = require("astroui.status").provider.bufnr() }
308+
-- @see astroui.status.utils.stylize
309+
function M.bufnr(opts)
310+
opts = extend_tbl(vim.tbl_get(config, "providers", "bufnr"), opts)
311+
return function(self)
312+
return status_utils.stylize(
313+
tostring(self and self.bufnr or vim.api.nvim_get_current_buf()) .. (opts.suffix or ""),
314+
opts
315+
)
316+
end
317+
end
318+
304319
--- A provider function for showing the current filename
305320
---@param opts? AstroUIProviderFilenameOpts provider options
306321
---@return function # the function for outputting the filename

0 commit comments

Comments
 (0)