feat: add icons to git_status finder (#401)

* add icons to git_status finder

* fix lint warning

* fix incorrect removed icon

* refactor, more states/icons

* refactor, widen columns to allow for 3char width icons

* attempted col width fix

* fixup: small comments

Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
This commit is contained in:
Senghan Bright
2021-04-09 19:33:10 +02:00
committed by GitHub
parent ba1e674e68
commit 5bd6f5ca98
3 changed files with 36 additions and 48 deletions

View File

@@ -1019,28 +1019,51 @@ function make_entry.gen_from_autocommands(_)
end end
end end
local git_icon_defaults = {
added = "+",
changed = "~",
copied = ">",
deleted = "-",
renamed = "",
unmerged = "",
untracked = "?"
}
function make_entry.gen_from_git_status(opts) function make_entry.gen_from_git_status(opts)
opts = opts or {}
local col_width = ((opts.git_icons and opts.git_icons.added) and opts.git_icons.added:len() + 2) or 2
local displayer = entry_display.create { local displayer = entry_display.create {
separator = " ", separator = "",
items = { items = {
{ width = 1 }, { width = col_width},
{ width = 1 }, { width = col_width},
{ remaining = true }, { remaining = true },
} }
} }
local icons = vim.tbl_extend("keep", opts.git_icons or {}, git_icon_defaults)
local git_abbrev = {
["A"] = {icon = icons.added, hl = "TelescopeResultsDiffAdd"},
["U"] = {icon = icons.unmerged, hl = "TelescopeResultsDiffAdd"},
["M"] = {icon = icons.changed, hl = "TelescopeResultsDiffChange"},
["C"] = {icon = icons.copied, hl = "TelescopeResultsDiffChange"},
["R"] = {icon = icons.renamed, hl = "TelescopeResultsDiffChange"},
["D"] = {icon = icons.deleted, hl = "TelescopeResultsDiffDelete"},
["?"] = {icon = icons.untracked, hl = "TelescopeResultsDiffUntracked"},
}
local make_display = function(entry) local make_display = function(entry)
local modified = "TelescopeResultsDiffChange" local x = string.sub(entry.status, 1, 1)
local staged = "TelescopeResultsDiffAdd" local y = string.sub(entry.status, -1)
local status_x = git_abbrev[x] or {}
if entry.status == "??" then local status_y = git_abbrev[y] or {}
modified = "TelescopeResultsDiffDelete"
staged = "TelescopeResultsDiffDelete"
end
local empty_space = (" ")
return displayer { return displayer {
{ string.sub(entry.status, 1, 1), staged }, { status_x.icon or empty_space, status_x.hl},
{ string.sub(entry.status, -1), modified }, { status_y.icon or empty_space, status_y.hl},
entry.value, entry.value,
} }
end end

View File

@@ -69,6 +69,7 @@ highlight default link TelescopeResultsSpecialComment SpecialComment
highlight default link TelescopeResultsDiffChange DiffChange highlight default link TelescopeResultsDiffChange DiffChange
highlight default link TelescopeResultsDiffAdd DiffAdd highlight default link TelescopeResultsDiffAdd DiffAdd
highlight default link TelescopeResultsDiffDelete DiffDelete highlight default link TelescopeResultsDiffDelete DiffDelete
highlight default link TelescopeResultsDiffUntracked NonText
" This is like "<C-R>" in your terminal. " This is like "<C-R>" in your terminal.
" To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch) " To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)

View File

@@ -1,36 +0,0 @@
-- Until I have better profiling stuff, this will have to do.
PERF = function(...) end
PERF_DEBUG = PERF_DEBUG or nil
START = nil
if PERF_DEBUG then
PERF = function(...)
local new_time = (vim.loop.hrtime() - START) / 1E9
if select('#', ...) == 0 then
vim.schedule(function()
vim.api.nvim_buf_set_lines(PERF_DEBUG, -1, -1, false, { '' })
end)
return
end
local to_insert = ''
if START then
to_insert = tostring(new_time) .. ' | '
end
for _, v in ipairs({...}) do
if type(v) == 'table' then
to_insert = to_insert .. tostring(#v) .. ' | '
else
to_insert = to_insert .. tostring(v) .. ' | '
end
end
vim.schedule(function()
vim.api.nvim_buf_set_lines(PERF_DEBUG, -1, -1, false, { to_insert })
end)
end
end