Skip to content

Commit

Permalink
feat(dashboard): add ability for text keys and preset.header to be fu…
Browse files Browse the repository at this point in the history
…nctions
  • Loading branch information
dsully committed Jan 3, 2025
1 parent d312053 commit 6134329
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lua/snacks/dashboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ math.randomseed(os.time())
---@field header? string
---@field icon? string
---@field title? string
---@field text? string|snacks.dashboard.Text[]
---@field text? snacks.dashboard.TextFunc

---@alias snacks.dashboard.Format.ctx {width?:number}
---@alias snacks.dashboard.Action string|fun(self:snacks.dashboard.Class)
---@alias snacks.dashboard.Gen fun(self:snacks.dashboard.Class):snacks.dashboard.Section?
---@alias snacks.dashboard.Section snacks.dashboard.Item|snacks.dashboard.Gen|snacks.dashboard.Section[]
---@alias snacks.dashboard.TextFunc snacks.dashboard.Text[]|snacks.dashboard.Text|string|fun():string|snacks.dashboard.Text|snacks.dashboard.Text[]

---@class snacks.dashboard.Text
---@field [1] string the text
Expand Down Expand Up @@ -101,6 +102,7 @@ local defaults = {
{ icon = " ", key = "q", desc = "Quit", action = ":qa" },
},
-- Used by the `header` section
---@type string|snacks.dashboard.TextFunc
header = [[
β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘
Expand Down Expand Up @@ -357,9 +359,10 @@ function D:align(item, width, align)
end
end

---@param texts snacks.dashboard.Text[]|snacks.dashboard.Text|string
---@param texts snacks.dashboard.TextFunc
function D:texts(texts)
texts = type(texts) == "string" and { { texts } } or texts
texts = type(texts) == "function" and { texts() } or texts
texts = type(texts[1]) == "string" and { texts } or texts
return texts --[[ @as snacks.dashboard.Text[] ]]
end
Expand Down Expand Up @@ -916,7 +919,7 @@ end
---@return snacks.dashboard.Gen
function M.sections.header()
return function(self)
return { header = self.opts.preset.header, padding = 2 }
return { header = type(self.opts.preset.header) == "function" and self.opts.preset.header() or self.opts.preset.header, padding = 2 }
end
end

Expand Down

0 comments on commit 6134329

Please sign in to comment.