feat: extend functionality of entry_display.create (#1408)
* feat: extend functionality of `entry_display.create` - now allows passing functions or fractional values to `width` option * refactor: cache `width` instead of results window size * feat: use new `width` functionality for more entry makers
This commit is contained in:
@@ -290,7 +290,7 @@ function make_entry.gen_from_quickfix(opts)
|
|||||||
separator = "▏",
|
separator = "▏",
|
||||||
items = {
|
items = {
|
||||||
{ width = 8 },
|
{ width = 8 },
|
||||||
{ width = 50 },
|
{ width = 0.45 },
|
||||||
{ remaining = true },
|
{ remaining = true },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -666,9 +666,9 @@ end
|
|||||||
|
|
||||||
function make_entry.gen_from_picker(opts)
|
function make_entry.gen_from_picker(opts)
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
separator = " ",
|
separator = " │ ",
|
||||||
items = {
|
items = {
|
||||||
{ width = 30 },
|
{ width = 0.5 },
|
||||||
{ remaining = true },
|
{ remaining = true },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -957,17 +957,17 @@ function make_entry.gen_from_lsp_diagnostics(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local layout = {
|
local display_items = {
|
||||||
{ width = utils.if_nil(signs, 8, 10) },
|
{ width = utils.if_nil(signs, 8, 10) },
|
||||||
{ remaining = true },
|
{ remaining = true },
|
||||||
}
|
}
|
||||||
local line_width = utils.get_default(opts.line_width, 45)
|
local line_width = utils.get_default(opts.line_width, 0.5)
|
||||||
if not utils.is_path_hidden(opts) then
|
if not utils.is_path_hidden(opts) then
|
||||||
table.insert(layout, 2, { width = line_width })
|
table.insert(display_items, 2, { width = line_width })
|
||||||
end
|
end
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
separator = "▏",
|
separator = "▏",
|
||||||
items = layout,
|
items = display_items,
|
||||||
}
|
}
|
||||||
|
|
||||||
local make_display = function(entry)
|
local make_display = function(entry)
|
||||||
@@ -1049,7 +1049,7 @@ function make_entry.gen_from_commands(_)
|
|||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
separator = "▏",
|
separator = "▏",
|
||||||
items = {
|
items = {
|
||||||
{ width = 25 },
|
{ width = 0.2 },
|
||||||
{ width = 4 },
|
{ width = 4 },
|
||||||
{ width = 4 },
|
{ width = 4 },
|
||||||
{ width = 11 },
|
{ width = 11 },
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
local strings = require "plenary.strings"
|
local strings = require "plenary.strings"
|
||||||
|
local state = require "telescope.state"
|
||||||
|
local resolve = require "telescope.config.resolve"
|
||||||
|
|
||||||
local entry_display = {}
|
local entry_display = {}
|
||||||
entry_display.truncate = strings.truncate
|
entry_display.truncate = strings.truncate
|
||||||
@@ -8,11 +10,19 @@ entry_display.create = function(configuration)
|
|||||||
for _, v in ipairs(configuration.items) do
|
for _, v in ipairs(configuration.items) do
|
||||||
if v.width then
|
if v.width then
|
||||||
local justify = v.right_justify
|
local justify = v.right_justify
|
||||||
|
local width
|
||||||
table.insert(generator, function(item)
|
table.insert(generator, function(item)
|
||||||
|
if width == nil then
|
||||||
|
local status = state.get_status(vim.api.nvim_get_current_buf())
|
||||||
|
local s = {}
|
||||||
|
s[1] = vim.api.nvim_win_get_width(status.results_win) - #status.picker.selection_caret
|
||||||
|
s[2] = vim.api.nvim_win_get_height(status.results_win)
|
||||||
|
width = resolve.resolve_width(v.width)(nil, s[1], s[2])
|
||||||
|
end
|
||||||
if type(item) == "table" then
|
if type(item) == "table" then
|
||||||
return strings.align_str(entry_display.truncate(item[1], v.width), v.width, justify), item[2]
|
return strings.align_str(entry_display.truncate(item[1], width), width, justify), item[2]
|
||||||
else
|
else
|
||||||
return strings.align_str(entry_display.truncate(item, v.width), v.width, justify)
|
return strings.align_str(entry_display.truncate(item, width), width, justify)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user