Skip to content

Commit

Permalink
feat: Icon Support and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
otavioschwanck committed Jul 9, 2023
1 parent 21f4c47 commit 4e94c02
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ currently only marks are supported in telescope
## ⇁ Configuration
if configuring harpoon is desired it must be done through harpoons setup function
```lua
require("harpoon").setup({ ... })
require("harpoon").setup({ global_settings = { ... }, projects = { ... }})
```

### Global Settings
Expand All @@ -152,6 +152,7 @@ global_settings = {

-- enable tabline with harpoon marks
tabline = false,
tabline_icons = false, -- requires nvim-web-devicons
tabline_prefix = " ",
tabline_suffix = " ",
}
Expand Down
3 changes: 2 additions & 1 deletion lua/harpoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function M.setup(config)
["excluded_filetypes"] = { "harpoon" },
["mark_branch"] = false,
["tabline"] = false,
["tabline_icons"] = false,
["tabline_suffix"] = " ",
["tabline_prefix"] = " ",
},
Expand All @@ -220,7 +221,7 @@ function M.setup(config)
-- an object for vim.loop.cwd()
ensure_correct_config(complete_config)

if complete_config.tabline then
if complete_config.global_settings.tabline then
require("harpoon.tabline").setup(complete_config)
end

Expand Down
34 changes: 27 additions & 7 deletions lua/harpoon/tabline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function M.setup(opts)
local tabline = ''

local index = require('harpoon.mark').get_index_of(vim.fn.bufname())
local cfg = opts.global_settings
local has_icons = cfg.tabline_icons

for i, tab in ipairs(tabs) do
local is_current = i == index
Expand All @@ -49,16 +51,34 @@ function M.setup(opts)
label = tab.filename
end


if is_current then
tabline = tabline ..
'%#HarpoonNumberActive#' .. (opts.tabline_prefix or ' ') .. i .. ' %*' .. '%#HarpoonActive#'
if has_icons then
local extension = tab.filename:match("^.+(%..+)$") or ""
local mime, color = require 'nvim-web-devicons'.get_icon(tab.filename, extension:sub(2, #extension),
{ default = true })

if is_current then
tabline = tabline ..
'%#HarpoonNumberActive#' ..
(cfg.tabline_prefix or ' ') ..
i .. ' %*%#' .. color .. '#' .. mime .. '%*%#HarpoonActive# '
else
tabline = tabline ..
'%#HarpoonNumberInactive#' ..
(cfg.tabline_prefix or ' ') ..
i .. ' %*%#' .. color .. '#' .. mime .. '%*' .. '%#HarpoonInactive# '
end
else
tabline = tabline ..
'%#HarpoonNumberInactive#' .. (opts.tabline_prefix or ' ') .. i .. ' %*' .. '%#HarpoonInactive#'
if is_current then
tabline = tabline ..
'%#HarpoonNumberActive#' .. (cfg.tabline_prefix or ' ') .. i .. ' %*' .. '%#HarpoonActive#'
else
tabline = tabline ..
'%#HarpoonNumberInactive#' ..
(opts.tabline_prefix or ' ') .. i .. ' %*' .. '%#HarpoonInactive#'
end
end

tabline = tabline .. label .. (opts.tabline_suffix or ' ') .. '%*'
tabline = tabline .. label .. (cfg.tabline_suffix or ' ') .. '%*'

if i < #tabs then
tabline = tabline .. '%T'
Expand Down

0 comments on commit 4e94c02

Please sign in to comment.