feat: add icons and colors to telescope picker (#119)
* feat: add icons and colors to telescope picker * feat: add configuration options for telescope icons * fix: remove highlight group for telescope normal selectionmain
parent
ca9900c31e
commit
8fc97b6182
|
|
@ -170,6 +170,11 @@ require("persisted").setup({
|
|||
copy_session = "<c-c>",
|
||||
delete_session = "<c-d>",
|
||||
},
|
||||
icons = { -- icons displayed in the picker, set to nil to disable entirely
|
||||
branch = " ",
|
||||
dir = " ",
|
||||
selected = " ",
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
|
|
|||
|
|
@ -169,6 +169,11 @@ The plugin comes with the following defaults:
|
|||
copy_session = "<c-c>",
|
||||
delete_session = "<c-d>",
|
||||
},
|
||||
icons = { -- icons displayed in the picker, set to nil to disable entirely
|
||||
branch = " ",
|
||||
dir = " ",
|
||||
selected = " ",
|
||||
},
|
||||
},
|
||||
})
|
||||
<
|
||||
|
|
|
|||
|
|
@ -27,13 +27,18 @@ local defaults = {
|
|||
copy_session = "<c-c>",
|
||||
delete_session = "<c-d>",
|
||||
},
|
||||
icons = { -- icons displayed in the picker
|
||||
branch = " ",
|
||||
dir = " ",
|
||||
selected = " ",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
M.options = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {})
|
||||
M.options = vim.tbl_deep_extend("force", defaults, opts or {})
|
||||
vim.fn.mkdir(M.options.save_dir, "p")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -367,11 +367,18 @@ function M.list()
|
|||
dir_path = session_name
|
||||
end
|
||||
|
||||
local f = io.popen("stat -f %a " .. session)
|
||||
local last_modified = ""
|
||||
if f then
|
||||
last_modified = f:read()
|
||||
end
|
||||
|
||||
table.insert(sessions, {
|
||||
["name"] = session_name,
|
||||
["file_path"] = session,
|
||||
["branch"] = branch,
|
||||
["dir_path"] = dir_path,
|
||||
["last_modified"] = last_modified,
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ end
|
|||
|
||||
return require("telescope").register_extension({
|
||||
setup = function(topts)
|
||||
vim.api.nvim_set_hl(0, "TelescopePersistedIsCurrent", { link = "TelescopeResultsOperator" })
|
||||
vim.api.nvim_set_hl(0, "TelescopePersistedDir", { link = "Directory" })
|
||||
vim.api.nvim_set_hl(0, "TelescopePersistedBranch", { link = "TelescopeResultsIdentifier" })
|
||||
telescope_opts = topts
|
||||
end,
|
||||
exports = {
|
||||
|
|
|
|||
|
|
@ -1,36 +1,49 @@
|
|||
local config = require("persisted.config")
|
||||
local finders = require("telescope.finders")
|
||||
local entry_display = require("telescope.pickers.entry_display")
|
||||
|
||||
local M = {}
|
||||
|
||||
local no_icons = {
|
||||
branch = "",
|
||||
dir = "",
|
||||
selected = "",
|
||||
}
|
||||
|
||||
M.session_finder = function(sessions)
|
||||
-- Layout borrowed from:
|
||||
---https://github.com/LinArcX/telescope-env.nvim/blob/master/lua/telescope/_extensions/env.lua
|
||||
local icons = vim.tbl_extend("force", no_icons, config.options.telescope.icons or {})
|
||||
|
||||
local displayer = entry_display.create({
|
||||
items = {
|
||||
{ remaining = true },
|
||||
},
|
||||
})
|
||||
local custom_displayer = function(session)
|
||||
local final_str = ""
|
||||
local hls = {}
|
||||
|
||||
local make_display = function(session)
|
||||
local str
|
||||
local function append(str, hl)
|
||||
local hl_start = #final_str
|
||||
final_str = final_str .. str
|
||||
if hl then
|
||||
table.insert(hls, { { hl_start, #final_str }, hl })
|
||||
end
|
||||
end
|
||||
|
||||
-- is current session
|
||||
append(session.file_path == vim.v.this_session and (icons.selected .. " ") or " ", "TelescopePersistedIsCurrent")
|
||||
|
||||
-- session path
|
||||
append(icons.dir, "TelescopePersistedDir")
|
||||
append(session.dir_path)
|
||||
|
||||
-- branch
|
||||
if session.branch then
|
||||
str = string.format("%s (branch: %s)", session.dir_path, session.branch)
|
||||
else
|
||||
str = session.dir_path
|
||||
append(" " .. icons.branch .. session.branch, "TelescopePersistedBranch")
|
||||
end
|
||||
if session.file_path == vim.v.this_session then
|
||||
str = "* " .. str
|
||||
end
|
||||
return displayer({ str })
|
||||
|
||||
return final_str, hls
|
||||
end
|
||||
|
||||
return finders.new_table({
|
||||
results = sessions,
|
||||
entry_maker = function(session)
|
||||
session.ordinal = session.name
|
||||
session.display = make_display
|
||||
session.display = custom_displayer
|
||||
session.name = session.name
|
||||
session.branch = session.branch
|
||||
session.file_path = session.file_path
|
||||
|
|
|
|||
Loading…
Reference in New Issue