|
11 | 11 | -- Author: Kien Nguyen-Tuan <kiennt2609@gmail.com> |
12 | 12 |
|
13 | 13 | local lualine = require "lualine" |
| 14 | +local utils = require "utils" |
14 | 15 |
|
15 | 16 | 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, |
23 | 24 | } |
24 | 25 |
|
| 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 | + |
25 | 41 | -- Config |
26 | 42 | 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 | + }, |
70 | 96 | }, |
71 | | - }, |
72 | 97 | }, |
73 | | - }, |
74 | 98 |
|
75 | | - extensions = { "nvim-tree", "mason", "fzf" }, |
| 99 | + extensions = { "nvim-tree", "mason", "fzf" }, |
76 | 100 | } |
77 | 101 |
|
78 | 102 | -- Mode symbol |
79 | 103 | 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 "[?]" |
102 | 126 | end |
103 | 127 |
|
104 | 128 | -- 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 |
108 | 130 |
|
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 |
112 | 132 |
|
113 | 133 | -- Left side |
114 | 134 | ins_left { mode } |
115 | 135 |
|
116 | 136 | ins_left { |
117 | | - "branch", |
118 | | - icon = " ", |
119 | | - color = { gui = "bold" }, |
| 137 | + "branch", |
| 138 | + icon = " ", |
| 139 | + color = { gui = "bold" }, |
120 | 140 | } |
121 | 141 |
|
122 | 142 | 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, |
126 | 146 | } |
127 | 147 |
|
128 | 148 | ins_left { function() return "%=" end } |
129 | 149 |
|
130 | 150 | -- Right side |
131 | 151 | 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" }, |
147 | 165 | } |
148 | 166 |
|
149 | 167 | 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, |
154 | 172 | } |
155 | 173 |
|
156 | 174 | 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" }, |
161 | 179 | } |
162 | 180 |
|
163 | 181 | ins_right { |
164 | | - "location", |
165 | | - color = { gui = "bold" }, |
| 182 | + "location", |
| 183 | + color = { gui = "bold" }, |
166 | 184 | } |
167 | 185 |
|
168 | 186 | ins_right { |
169 | | - "progress", |
170 | | - color = { gui = "bold" }, |
| 187 | + "progress", |
| 188 | + color = { gui = "bold" }, |
171 | 189 | } |
172 | 190 |
|
173 | 191 | -- Initialize lualine |
|
0 commit comments