1
- local config = require (" tvl.config.lualine.config" ).options
2
- local icons = require (" tvl.core.icons" )
1
+ local Config = require (" tvl.config.lualine.config" ).options
2
+ local Icons = require (" tvl.core.icons" )
3
+ local Util = require (" tvl.util" )
3
4
4
5
local M = {}
5
6
6
- local hl_str = function (str , hl_cur , hl_after )
7
+ --- @param text string text to be highlighted
8
+ --- @param hl_cur string highlight group for current text
9
+ --- @param hl_after ? string highlight group for text after current text
10
+ local hl_str = function (text , hl_cur , hl_after )
7
11
if hl_after == nil then
8
- return " %#" .. hl_cur .. " #" .. str .. " %*"
12
+ return " %#" .. hl_cur .. " #" .. text .. " %*"
9
13
end
10
- return " %#" .. hl_cur .. " #" .. str .. " %*" .. " %#" .. hl_after .. " #"
14
+ return " %#" .. hl_cur .. " #" .. text .. " %*" .. " %#" .. hl_after .. " #"
11
15
end
12
16
13
17
local function hide_in_width ()
@@ -35,26 +39,26 @@ M.branch = {
35
39
end
36
40
prev_branch = str
37
41
local icon = hl_str (" " , " SLGitIcon" , " SLBranchName" )
38
- return hl_str (config .separator_icon .left , " SLSeparator" )
42
+ return hl_str (Config .separator_icon .left , " SLSeparator" )
39
43
.. hl_str (icon , " SLGitIcon" )
40
44
.. hl_str (truncate (str , 10 ), " SLBranchName" )
41
- .. hl_str (config .separator_icon .right , " SLSeparator" , " SLSeparator" )
45
+ .. hl_str (Config .separator_icon .right , " SLSeparator" , " SLSeparator" )
42
46
end ,
43
47
}
44
48
45
49
M .position = function ()
46
50
-- print(vim.inspect(config.separator_icon))
47
51
local current_line = vim .fn .line (" ." )
48
52
local current_column = vim .fn .col (" ." )
49
- local left_sep = hl_str (config .separator_icon .left , " SLSeparator" )
50
- local right_sep = hl_str (config .separator_icon .right , " SLSeparator" , " SLSeparator" )
53
+ local left_sep = hl_str (Config .separator_icon .left , " SLSeparator" )
54
+ local right_sep = hl_str (Config .separator_icon .right , " SLSeparator" , " SLSeparator" )
51
55
local str = " Ln " .. current_line .. " , Col " .. current_column
52
56
return left_sep .. hl_str (str , " SLPosition" , " SLPosition" ) .. right_sep
53
57
end
54
58
55
59
M .spaces = function ()
56
- local left_sep = hl_str (config .separator_icon .left , " SLSeparator" )
57
- local right_sep = hl_str (config .separator_icon .right , " SLSeparator" , " SLSeparator" )
60
+ local left_sep = hl_str (Config .separator_icon .left , " SLSeparator" )
61
+ local right_sep = hl_str (Config .separator_icon .right , " SLSeparator" , " SLSeparator" )
58
62
local str = " Spaces: " .. vim .api .nvim_buf_get_option (0 , " shiftwidth" )
59
63
return left_sep .. hl_str (str , " SLShiftWidth" , " SLShiftWidth" ) .. right_sep
60
64
end
@@ -73,15 +77,32 @@ M.diagnostics = function()
73
77
end
74
78
75
79
local error_count , warn_count , info_count , hint_count = nvim_diagnostic ()
76
- local error_hl = hl_str (icons .diagnostics .error .. " " .. error_count , " SLError" , " SLError" )
77
- local warn_hl = hl_str (icons .diagnostics .warn .. " " .. warn_count , " SLWarning" , " SLWarning" )
78
- local info_hl = hl_str (icons .diagnostics .info .. " " .. info_count , " SLInfo" , " SLInfo" )
79
- local hint_hl = hl_str (icons .diagnostics .hint .. " " .. hint_count , " SLInfo" , " SLInfo" )
80
- local left_sep = hl_str (config .thin_separator_icon .left , " SLSeparator" )
81
- local right_sep = hl_str (config .thin_separator_icon .right , " SLSeparator" , " SLSeparator" )
80
+ local error_hl = hl_str (Icons .diagnostics .error .. " " .. error_count , " SLError" , " SLError" )
81
+ local warn_hl = hl_str (Icons .diagnostics .warn .. " " .. warn_count , " SLWarning" , " SLWarning" )
82
+ --- @diagnostic disable-next-line : unused-local
83
+ local info_hl = hl_str (Icons .diagnostics .info .. " " .. info_count , " SLInfo" , " SLInfo" )
84
+ local hint_hl = hl_str (Icons .diagnostics .hint .. " " .. hint_count , " SLInfo" , " SLInfo" )
85
+ local left_sep = hl_str (Config .thin_separator_icon .left , " SLSeparator" )
86
+ local right_sep = hl_str (Config .thin_separator_icon .right , " SLSeparator" , " SLSeparator" )
82
87
return left_sep .. error_hl .. " " .. warn_hl .. " " .. hint_hl .. right_sep
83
88
end
84
89
90
+ --- @param content string
91
+ --- @param type ? " fill" | " empty"
92
+ local build_module = function (content , type )
93
+ local left_sep = " "
94
+ local right_sep = " "
95
+ if type == " fill" then
96
+ left_sep = hl_str (Config .separator_icon .left , " SLSeparator" )
97
+ right_sep = hl_str (Config .separator_icon .right , " SLSeparator" , " SLSeparator" )
98
+ end
99
+ if type == " empty" then
100
+ left_sep = hl_str (Config .thin_separator_icon .left , " SLSeparator" )
101
+ right_sep = hl_str (Config .thin_separator_icon .right , " SLSeparator" , " SLSeparator" )
102
+ end
103
+ return left_sep .. content .. right_sep
104
+ end
105
+
85
106
M .diff = {
86
107
" diff" ,
87
108
colored = true ,
@@ -91,16 +112,16 @@ M.diff = {
91
112
removed = " SLDiffDelete" ,
92
113
},
93
114
symbols = {
94
- added = icons .git .added .. " " ,
95
- modified = icons .git .modified .. " " ,
96
- removed = icons .git .removed .. " " ,
115
+ added = Icons .git .added .. " " ,
116
+ modified = Icons .git .modified .. " " ,
117
+ removed = Icons .git .removed .. " " ,
97
118
}, -- changes diff symbols
98
119
fmt = function (str )
99
120
if str == " " then
100
121
return " "
101
122
end
102
- local left_sep = hl_str (config .thin_separator_icon .left , " SLSeparator" )
103
- local right_sep = hl_str (config .thin_separator_icon .right , " SLSeparator" , " SLSeparator" )
123
+ local left_sep = hl_str (Config .thin_separator_icon .left , " SLSeparator" )
124
+ local right_sep = hl_str (Config .thin_separator_icon .right , " SLSeparator" , " SLSeparator" )
104
125
return left_sep .. str .. right_sep
105
126
end ,
106
127
cond = hide_in_width ,
@@ -109,12 +130,32 @@ M.diff = {
109
130
M .mode = {
110
131
" mode" ,
111
132
fmt = function (str )
112
- local left_sep = hl_str (config .separator_icon .left , " SLSeparator" , " SLPadding" )
113
- local right_sep = hl_str (config .separator_icon .right , " SLSeparator" , " SLPadding" )
133
+ local left_sep = hl_str (Config .separator_icon .left , " SLSeparator" , " SLPadding" )
134
+ local right_sep = hl_str (Config .separator_icon .right , " SLSeparator" , " SLPadding" )
114
135
return left_sep .. hl_str (str , " SLMode" ) .. right_sep
115
136
end ,
116
137
}
117
138
139
+ M .cmp_source = function (name )
140
+ local ok , _ = pcall (require , " cmp" )
141
+ if not ok then
142
+ return " "
143
+ end
144
+ for _ , s in ipairs (require (" cmp" ).core .sources ) do
145
+ if s .name == name then
146
+ -- Warning if not icons.misc doesn't have name
147
+ if not Icons .misc [name ] then
148
+ Util .notify (" No icon for " .. name , " warn" )
149
+ end
150
+ print (" hello" )
151
+ end
152
+ end
153
+ return function ()
154
+ local text = Icons .misc [name ]
155
+ return build_module (hl_str (text , " CmpItemKindVariable" ), " fill" )
156
+ end
157
+ end
158
+
118
159
local prev_filetype = " "
119
160
M .filetype = {
120
161
" filetype" ,
@@ -155,8 +196,8 @@ M.filetype = {
155
196
prev_filetype = str
156
197
filetype_str = str
157
198
end
158
- local left_sep = hl_str (config .separator_icon .left , " SLSeparator" )
159
- local right_sep = hl_str (config .separator_icon .right , " SLSeparator" , " SLSeparator" )
199
+ local left_sep = hl_str (Config .separator_icon .left , " SLSeparator" )
200
+ local right_sep = hl_str (Config .separator_icon .right , " SLSeparator" , " SLSeparator" )
160
201
-- Upper case first character
161
202
filetype_str = filetype_str :gsub (" %a" , string.upper , 1 )
162
203
local filetype_hl = hl_str (filetype_str , " SLFiletype" , " SLFiletype" )
0 commit comments