1
1
local wbC = {};
2
2
local utils = require (" bars.utils" );
3
3
4
- wbC .path = function (buffer , window , main_config )
5
- --- @type string | " "
6
- local name = vim .api .nvim_buf_get_name (buffer );
7
-
8
- if name == " " then
9
- return ;
10
- else
11
- name = vim .fn .fnamemodify (name , " :~:." );
12
- end
13
-
14
- --- @type integer
15
- local throttle = main_config .throttle or 50 ;
16
-
17
- --- @type integer
18
- local before = vim .w [window ].__path_time or 0 ;
19
- --- @type string
20
- local old = vim .w [window ].__path_data ;
21
- --- @type integer
22
- local now = vim .uv .hrtime ();
23
-
24
- if old and (now - before ) < (throttle * 1e6 ) then
25
- return old ;
26
- end
27
-
28
- local sep = string.sub (package.config or " " , 1 , 1 );
29
-
30
- if sep == " \\ " then
31
- name = string.gsub (name , " ^%u:" , " " );
32
- end
33
-
34
- --- @type string[]
35
- local parts = vim .split (name , " /" , { trimempty = true });
36
- local _o = " " ;
37
-
38
- while # parts > 0 do
39
- local part = parts [# parts ];
40
-
41
- local part_config = utils .match (main_config , part , {});
42
- local is_dir = false ;
43
-
44
- if _o ~= " " and vim .fn .fnamemodify (part , " :e" ) == " " then
45
- is_dir = true ;
46
- end
47
-
48
- _o = table.concat ({
49
-
50
- utils .create_segmant (part_config .corner_left , part_config .corner_left_hl or part_config .hl ),
51
- utils .create_segmant (part_config .padding_left , part_config .padding_left_hl or part_config .hl ),
52
- utils .create_segmant (is_dir == true and part_config .dir_icon or part_config .icon , (is_dir == true and part_config .dir_icon_hl or part_config .icon_hl ) or part_config .hl ),
53
-
54
- utils .create_segmant (part_config .text or part , part_config .hl ),
55
-
56
- utils .create_segmant (part_config .padding_right , part_config .padding_right_hl or part_config .hl ),
57
- utils .create_segmant (part_config .corner_right , part_config .corner_right_hl or part_config .hl ),
58
-
59
- utils .create_segmant (_o ~= " " and main_config .separator or " " , main_config .separator_hl ),
60
-
61
- _o ,
62
- });
63
-
64
- table.remove (parts , # parts );
65
- end
66
-
67
- vim .w [window ].__path_data = _o ;
68
- vim .w [window ].__path_time = now ;
69
-
70
- return _o ;
71
- end
72
-
73
4
--- Node under cursor
74
5
--- @param buffer integer
75
6
--- @param window integer
76
- --- @param main_config winbar.node
7
+ --- @param main_config winbar.part. node
77
8
--- @return string
78
9
wbC .node = function (buffer , window , main_config )
79
10
--- | fS
@@ -145,13 +76,13 @@ wbC.node = function (buffer, window, main_config)
145
76
return node ;
146
77
end
147
78
148
- local lookup = main_config .lookup or 9 ;
79
+ local depth = main_config .depth or 9 ;
149
80
local _o = " " ;
150
81
151
82
while node do
152
83
--- | fS
153
84
154
- if lookup <= 0 then
85
+ if depth <= 0 then
155
86
break ;
156
87
end
157
88
@@ -161,7 +92,7 @@ wbC.node = function (buffer, window, main_config)
161
92
local item_config = utils .match (lang_config , node :type (), {});
162
93
local has_sep = true ;
163
94
164
- if lookup == 1 then
95
+ if depth == 1 then
165
96
has_sep = false ;
166
97
elseif not node :parent () then
167
98
has_sep = false ;
@@ -194,7 +125,7 @@ wbC.node = function (buffer, window, main_config)
194
125
195
126
_o ,
196
127
});
197
- lookup = lookup - 1 ;
128
+ depth = depth - 1 ;
198
129
199
130
:: ignore::
200
131
@@ -203,7 +134,7 @@ wbC.node = function (buffer, window, main_config)
203
134
--- | fE
204
135
end
205
136
206
- if lookup <= 0 and node then
137
+ if depth <= 0 and node then
207
138
local lanuage = get_language (node );
208
139
local lang_config = utils .match (main_config , lanuage or " default" , {});
209
140
@@ -226,32 +157,97 @@ wbC.node = function (buffer, window, main_config)
226
157
});
227
158
end
228
159
229
- if type (main_config .max_width ) == " number" then
160
+ vim .w [window ].__node_data = _o ;
161
+ vim .w [window ].__node_time = now ;
162
+
163
+ return _o ;
164
+
165
+ --- | fE
166
+ end
167
+
168
+ --- Node under cursor
169
+ --- @param buffer integer
170
+ --- @param window integer
171
+ --- @param main_config winbar.part.path
172
+ --- @return string
173
+ wbC .path = function (buffer , window , main_config )
174
+ --- | fS
175
+
176
+ --- @type string | " "
177
+ local name = vim .api .nvim_buf_get_name (buffer );
178
+
179
+ if name == " " then
180
+ return " " ;
181
+ else
182
+ name = vim .fn .fnamemodify (name , " :~:." );
183
+ end
184
+
185
+ --- @type integer
186
+ local throttle = main_config .throttle or 50 ;
187
+
188
+ --- @type integer
189
+ local before = vim .w [window ].__path_time or 0 ;
190
+ --- @type string
191
+ local old = vim .w [window ].__path_data ;
192
+ --- @type integer
193
+ local now = vim .uv .hrtime ();
194
+
195
+ if old and (now - before ) < (throttle * 1e6 ) then
196
+ return old ;
197
+ end
198
+
199
+ local sep = string.sub (package.config or " " , 1 , 1 );
200
+
201
+ if sep == " \\ " then
202
+ name = string.gsub (name , " ^%u:" , " " );
203
+ end
204
+
205
+ --- @type string[]
206
+ local parts = vim .split (name , sep , { trimempty = true });
207
+ local _o = " " ;
208
+
209
+ while # parts > 0 do
210
+ local part = parts [# parts ];
211
+
212
+ local part_config = utils .match (main_config , part , {});
213
+ local is_dir = false ;
214
+
215
+ if _o ~= " " and vim .fn .fnamemodify (part , " :e" ) == " " then
216
+ is_dir = true ;
217
+ end
218
+
230
219
_o = table.concat ({
231
- " %" ,
232
- 0 ,
233
- " ." ,
234
- main_config .max_width ,
235
- " (" ,
236
- " " ,
220
+
221
+ utils .create_segmant (part_config .corner_left , part_config .corner_left_hl or part_config .hl ),
222
+ utils .create_segmant (part_config .padding_left , part_config .padding_left_hl or part_config .hl ),
223
+ utils .create_segmant (is_dir == true and part_config .dir_icon or part_config .icon , (is_dir == true and part_config .dir_icon_hl or part_config .icon_hl ) or part_config .hl ),
224
+
225
+ utils .create_segmant (part_config .text or part , part_config .hl ),
226
+
227
+ utils .create_segmant (part_config .padding_right , part_config .padding_right_hl or part_config .hl ),
228
+ utils .create_segmant (part_config .corner_right , part_config .corner_right_hl or part_config .hl ),
229
+
230
+ utils .create_segmant (_o ~= " " and main_config .separator or " " , main_config .separator_hl ),
231
+
237
232
_o ,
238
- " %)"
239
233
});
234
+
235
+ table.remove (parts , # parts );
240
236
end
241
237
242
- vim .w [window ].__node_data = _o ;
243
- vim .w [window ].__node_time = now ;
238
+ vim .w [window ].__path_data = _o ;
239
+ vim .w [window ].__path_time = now ;
244
240
245
241
return _o ;
246
242
247
243
--- | fE
248
244
end
249
245
250
246
--- Custom section.
251
- --- @param config winbae.parts .custom
247
+ --- @param config winbar.part .custom
252
248
--- @return string
253
249
wbC .custom = function (_ , _ , config )
254
- return config .value ;
250
+ return config .value --[[ @as string ]] ;
255
251
end
256
252
257
253
---- ------------------------------------------------------------------
0 commit comments