From 9e603d3c1b947c8f063d81a3c926e216b708928f Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 15 Apr 2021 21:26:38 +0800 Subject: [PATCH] feat: table layout for builtin commands (#754) --- lua/telescope/builtin/internal.lua | 10 ++----- 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 = "~",