Skip to content

Commit abaed7e

Browse files
committed
feat(nut): add tab.tablist.number
1 parent f2cfd55 commit abaed7e

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
local core = require("nougat.core")
2+
local Item = require("nougat.item")
3+
4+
-- re-used tables
5+
local o_label_opts = { tabnr = nil }
6+
local o_label_parts = {}
7+
8+
---@param ctx nougat.nut.tab.tablist_ctx
9+
local function content(_, ctx)
10+
o_label_opts.tabnr = ctx.tab.tabnr
11+
local parts_len = core.add_label(tostring(ctx.tab.tabnr), o_label_opts, o_label_parts, 0)
12+
return table.concat(o_label_parts, nil, 1, parts_len)
13+
end
14+
15+
local hl = {}
16+
17+
function hl.diagnostic()
18+
return require("nougat.nut.tab.tablist.label").hl.diagnostic()
19+
end
20+
21+
local mod = {
22+
hl = hl,
23+
}
24+
25+
---@param config nougat_item_config__nil
26+
function mod.create(config)
27+
local item = Item({
28+
priority = config.priority,
29+
hidden = config.hidden,
30+
hl = config.hl,
31+
sep_left = config.sep_left,
32+
prefix = config.prefix,
33+
content = content,
34+
suffix = config.suffix,
35+
sep_right = config.sep_right,
36+
on_click = config.on_click,
37+
context = config.context,
38+
})
39+
40+
return item
41+
end
42+
43+
return mod

tests/nougat/nut/tab/tablist_spec.lua

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ describe("nut.tab.tablist", function()
3333
label = require("nougat.nut.tab.tablist.label").create,
3434
label_hl = require("nougat.nut.tab.tablist.label").hl,
3535
modified = require("nougat.nut.tab.tablist.modified").create,
36+
number = require("nougat.nut.tab.tablist.number").create,
37+
number_hl = require("nougat.nut.tab.tablist.number").hl,
3638
}
3739

3840
tabs = {}
@@ -394,6 +396,64 @@ describe("nut.tab.tablist", function()
394396
end)
395397
end)
396398

399+
describe("number", function()
400+
it("handles tab move", function()
401+
vim.api.nvim_buf_set_name(tabs[1].bufnr, "_A_")
402+
vim.api.nvim_buf_set_name(add_tab().bufnr, "_B_")
403+
vim.api.nvim_buf_set_name(add_tab().bufnr, "_C_")
404+
405+
bar:add_item(tablist.tabs({
406+
active_tab = {
407+
content = {
408+
tablist.number({}),
409+
},
410+
},
411+
inactive_tab = {
412+
content = {
413+
tablist.number({}),
414+
},
415+
},
416+
}))
417+
418+
t.eq(
419+
bar:generate(ctx),
420+
table.concat({
421+
"%#bg_0a0b10_fg_c4c6cd_b#",
422+
"%1T1%T",
423+
"%#bg_0a0b10_fg_c4c6cd_#",
424+
"%#bg_0a0b10_fg_c4c6cd_#",
425+
"%2T2%T",
426+
"%#bg_0a0b10_fg_c4c6cd_#",
427+
"%#bg_0a0b10_fg_c4c6cd_#",
428+
"%3T3%T",
429+
"%#bg_0a0b10_fg_c4c6cd_#",
430+
})
431+
)
432+
433+
vim.api.nvim_set_current_tabpage(tabs[1].tabid)
434+
vim.cmd.tabmove(2)
435+
436+
t.eq(
437+
bar:generate(ctx),
438+
table.concat({
439+
"%#bg_0a0b10_fg_c4c6cd_#",
440+
"%1T1%T",
441+
"%#bg_0a0b10_fg_c4c6cd_#",
442+
"%#bg_0a0b10_fg_c4c6cd_b#",
443+
"%2T2%T",
444+
"%#bg_0a0b10_fg_c4c6cd_#",
445+
"%#bg_0a0b10_fg_c4c6cd_#",
446+
"%3T3%T",
447+
"%#bg_0a0b10_fg_c4c6cd_#",
448+
})
449+
)
450+
end)
451+
452+
it(".hl.diagnostic()", function()
453+
t.ref(tablist.number_hl.diagnostic(), tablist.label_hl.diagnostic())
454+
end)
455+
end)
456+
397457
it("diagnostic_count", function()
398458
vim.api.nvim_buf_set_name(tabs[1].bufnr, "_A_")
399459
vim.api.nvim_buf_set_name(add_tab().bufnr, "_B_")

0 commit comments

Comments
 (0)