summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/telescope/pickers.lua8
-rw-r--r--lua/telescope/pickers/layout_strategies.lua92
-rw-r--r--lua/telescope/themes.lua29
3 files changed, 123 insertions, 6 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 4336558..a3fcc57 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -83,6 +83,10 @@ function Picker:new(opts)
return setmetatable({
prompt = opts.prompt,
+
+ results_title = get_default(opts.results_title, "Results"),
+ preview_title = get_default(opts.preview_title, "Preview"),
+
default_text = opts.default_text,
finder = opts.finder,
@@ -139,7 +143,7 @@ function Picker:_get_initial_window_options(prompt_title)
local popup_borderchars = resolve.win_option(self.window.borderchars)
local preview = {
- title = 'Preview',
+ title = self.preview_title,
border = popup_border.preview,
borderchars = popup_borderchars.preview,
enter = false,
@@ -147,7 +151,7 @@ function Picker:_get_initial_window_options(prompt_title)
}
local results = {
- title = 'Results',
+ title = self.results_title,
border = popup_border.results,
borderchars = popup_borderchars.results,
enter = false,
diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua
index b8fe6d1..5f25511 100644
--- a/lua/telescope/pickers/layout_strategies.lua
+++ b/lua/telescope/pickers/layout_strategies.lua
@@ -1,6 +1,32 @@
+--[[
+
+Layout strategies are different functions to position telescope.
+
+horizontal:
+- Supports `prompt_position`, `preview_cutoff`
+
+vertical:
+
+flex: Swap between `horizontal` and `vertical` strategies based on the window width
+- Supports `vertical` or `horizontal` features
+
+dropdown:
-local layout_strategies = {}
+Layout strategies are callback functions
+
+-- @param self: Picker
+-- @param columns: number Columns in the vim window
+-- @param lines: number Lines in the vim window
+-- @param prompt_title: string
+function(self, columns, lines, prompt_title)
+end
+
+--]]
+
+local layout_strategies = {}
+local log = require("telescope.log")
+local resolve = require("telescope.config.resolve")
--[[
+-----------------+---------------------+
| | |
@@ -19,7 +45,6 @@ layout_strategies.horizontal = function(self, max_columns, max_lines, prompt_tit
-- TODO: Test with 120 width terminal
-- TODO: Test with self.width
-
local width_padding = 10
-- TODO: Determine config settings.
@@ -40,6 +65,7 @@ layout_strategies.horizontal = function(self, max_columns, max_lines, prompt_tit
end
local other_width = max_columns - preview.width - (2 * width_padding)
+
results.width = other_width
prompt.width = other_width
@@ -80,11 +106,69 @@ layout_strategies.horizontal = function(self, max_columns, max_lines, prompt_tit
return {
preview = preview.width > 0 and preview,
results = results,
- prompt = prompt,
- }
+ prompt = prompt
+}
+end
+
+--[[
+ +-----------------+
+ | Prompt |
+ +-----------------+
+ | Result |
+ | Result |
+ | Result |
+ +-----------------+
+--]]
+
+-- Check if there are any borders. Right now it's a little raw as
+-- there are a few things that contribute to the border
+local is_borderless = function(opts)
+ if opts.window.border == false then return true end
end
+layout_strategies.center = function(self, columns, lines, prompt_title)
+ local initial_options = self:_get_initial_window_options(prompt_title)
+ local preview = initial_options.preview
+ local results = initial_options.results
+ local prompt = initial_options.prompt
+
+ local max_results = self.max_results or 15
+ local width = self.width or 70
+
+ local max_width = (width > columns and columns or width)
+
+ prompt.height = 1
+ results.height = max_results
+
+ prompt.width = max_width
+ results.width = max_width
+ preview.width = max_width
+ local bs = 1 -- border size
+
+ if is_borderless(self) then bs = 0 end
+
+ prompt.line = (lines / 2) - ((max_results + (bs * 2)) / 2)
+ results.line = prompt.line + prompt.height + (bs * 2)
+
+ preview.line = 1
+ preview.height = math.floor(prompt.line - 2)
+
+ if not self.previewer or columns < self.preview_cutoff then
+ preview.height = 0
+ end
+
+ -- Get left column, after centering, appling the width, and the border size
+ results.col = (columns / 2) - (width / 2) + (bs * 2)
+ prompt.col = results.col
+ preview.col = results.col
+
+ return {
+ preview = self.previewer and preview,
+ results = results,
+ prompt = prompt
+ }
+end
--[[
+-----------------+
diff --git a/lua/telescope/themes.lua b/lua/telescope/themes.lua
new file mode 100644
index 0000000..5146dbb
--- /dev/null
+++ b/lua/telescope/themes.lua
@@ -0,0 +1,29 @@
+-- Prototype Theme System (WIP)
+-- Currently certain designs need a number of parameters.
+--
+-- local opts = themes.get_dropdown { winblend = 3 }
+--
+
+local themes = {}
+
+function themes.get_dropdown(opts)
+ local theme_opts = {
+ -- WIP: Decide on keeping these names or not.
+ theme = "dropdown",
+
+ sorting_strategy = "ascending",
+ layout_strategy = "center",
+ results_title = false,
+ preview_title = "Preview",
+ border = false,
+ borderchars = {
+ prompt = {"─", "│", " ", "│", "╭", "╮", "│", "│"},
+ results = {"─", "│", "─", "│", "├", "┤", "╯", "╰"},
+ preview = {"=", "=", "", "", "", "", "", ""}
+ },
+ }
+
+ return vim.tbl_deep_extend("force", theme_opts, opts)
+end
+
+return themes