summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorLuke Kershaw <35707277+l-kershaw@users.noreply.github.com>2021-10-04 20:16:58 +0100
committerGitHub <noreply@github.com>2021-10-04 21:16:58 +0200
commitbe600b5421c652c84f94c0c75ba6d309165ed0ef (patch)
treee54c30e95a97bd7a1241e2695eb4c66a95347f94 /lua
parente39ed31f17e35d4f42b516d10ed4340fca25eb6a (diff)
feat: more prompt position strategies (#1280)
* feat: allow `prompt_position` for `vertical` layout strategy * feat: allow `prompt_position` for `bottom_pane` layout strategy * stylua * [docgen] Update doc/telescope.txt skip-checks: true * refactor: switch to `string.format` * stylua * feat: allow `prompt_position` for `center` layout strategy * feat: handle user defined `prompt_position` within themes * [docgen] Update doc/telescope.txt skip-checks: true * fix: tweak `center` layout - ensure `prompt` title is visible when `prompt_position="bottom"` * fix: refactor `center` tweak - move title to bottom of picker when `prompt_position="bottom"` * fix: tweak `bottom_pane` layout * stylua Co-authored-by: Github Actions <actions@github>
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/config.lua3
-rw-r--r--lua/telescope/pickers/layout_strategies.lua67
-rw-r--r--lua/telescope/themes.lua20
3 files changed, 73 insertions, 17 deletions
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua
index 8f09c47..6f67c74 100644
--- a/lua/telescope/config.lua
+++ b/lua/telescope/config.lua
@@ -87,6 +87,7 @@ local layout_config_defaults = {
vertical = {
width = 0.8,
height = 0.9,
+ prompt_position = "bottom",
preview_cutoff = 40,
},
@@ -94,6 +95,7 @@ local layout_config_defaults = {
width = 0.8,
height = 0.9,
preview_cutoff = 40,
+ prompt_position = "top",
},
cursor = {
@@ -104,6 +106,7 @@ local layout_config_defaults = {
bottom_pane = {
height = 25,
+ prompt_position = "top",
},
}
diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua
index 4002475..411b7fc 100644
--- a/lua/telescope/pickers/layout_strategies.lua
+++ b/lua/telescope/pickers/layout_strategies.lua
@@ -351,7 +351,7 @@ layout_strategies.horizontal = make_documented_layout(
results.line = preview.line
prompt.line = results.line + results.height + 1 + bs
else
- error("Unknown prompt_position: " .. tostring(self.window.prompt_position) .. "\n" .. vim.inspect(layout_config))
+ error(string.format("Unknown prompt_position: %s\n%s", self.window.prompt_position, vim.inspect(layout_config)))
end
if tbln then
@@ -433,15 +433,26 @@ layout_strategies.center = make_documented_layout(
prompt.height = 1
results.height = height - prompt.height - h_space
+ local topline = (max_lines / 2) - ((results.height + (2 * bs)) / 2) + 1
-- Align the prompt and results so halfway up the screen is
-- in the middle of this combined block
- prompt.line = (max_lines / 2) - ((results.height + (2 * bs)) / 2) + 1
- results.line = prompt.line + 1 + bs
+ if layout_config.prompt_position == "top" then
+ prompt.line = topline
+ results.line = prompt.line + 1 + bs
+ elseif layout_config.prompt_position == "bottom" then
+ results.line = topline
+ prompt.line = results.line + results.height + bs
+ if type(prompt.title) == "string" then
+ prompt.title = { { pos = "S", text = prompt.title } }
+ end
+ else
+ error(string.format("Unknown prompt_position: %s\n%s", self.window.prompt_position, vim.inspect(layout_config)))
+ end
preview.line = 2
if self.previewer and max_lines >= layout_config.preview_cutoff then
- preview.height = math.floor(prompt.line - (3 + bs))
+ preview.height = math.floor(topline - (3 + bs))
else
preview.height = 0
end
@@ -594,7 +605,7 @@ layout_strategies.vertical = make_documented_layout(
vim.tbl_extend("error", shared_options, {
preview_cutoff = "When lines are less than this value, the preview will be disabled",
preview_height = { "Change the height of Telescope's preview window", "See |resolver.resolve_height()|" },
- prompt_position = { "(unimplemented, but we plan on supporting)" },
+ prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}),
function(self, max_columns, max_lines, layout_config)
local initial_options = p_window.get_initial_window_options(self)
@@ -640,13 +651,28 @@ layout_strategies.vertical = make_documented_layout(
local height_padding = math.floor((max_lines - height) / 2)
if not layout_config.mirror then
- preview.line = height_padding + bs + 1
- results.line = (preview.height == 0) and preview.line or preview.line + preview.height + (1 + bs)
- prompt.line = results.line + results.height + (1 + bs)
+ preview.line = height_padding + (1 + bs)
+ if layout_config.prompt_position == "top" then
+ prompt.line = (preview.height == 0) and preview.line or preview.line + preview.height + (1 + bs)
+ results.line = prompt.line + prompt.height + (1 + bs)
+ elseif layout_config.prompt_position == "bottom" then
+ results.line = (preview.height == 0) and preview.line or preview.line + preview.height + (1 + bs)
+ prompt.line = results.line + results.height + (1 + bs)
+ else
+ error(string.format("Unknown prompt_position: %s\n%s", self.window.prompt_position, vim.inspect(layout_config)))
+ end
else
- prompt.line = height_padding + bs + 1
- results.line = prompt.line + prompt.height + (1 + bs)
- preview.line = results.line + results.height + (1 + bs)
+ if layout_config.prompt_position == "top" then
+ prompt.line = height_padding + (1 + bs)
+ results.line = prompt.line + prompt.height + (1 + bs)
+ preview.line = results.line + results.height + (1 + bs)
+ elseif layout_config.prompt_position == "bottom" then
+ results.line = height_padding + (1 + bs)
+ prompt.line = results.line + results.height + (1 + bs)
+ preview.line = prompt.line + prompt.height + (1 + bs)
+ else
+ error(string.format("Unknown prompt_position: %s\n%s", self.window.prompt_position, vim.inspect(layout_config)))
+ end
end
if tbln then
@@ -750,7 +776,7 @@ end)
layout_strategies.bottom_pane = make_documented_layout(
"bottom_pane",
vim.tbl_extend("error", shared_options, {
- -- No custom options...
+ prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}),
function(self, max_columns, max_lines, layout_config)
local initial_options = p_window.get_initial_window_options(self)
@@ -791,9 +817,20 @@ layout_strategies.bottom_pane = make_documented_layout(
end
-- Line
- prompt.line = max_lines - results.height - (1 + bs) + 1
- results.line = prompt.line + 1
- preview.line = results.line + bs
+ if layout_config.prompt_position == "top" then
+ prompt.line = max_lines - results.height - (1 + bs) + 1
+ results.line = prompt.line + 1
+ preview.line = results.line + bs
+ elseif layout_config.prompt_position == "bottom" then
+ results.line = max_lines - results.height - (1 + bs) + 1
+ preview.line = results.line
+ prompt.line = max_lines - bs
+ if type(prompt.title) == "string" then
+ prompt.title = { { pos = "S", text = prompt.title } }
+ end
+ else
+ error("Unknown prompt_position: " .. tostring(self.window.prompt_position) .. "\n" .. vim.inspect(layout_config))
+ end
-- Col
prompt.col = 0 -- centered
diff --git a/lua/telescope/themes.lua b/lua/telescope/themes.lua
index 5b334b1..398a842 100644
--- a/lua/telescope/themes.lua
+++ b/lua/telescope/themes.lua
@@ -52,6 +52,13 @@ function themes.get_dropdown(opts)
preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
},
}
+ if opts.layout_config and opts.layout_config.prompt_position == "bottom" then
+ theme_opts.borderchars = {
+ prompt = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
+ results = { "─", "│", "─", "│", "╭", "╮", "┤", "├" },
+ preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
+ }
+ end
return vim.tbl_deep_extend("force", theme_opts, opts)
end
@@ -99,7 +106,7 @@ end
function themes.get_ivy(opts)
opts = opts or {}
- return vim.tbl_deep_extend("force", {
+ local theme_opts = {
theme = "ivy",
sorting_strategy = "ascending",
@@ -117,7 +124,16 @@ function themes.get_ivy(opts)
results = { " " },
preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
},
- }, opts)
+ }
+ if opts.layout_config and opts.layout_config.prompt_position == "bottom" then
+ theme_opts.borderchars = {
+ prompt = { " ", " ", "─", " ", " ", " ", "─", "─" },
+ results = { "─", " ", " ", " ", "─", "─", " ", " " },
+ preview = { "─", " ", "─", "│", "┬", "─", "─", "╰" },
+ }
+ end
+
+ return vim.tbl_deep_extend("force", theme_opts, opts)
end
return themes