-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dedicated lualine component (#120)
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ MD033: | |
- "details" | ||
- "img" | ||
- "summary" | ||
- "table" | ||
- "td" | ||
- "tr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
---@class grapple.lualine.component | ||
---@field options grapple.lualine.options | ||
local Component = require("lualine.component"):extend() | ||
|
||
---@class grapple.lualine.options | ||
local defaults = { | ||
icon = "", | ||
inactive = " %s ", | ||
active = "[%s]", | ||
} | ||
|
||
---@class grapple.lualine.options | ||
function Component:init(opts) | ||
opts = vim.tbl_deep_extend("keep", opts or {}, defaults) | ||
Component.super:init(opts) | ||
end | ||
|
||
function Component:update_status() | ||
if package.loaded["grapple"] == nil then | ||
return | ||
end | ||
|
||
local ok, grapple = pcall(require, "grapple") | ||
if not ok then | ||
return | ||
end | ||
|
||
local tags = grapple.tags() | ||
local current = grapple.find({ buffer = 0 }) | ||
|
||
local output = {} | ||
for i, tag in ipairs(tags) do | ||
local tag_str = tag.name and tag.name or i | ||
local tag_fmt = self.options.inactive | ||
if current and current.path == tag.path then | ||
tag_fmt = self.options.active | ||
end | ||
table.insert(output, string.format(tag_fmt, tag_str)) | ||
end | ||
|
||
return table.concat(output) | ||
end | ||
|
||
return Component | ||
|
||
--[[ | ||
local lualine_require = require("lualine_require") | ||
local M = lualine_require.require("lualine.component"):extend() | ||
local hl = require("harpoon-lualine") | ||
local default_options = { | ||
icon = " ", | ||
indicators = { "1", "2", "3", "4" }, | ||
active_indicators = { "[1]", "[2]", "[3]", "[4]" }, | ||
} | ||
function M:init(options) | ||
M.super.init(self, options) | ||
self.options = vim.tbl_deep_extend("keep", self.options or {}, default_options) | ||
end | ||
function M:update_status() | ||
local harpoon_loaded = package.loaded["harpoon"] ~= nil | ||
if not harpoon_loaded then | ||
return "Harpoon not loaded" | ||
end | ||
return hl.status(self.options) | ||
end | ||
return M--]] |