@@ -57,7 +57,7 @@ tlC.tabs = function (config)
57
57
end
58
58
59
59
--- @type integer Start index. Must be above 0 ;
60
- local from = math.max (vim .g .__bars_tabpage_from , 1 );
60
+ local from = utils . clamp (vim .g .__bars_tabpage_from , 1 , # tabs );
61
61
--- @type integer Number of tabs to show.
62
62
local max = config .max or 5 ;
63
63
--- @type boolean Is the list position locked ?
@@ -193,6 +193,210 @@ tlC.tabs = function (config)
193
193
--- | fE
194
194
end
195
195
196
+ --- Tab list.
197
+ --- @param config tabline.parts.tabs
198
+ --- @return string
199
+ tlC .bufs = function (config )
200
+ --- | fS
201
+
202
+ local function truncate_fname (fname , name_len )
203
+ name_len = name_len or 15 ;
204
+
205
+ if vim .fn .strchars (fname ) <= name_len then
206
+ return fname ;
207
+ else
208
+ local truncate_symbol = config .truncate_symbol or " …" ;
209
+
210
+ local ext = vim .fn .fnamemodify (fname , " :e" );
211
+ local name = vim .fn .fnamemodify (fname , " :t:r" );
212
+
213
+ local available_len = name_len - vim .fn .strchars (ext .. truncate_symbol .. " ." );
214
+
215
+ return string.format (
216
+ " %s%s%s%s" ,
217
+ vim .fn .strcharpart (name , 0 , math.max (available_len , 2 )),
218
+ truncate_symbol ,
219
+ ext ~= " " and " ." or " " ,
220
+ ext ~= " " and ext or " "
221
+ );
222
+ end
223
+ end
224
+
225
+ local bufs = utils .get_valid_bufs ();
226
+ local _o = " " ;
227
+
228
+ if not vim .g .__bars_buf_from then
229
+ vim .g .__bars_buf_from = 1 ;
230
+ elseif vim .g .__bars_buf_from > # bufs then
231
+ vim .g .__bars_buf_from = 1 ;
232
+ end
233
+
234
+ if not vim .g .__bars_tabpage_list_locked then
235
+ vim .g .__bars_tabpage_list_locked = false ;
236
+ end
237
+
238
+ --- @type integer Start index. Must be above 0 ;
239
+ local from = utils .clamp (vim .g .__bars_buf_from , 1 , # bufs );
240
+ --- @type integer Number of bufs to show.
241
+ local max = config .max or 5 ;
242
+ --- @type boolean Is the list position locked ?
243
+ local locked = vim .g .__bars_tabpage_list_locked ;
244
+
245
+ --- Maximum number of bufs to show.
246
+ --- Stored to he used by `autocmds`.
247
+ vim .g .__tabline_max_bufs = max ;
248
+
249
+ if from ~= 1 then
250
+ if locked == true then
251
+ _o = table.concat ({
252
+ _o ,
253
+
254
+ utils .create_segmant (config .nav_left_locked , config .nav_left_locked_hl ),
255
+ });
256
+ else
257
+ _o = table.concat ({
258
+ _o ,
259
+
260
+ " %@v:lua.__buf_from_decrease@" ,
261
+ utils .create_segmant (config .nav_left , config .nav_left_hl ),
262
+ " %X"
263
+ });
264
+ end
265
+ end
266
+
267
+ local wrapped = false ;
268
+
269
+ for t = from , from + (max - 1 ), 1 do
270
+ local buf_index = wrapped_index (# bufs , t );
271
+ local buffer = bufs [buf_index ];
272
+
273
+ if t > # bufs then
274
+ if buf_index == wrapped_index (# bufs , from ) and wrapped == true then
275
+ --- Do not wrap around multiple
276
+ --- times.
277
+ break ;
278
+ elseif from == 1 and # bufs < max then
279
+ --- If we are showing bufs from
280
+ --- the start and the number of
281
+ --- bufs are less than the amount
282
+ --- we can show, then don't wrap.
283
+ break ;
284
+ elseif buf_index == 1 then
285
+ --- Wrap marker should only be added
286
+ --- to the 1st entry.
287
+ wrapped = true ;
288
+
289
+ _o = table.concat ({
290
+ _o ,
291
+ utils .set_hl (config .overflow_hl ),
292
+ config .overflow or " "
293
+ });
294
+ else
295
+ _o = table.concat ({
296
+ _o ,
297
+ utils .create_segmant (config .separator , config .separator_hl )
298
+ });
299
+ end
300
+ elseif buf_index ~= 1 then
301
+ _o = table.concat ({
302
+ _o ,
303
+ utils .create_segmant (config .separator , config .separator_hl )
304
+ });
305
+ end
306
+
307
+ local current = buffer == vim .api .nvim_get_current_buf ();
308
+ local buf_config = current == true and (config .active or {}) or (config .inactive or {});
309
+
310
+ if current == false then
311
+ utils .create_to_buf (buffer )
312
+ end
313
+
314
+ local name = vim .fn .fnamemodify (vim .api .nvim_buf_get_name (buffer ), " :t" );
315
+
316
+ if name == " " then
317
+ name = " New file" ;
318
+ end
319
+
320
+ if buf_config .ft_icon ~= false and pcall (require , " icons" ) then
321
+ local icon_config = require (" icons" ).get (
322
+ vim .fn .fnamemodify (name , " :e" ),
323
+ {
324
+ buf_config .icon_hl , buf_config .icon ,
325
+ buf_config .icon_hl , buf_config .icon ,
326
+ buf_config .icon_hl , buf_config .icon ,
327
+ }
328
+ );
329
+
330
+ buf_config .icon = icon_config .icon ;
331
+ --- @type string
332
+ buf_config .icon_hl = buf_config .icon_hl or icon_config .hl ;
333
+ end
334
+
335
+ _o = table.concat ({
336
+ _o ,
337
+
338
+ current == false and " %@v:lua.__tabline_to_buf.b" .. buffer .. " @" or " " ,
339
+
340
+ utils .create_segmant (buf_config .corner_left , buf_config .corner_left_hl or buf_config .hl ),
341
+ utils .create_segmant (buf_config .padding_left , buf_config .padding_left_hl or buf_config .hl ),
342
+
343
+ utils .create_segmant (buf_config .icon , buf_config .icon_hl ),
344
+ });
345
+
346
+ if type (buf_config .win_count ) == " string" then
347
+ local wins = vim .fn .win_findbuf (buffer );
348
+
349
+ _o = table.concat ({
350
+ _o ,
351
+
352
+ utils .create_segmant (truncate_fname (name ), buf_config .hl ),
353
+ utils .create_segmant (
354
+ string.format (buf_config .win_count , # wins ),
355
+ buf_config .win_count_hl
356
+ ),
357
+ });
358
+ else
359
+ _o = table.concat ({
360
+ _o ,
361
+ utils .create_segmant (truncate_fname (name , buf_config .max_name_len ), buf_config .hl )
362
+ });
363
+ end
364
+
365
+ _o = table.concat ({
366
+ _o ,
367
+
368
+ utils .create_segmant (buf_config .padding_right , buf_config .padding_right_hl or buf_config .hl ),
369
+ utils .create_segmant (buf_config .corner_right , buf_config .corner_right_hl or buf_config .hl ),
370
+
371
+ current == false and " %T" or " "
372
+ });
373
+ end
374
+
375
+ if max < # bufs then
376
+ if locked == true then
377
+ _o = table.concat ({
378
+ _o ,
379
+
380
+ utils .create_segmant (config .separator , config .separator_hl ),
381
+ utils .create_segmant (config .nav_right_locked , config .nav_right_locked_hl ),
382
+ });
383
+ else
384
+ _o = table.concat ({
385
+ _o ,
386
+
387
+ utils .create_segmant (config .separator , config .separator_hl ),
388
+
389
+ " %@v:lua.__buf_from_increase@" ,
390
+ utils .create_segmant (config .nav_right , config .nav_right_hl ),
391
+ " %X"
392
+ });
393
+ end
394
+ end
395
+
396
+ return _o ;
397
+ --- | fE
398
+ end
399
+
196
400
--- Returns the output of the section {name}.
197
401
--- @param part_config table
198
402
--- @param tabline string
0 commit comments