1
1
local tabline = {}
2
2
local components = require (" bars.components.tabline" );
3
3
4
+ --- Custom tabline.
5
+ --- @type string
6
+ local TBL = " %!v:lua.require('bars.tabline').render()" ;
7
+
4
8
--- @class tabline.config
5
9
tabline .config = {
6
10
--- | fS
204
208
tabline .detach = function ()
205
209
--- | fS
206
210
207
- vim .scheduleefer_fn (function ()
211
+ vim .schedule (function ()
208
212
tabline .state .attached = false ;
209
- vim .o .tabline = vim .o .__tabline or " " ;
213
+
214
+ --- Cached tabline.
215
+ --- @type string | nil
216
+ local _tl = vim .g .__tabline or " " ;
217
+
218
+ if _tl == " " or _tl == nil then
219
+ --- Reset tabline.
220
+ vim .cmd (" set tabline&" );
221
+ else
222
+ vim .api .nvim_set_option_value (
223
+ " tabline" ,
224
+ _tl ,
225
+ {
226
+ scope = " global"
227
+ }
228
+ );
229
+ end
210
230
211
231
vim .g .__tlID = nil ;
212
232
vim .g .__tabline = nil ;
@@ -216,7 +236,9 @@ tabline.detach = function ()
216
236
end
217
237
218
238
tabline .can_attach = function ()
219
- if not tabline .config .condition then
239
+ if tabline .state .enable ~= true then
240
+ return false ;
241
+ elseif tabline .config .condition == nil then
220
242
return true ;
221
243
end
222
244
@@ -239,8 +261,8 @@ tabline.attach = function ()
239
261
240
262
tabline .update_id ();
241
263
242
- vim .g .__tabline = vim .o .tabline ;
243
- vim .o .tabline = " %!v:lua.require('bars.tabline').render() " ;
264
+ vim .g .__tabline = vim .o .tabline == TBL and " " or vim . o . tabline ;
265
+ vim .o .tabline = TBL ;
244
266
245
267
--- | fE
246
268
end
@@ -255,6 +277,24 @@ tabline.clean = function ()
255
277
end );
256
278
end
257
279
280
+ --- Toggles state of tabline.
281
+ tabline .toggle = function ()
282
+ if tabline .state .attached == true then
283
+ tabline .detach ();
284
+ else
285
+ tabline .attach ();
286
+ end
287
+ end
288
+
289
+ --- Toggles tabline.
290
+ tabline .Toggle = function ()
291
+ tabline .toggle ();
292
+
293
+ --- true -> false,
294
+ --- false -> true
295
+ tabline .state .enable = not tabline .state .enable ;
296
+ end
297
+
258
298
--- Sets up the tabline module.
259
299
--- @param config tabline.config | nil
260
300
tabline .setup = function (config )
0 commit comments