Skip to content

Commit 6da7eb5

Browse files
remove treesitter icon, colorize filetype if no treesitter
1 parent 3e1ea67 commit 6da7eb5

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

nvim/lua/dko/heirline/winbar-filename.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
local dkohl = require("dko.heirline.utils").hl
12
local utils = require("heirline.utils")
2-
local hl = require("dko.heirline.utils").hl
33

44
local DIRTY = { fg = utils.get_highlight("Todo").fg }
55

@@ -17,7 +17,7 @@ return {
1717
end,
1818
provider = "",
1919
hl = function()
20-
return hl("Special")
20+
return dkohl("Special")
2121
end,
2222
},
2323

@@ -37,7 +37,7 @@ return {
3737
return vim.fn.fnamemodify(self.filepath, ":t")
3838
end,
3939
hl = function()
40-
return hl(vim.bo.modified and DIRTY or "StatusLine")
40+
return dkohl(vim.bo.modified and DIRTY or "StatusLine")
4141
end,
4242
},
4343
{ provider = " " },

nvim/lua/dko/heirline/winbar-filepath.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ return {
1313
end,
1414
provider = function(self)
1515
local win_width = vim.api.nvim_win_get_width(0)
16-
local extrachars = 3 + 3 + self.filetype_text:len()
16+
local extrachars = 3 + self.filetype_text:len()
1717
local remaining = win_width - extrachars
1818

1919
local cwd = vim.fn.fnamemodify(vim.uv.cwd() or "", ":~")

nvim/lua/dko/heirline/winbar-filetype.lua

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
local hl = require("dko.heirline.utils").hl
1+
local dkohl = require("dko.heirline.utils").hl
2+
local dkots = require("dko.utils.treesitter")
23
local utils = require("heirline.utils")
34

45
-- =======================================================================
@@ -10,8 +11,25 @@ return {
1011
return vim.bo.filetype ~= ""
1112
end,
1213

14+
init = function(self)
15+
self.bg = dkots.is_highlight_enabled()
16+
and utils.get_highlight("dkoStatusKey").bg
17+
or utils.get_highlight("DiffDelete").bg
18+
self.fg = dkots.is_highlight_enabled()
19+
and utils.get_highlight("StatusLine").fg
20+
or utils.get_highlight("DiffDelete").fg
21+
self.treesitter_active = {
22+
fg = self.fg,
23+
bg = self.bg,
24+
}
25+
end,
26+
1327
utils.surround({ "", "" }, function()
14-
return utils.get_highlight("dkoStatusKey").bg
28+
local bg = dkots.is_highlight_enabled()
29+
and utils.get_highlight("dkoStatusKey").bg
30+
or utils.get_highlight("DiffDelete").bg
31+
--- red if no treesitter
32+
return dkohl(bg, utils.get_highlight("dkoStatusKey").bg)
1533
end, {
1634
{
1735
condition = function(self)
@@ -20,12 +38,12 @@ return {
2038
provider = function(self)
2139
return self.icon
2240
end,
23-
hl = function()
41+
hl = function(self)
2442
local _, icons = pcall(require, "nvim-web-devicons")
2543
if icons then
2644
local _, color = icons.get_icon_color_by_filetype(vim.bo.filetype)
2745
if color then
28-
return hl({ fg = color }, "dkoStatusKey")
46+
return dkohl({ fg = color, bg = self.bg }, "dkoStatusKey")
2947
end
3048
end
3149
return ""
@@ -38,7 +56,9 @@ return {
3856
provider = function(self)
3957
return (self.icon ~= "" and " " or "") .. self.filetype_text
4058
end,
41-
hl = "dkoStatusKey",
59+
hl = function(self)
60+
return dkohl(self.treesitter_active, "dkoStatusKey")
61+
end,
4262
},
4363
}),
4464
}

nvim/lua/dko/heirline/winbar-treesitter.lua

Lines changed: 0 additions & 22 deletions
This file was deleted.

nvim/lua/dko/heirline/winbar.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ return {
2222
hl = function()
2323
return hl()
2424
end,
25-
require("dko.heirline.winbar-treesitter"),
2625
require("dko.heirline.winbar-filetype"),
2726
require("dko.heirline.winbar-filename"),
2827
require("dko.heirline.winbar-filepath"),

nvim/lua/dko/utils/treesitter.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ local M = {}
22

33
M.is_highlight_enabled = function(bufnr)
44
bufnr = bufnr and vim.fn.bufnr(bufnr) or vim.fn.bufnr()
5-
return bufnr > -1 and vim.treesitter.highlighter.active[bufnr] ~= nil
5+
if bufnr > -1 then
6+
return vim.treesitter.highlighter.active[bufnr] ~= nil
7+
end
8+
return false
69
end
710

811
return M

0 commit comments

Comments
 (0)