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:
@@ -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
|
||||
|
||||
--[[
|
||||
+-----------------+
|
||||
|
||||
Reference in New Issue
Block a user