forked from moyiz/git-dev.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnacks.lua
More file actions
85 lines (80 loc) · 2.07 KB
/
Copy pathsnacks.lua
File metadata and controls
85 lines (80 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local config = require("git-dev.pickers").config.history
local picker_utils = require("git-dev.pickers").utils
local pickers = {}
---@param local_opts HistoryLocalOpts
function pickers.history(local_opts)
local snacks = require "snacks"
local widths
return snacks.picker.pick {
source = "git-dev",
title = config.title,
items = config.get_entries(),
confirm = function(picker, item)
if picker then
picker:close()
end
config.select_entry(item)
end,
format = function(item, p)
if not widths then
widths = picker_utils.normalize_width(
vim.fn.winwidth(p.list.win.win), -- should deduct separator width
local_opts.entry.ratios,
{
local_opts.entry.repo_url.width,
local_opts.entry.ref.width,
local_opts.entry.selected_path.width,
}
)
end
local parts = config.label_parts(item)
return {
{
picker_utils.fit_string(
parts[1],
widths[1],
{ align = "left", truncate = "left" }
),
local_opts.entry.repo_url.hl_group,
},
{
local_opts.separator.text or " ",
local_opts.separator.hl_group,
},
{
picker_utils.fit_string(
parts[2],
widths[2],
{ align = "center", truncate = "right" }
),
local_opts.entry.ref.hl_group,
},
{
local_opts.separator.text or " ",
local_opts.separator.hl_group,
},
{
picker_utils.fit_string(
parts[3],
widths[3],
{ align = "left", truncate = "left" }
),
local_opts.entry.selected_path.hl_group,
},
}
end,
transform = function(item)
item.text = config.ordinal(item)
item.preview = {
ft = "lua",
text = vim.inspect {
args = item.args,
parsed = item.parsed,
},
}
return item
end,
preview = "preview",
}
end
return pickers