feat: Themes (#79)
Big shoutout to @rockerBOO for the idea and basically all the impl! * feat: Add dropdown layout strategy * Adding more docs. Working better with options * Refactor borders * Fix for spaces * Add preview to layout. Add Themes. * feat: themes Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
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
|
||||
|
||||
--[[
|
||||
+-----------------+
|
||||
|
||||
29
lua/telescope/themes.lua
Normal file
29
lua/telescope/themes.lua
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user