Skip to content

Commit

Permalink
feat: dedicated lualine component (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbochs authored Mar 15, 2024
1 parent e4d2031 commit b07efce
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ MD033:
- "details"
- "img"
- "summary"
- "table"
- "td"
- "tr"
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,30 @@ A statusline component can be easily added to show whether a buffer is tagged.

**[lualine.nvim](https://github.com/nvim-lualine/lualine.nvim) statusline**

<table>
<tr>
<td> Snippet </td>
<td> Screenshot </td>
</tr>

<tr>
<td>

```lua
require("lualine").setup({
sections = {
lualine_b = { "grapple" }
}
})
```

</td>
<td><img width="300" alt="image" src="https://github.com/cbochs/grapple.nvim/assets/2467016/3b875b99-1a39-43f9-88c7-37814db86184"></td>
</tr>

<tr>
<td>

```lua
require("lualine").setup({
sections = {
Expand All @@ -867,6 +891,11 @@ require("lualine").setup({
})
```

</td>
<td><img width="300" alt="image" src="https://github.com/cbochs/grapple.nvim/assets/2467016/d10f4359-9463-4fb8-b131-f7867e4c8fcc"></td>
</tr>
</table>

## Grapple Types

<details open>
Expand Down
72 changes: 72 additions & 0 deletions lua/lualine/components/grapple.lua
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--]]

0 comments on commit b07efce

Please sign in to comment.