Skip to content

Commit 7ba0f96

Browse files
committed
fix(lualine): truly transparent
1 parent 58d072c commit 7ba0f96

File tree

2 files changed

+140
-114
lines changed

2 files changed

+140
-114
lines changed

lua/autocmds.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ autocmd("Filetype", {
6262
vim.opt_local.spell = true
6363
end,
6464
})
65+
66+
autocmd({ "ColorScheme" }, {
67+
callback = function()
68+
vim.cmd [[hi Lualine_c_normal guibg=none]]
69+
vim.cmd [[hi StatusLine guibg=none]]
70+
vim.cmd [[hi StatusLineNC guibg=none]]
71+
end,
72+
})

lua/plugins/configs/lualine.lua

Lines changed: 132 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -11,163 +11,181 @@
1111
-- Author: Kien Nguyen-Tuan <kiennt2609@gmail.com>
1212

1313
local lualine = require "lualine"
14+
local utils = require "utils"
1415

1516
local conditions = {
16-
buffer_not_empty = function() return vim.fn.empty(vim.fn.expand "%:t") ~= 1 end,
17-
hide_in_width = function() return vim.fn.winwidth(0) > 80 end,
18-
check_git_workspace = function()
19-
local filepath = vim.fn.expand "%:p:h"
20-
local gitdir = vim.fn.finddir(".git", filepath .. ";")
21-
return gitdir and #gitdir > 0 and #gitdir < #filepath
22-
end,
17+
buffer_not_empty = function() return vim.fn.empty(vim.fn.expand "%:t") ~= 1 end,
18+
hide_in_width = function() return vim.fn.winwidth(0) > 80 end,
19+
check_git_workspace = function()
20+
local filepath = vim.fn.expand "%:p:h"
21+
local gitdir = vim.fn.finddir(".git", filepath .. ";")
22+
return gitdir and #gitdir > 0 and #gitdir < #filepath
23+
end,
2324
}
2425

26+
local auto = require "lualine.themes.auto"
27+
local function make_transparent(theme_table)
28+
for _, sections in pairs(theme_table) do
29+
if type(sections) == "table" then
30+
for _, section_colors in pairs(sections) do
31+
-- Set the background of every section to nil
32+
if type(section_colors) == "table" and section_colors.bg then section_colors.bg = nil end
33+
end
34+
end
35+
end
36+
end
37+
38+
-- Apply transparency
39+
make_transparent(auto)
40+
2541
-- Config
2642
local config = {
27-
options = {
28-
theme = "auto",
29-
component_separators = "",
30-
section_separators = "",
31-
disabled_filetypes = { "Lazy", "NvimTree" },
32-
},
33-
34-
sections = {
35-
lualine_a = {},
36-
lualine_b = {},
37-
lualine_y = {},
38-
lualine_z = {},
39-
lualine_c = {},
40-
lualine_x = {},
41-
},
42-
43-
inactive_sections = {
44-
lualine_a = {},
45-
lualine_b = {},
46-
lualine_y = {},
47-
lualine_z = {},
48-
lualine_c = {},
49-
lualine_x = {},
50-
},
51-
52-
tabline = {
53-
lualine_a = {
54-
{
55-
"buffers",
56-
max_length = vim.o.columns * 2 / 3,
57-
show_filename_only = false,
58-
mode = 0,
59-
right_padding = 5,
60-
left_padding = 5,
61-
use_mode_colors = true,
62-
buffers_color = {
63-
active = { gui = "bold" },
64-
inactive = {},
65-
},
66-
symbols = {
67-
modified = "",
68-
alternate_file = "",
69-
directory = "",
43+
options = {
44+
theme = auto,
45+
component_separators = "",
46+
section_separators = "",
47+
disabled_filetypes = { "Lazy", "NvimTree" },
48+
},
49+
50+
sections = {
51+
lualine_a = {},
52+
lualine_b = {},
53+
lualine_y = {},
54+
lualine_z = {},
55+
lualine_c = {},
56+
lualine_x = {},
57+
},
58+
59+
inactive_sections = {
60+
lualine_a = {},
61+
lualine_b = {},
62+
lualine_y = {},
63+
lualine_z = {},
64+
lualine_c = {},
65+
lualine_x = {},
66+
},
67+
68+
tabline = {
69+
lualine_a = {
70+
{
71+
"buffers",
72+
max_length = vim.o.columns * 2 / 3,
73+
show_filename_only = false,
74+
mode = 0,
75+
right_padding = 5,
76+
left_padding = 5,
77+
use_mode_colors = true,
78+
buffers_color = {
79+
-- Same values as the general color option can be used here.
80+
active = {
81+
fg = utils.darken(auto.normal.a.fg, 1.2),
82+
bg = auto.normal.a.bg,
83+
gui = "bold",
84+
},
85+
inactive = {
86+
fg = auto.normal.a.fg,
87+
bg = auto.normal.a.bg,
88+
},
89+
},
90+
symbols = {
91+
modified = "",
92+
alternate_file = "",
93+
directory = "",
94+
},
95+
},
7096
},
71-
},
7297
},
73-
},
7498

75-
extensions = { "nvim-tree", "mason", "fzf" },
99+
extensions = { "nvim-tree", "mason", "fzf" },
76100
}
77101

78102
-- Mode symbol
79103
local function mode()
80-
local mode_map = {
81-
n = "N",
82-
i = "I",
83-
v = "V",
84-
[""] = "V",
85-
V = "V",
86-
c = "C",
87-
no = "N",
88-
s = "S",
89-
S = "S",
90-
ic = "I",
91-
R = "R",
92-
Rv = "R",
93-
cv = "C",
94-
ce = "C",
95-
r = "R",
96-
rm = "M",
97-
["r?"] = "?",
98-
["!"] = "!",
99-
t = "T",
100-
}
101-
return mode_map[vim.fn.mode()] or "[?]"
104+
local mode_map = {
105+
n = "N",
106+
i = "I",
107+
v = "V",
108+
[""] = "V",
109+
V = "V",
110+
c = "C",
111+
no = "N",
112+
s = "S",
113+
S = "S",
114+
ic = "I",
115+
R = "R",
116+
Rv = "R",
117+
cv = "C",
118+
ce = "C",
119+
r = "R",
120+
rm = "M",
121+
["r?"] = "?",
122+
["!"] = "!",
123+
t = "T",
124+
}
125+
return mode_map[vim.fn.mode()] or "[?]"
102126
end
103127

104128
-- Helpers
105-
local function ins_left(component)
106-
table.insert(config.sections.lualine_c, component)
107-
end
129+
local function ins_left(component) table.insert(config.sections.lualine_c, component) end
108130

109-
local function ins_right(component)
110-
table.insert(config.sections.lualine_x, component)
111-
end
131+
local function ins_right(component) table.insert(config.sections.lualine_x, component) end
112132

113133
-- Left side
114134
ins_left { mode }
115135

116136
ins_left {
117-
"branch",
118-
icon = "",
119-
color = { gui = "bold" },
137+
"branch",
138+
icon = "",
139+
color = { gui = "bold" },
120140
}
121141

122142
ins_left {
123-
"diff",
124-
symbols = { added = "", modified = "󰝤 ", removed = "" },
125-
cond = conditions.hide_in_width,
143+
"diff",
144+
symbols = { added = "", modified = "󰝤 ", removed = "" },
145+
cond = conditions.hide_in_width,
126146
}
127147

128148
ins_left { function() return "%=" end }
129149

130150
-- Right side
131151
ins_right {
132-
function()
133-
local msg = "null"
134-
local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
135-
local clients = vim.lsp.get_active_clients()
136-
if next(clients) == nil then return msg end
137-
for _, client in ipairs(clients) do
138-
local filetypes = client.config.filetypes
139-
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
140-
return client.name
141-
end
142-
end
143-
return msg
144-
end,
145-
icon = " LSP:",
146-
color = { gui = "bold" },
152+
function()
153+
local msg = "null"
154+
local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
155+
local clients = vim.lsp.get_active_clients()
156+
if next(clients) == nil then return msg end
157+
for _, client in ipairs(clients) do
158+
local filetypes = client.config.filetypes
159+
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then return client.name end
160+
end
161+
return msg
162+
end,
163+
icon = " LSP:",
164+
color = { gui = "bold" },
147165
}
148166

149167
ins_right {
150-
"diagnostics",
151-
sources = { "nvim_diagnostic" },
152-
symbols = { error = "", warn = "", info = "", hints = "󰛩 " },
153-
always_visible = false,
168+
"diagnostics",
169+
sources = { "nvim_diagnostic" },
170+
symbols = { error = "", warn = "", info = "", hints = "󰛩 " },
171+
always_visible = false,
154172
}
155173

156174
ins_right {
157-
"fileformat",
158-
fmt = string.upper,
159-
icons_enabled = true,
160-
color = { gui = "bold" },
175+
"fileformat",
176+
fmt = string.upper,
177+
icons_enabled = true,
178+
color = { gui = "bold" },
161179
}
162180

163181
ins_right {
164-
"location",
165-
color = { gui = "bold" },
182+
"location",
183+
color = { gui = "bold" },
166184
}
167185

168186
ins_right {
169-
"progress",
170-
color = { gui = "bold" },
187+
"progress",
188+
color = { gui = "bold" },
171189
}
172190

173191
-- Initialize lualine

0 commit comments

Comments
 (0)