diff options
| author | Weihang Lo <weihanglo@users.noreply.github.com> | 2021-04-15 21:26:38 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-15 09:26:38 -0400 |
| commit | 9e603d3c1b947c8f063d81a3c926e216b708928f (patch) | |
| tree | be557f52e77e2443a6eb261166f0bfb445d3b208 /lua | |
| parent | 2e7ee55aa44306dc5a6a47946559d10d4fe360db (diff) | |
feat: table layout for builtin commands (#754)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/telescope/builtin/internal.lua | 10 | ||||
| -rw-r--r-- | lua/telescope/make_entry.lua | 42 |
2 files changed, 44 insertions, 8 deletions
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 7eefcb2..cab145d 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -159,14 +159,8 @@ internal.commands = function(opts) return commands end)(), - entry_maker = function(line) - return { - valid = line ~= "", - value = line, - ordinal = line.name, - display = line.name - } - end + + entry_maker = opts.entry_maker or make_entry.gen_from_commands(opts), }, sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index b9635bb..02d9ca1 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -1019,6 +1019,48 @@ function make_entry.gen_from_autocommands(_) end end +function make_entry.gen_from_commands(_) + local displayer = entry_display.create { + separator = "▏", + items = { + { width = 25 }, + { width = 4 }, + { width = 4 }, + { width = 11 }, + { remaining = true }, + }, + } + + local make_display = function(entry) + local attrs = "" + if entry.bang then attrs = attrs .. "!" end + if entry.bar then attrs = attrs .. "|" end + if entry.register then attrs = attrs .. '"' end + return displayer { + {entry.name, "TelescopeResultsIdentifier"}, + attrs, + entry.nargs, + entry.complete or "", + entry.definition, + } + end + + return function(entry) + return { + name = entry.name, + bang = entry.bang, + nargs = entry.nargs, + complete = entry.complete, + definition = entry.definition, + -- + value = entry, + valid = true, + ordinal = entry.name, + display = make_display, + } + end +end + local git_icon_defaults = { added = "+", changed = "~", |
