feat: add ivy-style layout strategy (#771)
* feat: add new layout strategy * [docgen] Update doc/telescope.txt skip-checks: true Co-authored-by: Github Actions <actions@github>
This commit is contained in:
@@ -91,6 +91,37 @@ telescope.extensions() *telescope.extensions()*
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
*telescope.themes*
|
||||||
|
|
||||||
|
Themes are ways to combine several elements of styling together.
|
||||||
|
|
||||||
|
They are helpful for managing the several differnt UI aspects for telescope and
|
||||||
|
provide a simple interface for users to get a particular "style" of picker.
|
||||||
|
|
||||||
|
themes.get_dropdown() *themes.get_dropdown()*
|
||||||
|
Dropdown style theme.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
`local builtin = require('telescope.builtin')`
|
||||||
|
`local themes = require('telescope.themes')`
|
||||||
|
`builtin.find_files(themes.get_dropdown())`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
themes.get_ivy() *themes.get_ivy()*
|
||||||
|
Ivy style theme.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
`local builtin = require('telescope.builtin')`
|
||||||
|
`local themes = require('telescope.themes')`
|
||||||
|
`builtin.find_files(themes.get_ivy())`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
*telescope.actions.set*
|
*telescope.actions.set*
|
||||||
|
|
||||||
|
|||||||
@@ -61,38 +61,7 @@
|
|||||||
local config = require('telescope.config')
|
local config = require('telescope.config')
|
||||||
local resolve = require("telescope.config.resolve")
|
local resolve = require("telescope.config.resolve")
|
||||||
|
|
||||||
local function get_initial_window_options(picker)
|
local p_window = require('telescope.pickers.window')
|
||||||
local popup_border = resolve.win_option(picker.window.border)
|
|
||||||
local popup_borderchars = resolve.win_option(picker.window.borderchars)
|
|
||||||
|
|
||||||
local preview = {
|
|
||||||
title = picker.preview_title,
|
|
||||||
border = popup_border.preview,
|
|
||||||
borderchars = popup_borderchars.preview,
|
|
||||||
enter = false,
|
|
||||||
highlight = false
|
|
||||||
}
|
|
||||||
|
|
||||||
local results = {
|
|
||||||
title = picker.results_title,
|
|
||||||
border = popup_border.results,
|
|
||||||
borderchars = popup_borderchars.results,
|
|
||||||
enter = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
local prompt = {
|
|
||||||
title = picker.prompt_title,
|
|
||||||
border = popup_border.prompt,
|
|
||||||
borderchars = popup_borderchars.prompt,
|
|
||||||
enter = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
preview = preview,
|
|
||||||
results = results,
|
|
||||||
prompt = prompt,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Check if there are any borders. Right now it's a little raw as
|
-- Check if there are any borders. Right now it's a little raw as
|
||||||
@@ -139,7 +108,7 @@ layout_strategies.horizontal = function(self, max_columns, max_lines)
|
|||||||
scroll_speed = "The speed when scrolling through the previewer",
|
scroll_speed = "The speed when scrolling through the previewer",
|
||||||
})
|
})
|
||||||
|
|
||||||
local initial_options = get_initial_window_options(self)
|
local initial_options = p_window.get_initial_window_options(self)
|
||||||
local preview = initial_options.preview
|
local preview = initial_options.preview
|
||||||
local results = initial_options.results
|
local results = initial_options.results
|
||||||
local prompt = initial_options.prompt
|
local prompt = initial_options.prompt
|
||||||
@@ -237,7 +206,7 @@ end
|
|||||||
--- +--------------+
|
--- +--------------+
|
||||||
--- </pre>
|
--- </pre>
|
||||||
layout_strategies.center = function(self, columns, lines)
|
layout_strategies.center = function(self, columns, lines)
|
||||||
local initial_options = get_initial_window_options(self)
|
local initial_options = p_window.get_initial_window_options(self)
|
||||||
local preview = initial_options.preview
|
local preview = initial_options.preview
|
||||||
local results = initial_options.results
|
local results = initial_options.results
|
||||||
local prompt = initial_options.prompt
|
local prompt = initial_options.prompt
|
||||||
@@ -307,7 +276,7 @@ layout_strategies.vertical = function(self, max_columns, max_lines)
|
|||||||
scroll_speed = "The speed when scrolling through the previewer",
|
scroll_speed = "The speed when scrolling through the previewer",
|
||||||
})
|
})
|
||||||
|
|
||||||
local initial_options = get_initial_window_options(self)
|
local initial_options = p_window.get_initial_window_options(self)
|
||||||
local preview = initial_options.preview
|
local preview = initial_options.preview
|
||||||
local results = initial_options.results
|
local results = initial_options.results
|
||||||
local prompt = initial_options.prompt
|
local prompt = initial_options.prompt
|
||||||
@@ -447,4 +416,67 @@ layout_strategies.current_buffer = function(self, _, _)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
layout_strategies.bottom_pane = function(self, max_columns, max_lines)
|
||||||
|
local layout_config = validate_layout_config(self.layout_config or {}, {
|
||||||
|
height = "The height of the layout",
|
||||||
|
})
|
||||||
|
|
||||||
|
local initial_options = p_window.get_initial_window_options(self)
|
||||||
|
local results = initial_options.results
|
||||||
|
local prompt = initial_options.prompt
|
||||||
|
local preview = initial_options.preview
|
||||||
|
|
||||||
|
local result_height = layout_config.height or 25
|
||||||
|
|
||||||
|
local prompt_width = max_columns
|
||||||
|
local col = 0
|
||||||
|
|
||||||
|
local has_border = not not self.window.border
|
||||||
|
if has_border then
|
||||||
|
col = 1
|
||||||
|
prompt_width = prompt_width - 2
|
||||||
|
end
|
||||||
|
|
||||||
|
local result_width
|
||||||
|
if self.previewer then
|
||||||
|
result_width = math.floor(prompt_width / 2)
|
||||||
|
|
||||||
|
local base_col = result_width + 1
|
||||||
|
if has_border then
|
||||||
|
preview = vim.tbl_deep_extend("force", {
|
||||||
|
col = base_col + 2,
|
||||||
|
line = max_lines - result_height + 1,
|
||||||
|
width = prompt_width - result_width - 2,
|
||||||
|
height = result_height - 1,
|
||||||
|
}, preview)
|
||||||
|
else
|
||||||
|
preview = vim.tbl_deep_extend("force", {
|
||||||
|
col = base_col,
|
||||||
|
line = max_lines - result_height,
|
||||||
|
width = prompt_width - result_width,
|
||||||
|
height = result_height,
|
||||||
|
}, preview)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
preview = nil
|
||||||
|
result_width = prompt_width
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
preview = preview,
|
||||||
|
prompt = vim.tbl_deep_extend("force", prompt, {
|
||||||
|
line = max_lines - result_height - 1,
|
||||||
|
col = col,
|
||||||
|
height = 1,
|
||||||
|
width = prompt_width,
|
||||||
|
}),
|
||||||
|
results = vim.tbl_deep_extend("force", results, {
|
||||||
|
line = max_lines - result_height,
|
||||||
|
col = col,
|
||||||
|
height = result_height,
|
||||||
|
width = result_width,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
return layout_strategies
|
return layout_strategies
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
local p_layouts = require('telescope.pickers.layout_strategies')
|
local resolve = require("telescope.config.resolve")
|
||||||
|
|
||||||
local p_window = {}
|
local p_window = {}
|
||||||
|
|
||||||
function p_window.get_window_options(picker, max_columns, max_lines)
|
function p_window.get_window_options(picker, max_columns, max_lines)
|
||||||
local layout_strategy = picker.layout_strategy
|
local layout_strategy = picker.layout_strategy
|
||||||
local getter = p_layouts[layout_strategy]
|
local getter = require('telescope.pickers.layout_strategies')[layout_strategy]
|
||||||
|
|
||||||
if not getter then
|
if not getter then
|
||||||
error("Not a valid layout strategy: " .. layout_strategy)
|
error("Not a valid layout strategy: " .. layout_strategy)
|
||||||
@@ -13,5 +13,38 @@ function p_window.get_window_options(picker, max_columns, max_lines)
|
|||||||
return getter(picker, max_columns, max_lines)
|
return getter(picker, max_columns, max_lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function p_window.get_initial_window_options(picker)
|
||||||
|
local popup_border = resolve.win_option(picker.window.border)
|
||||||
|
local popup_borderchars = resolve.win_option(picker.window.borderchars)
|
||||||
|
|
||||||
|
local preview = {
|
||||||
|
title = picker.preview_title,
|
||||||
|
border = popup_border.preview,
|
||||||
|
borderchars = popup_borderchars.preview,
|
||||||
|
enter = false,
|
||||||
|
highlight = false
|
||||||
|
}
|
||||||
|
|
||||||
|
local results = {
|
||||||
|
title = picker.results_title,
|
||||||
|
border = popup_border.results,
|
||||||
|
borderchars = popup_borderchars.results,
|
||||||
|
enter = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
local prompt = {
|
||||||
|
title = picker.prompt_title,
|
||||||
|
border = popup_border.prompt,
|
||||||
|
borderchars = popup_borderchars.prompt,
|
||||||
|
enter = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
preview = preview,
|
||||||
|
results = results,
|
||||||
|
prompt = prompt,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return p_window
|
return p_window
|
||||||
|
|||||||
@@ -2,10 +2,27 @@
|
|||||||
-- Currently certain designs need a number of parameters.
|
-- Currently certain designs need a number of parameters.
|
||||||
--
|
--
|
||||||
-- local opts = themes.get_dropdown { winblend = 3 }
|
-- local opts = themes.get_dropdown { winblend = 3 }
|
||||||
--
|
|
||||||
|
---@tag telescope.themes
|
||||||
|
|
||||||
|
---@brief [[
|
||||||
|
--- Themes are ways to combine several elements of styling together.
|
||||||
|
---
|
||||||
|
--- They are helpful for managing the several differnt UI aspects for telescope and provide
|
||||||
|
--- a simple interface for users to get a particular "style" of picker.
|
||||||
|
---@brief ]]
|
||||||
|
|
||||||
local themes = {}
|
local themes = {}
|
||||||
|
|
||||||
|
--- Dropdown style theme.
|
||||||
|
--- <pre>
|
||||||
|
---
|
||||||
|
--- Usage:
|
||||||
|
---
|
||||||
|
--- `local builtin = require('telescope.builtin')`
|
||||||
|
--- `local themes = require('telescope.themes')`
|
||||||
|
--- `builtin.find_files(themes.get_dropdown())`
|
||||||
|
--- </pre>
|
||||||
function themes.get_dropdown(opts)
|
function themes.get_dropdown(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
@@ -21,14 +38,49 @@ function themes.get_dropdown(opts)
|
|||||||
width = 80,
|
width = 80,
|
||||||
results_height = 15,
|
results_height = 15,
|
||||||
borderchars = {
|
borderchars = {
|
||||||
{ '─', '│', '─', '│', '╭', '╮', '╯', '╰'},
|
{ "─", "│", "─", "│", "╭", "╮", "╯", "╰"},
|
||||||
prompt = {"─", "│", " ", "│", "╭", "╮", "│", "│"},
|
prompt = {"─", "│", " ", "│", "╭", "╮", "│", "│"},
|
||||||
results = {"─", "│", "─", "│", "├", "┤", "╯", "╰"},
|
results = {"─", "│", "─", "│", "├", "┤", "╯", "╰"},
|
||||||
preview = { '─', '│', '─', '│', '╭', '╮', '╯', '╰'},
|
preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return vim.tbl_deep_extend("force", theme_opts, opts)
|
return vim.tbl_deep_extend("force", theme_opts, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Ivy style theme.
|
||||||
|
--- <pre>
|
||||||
|
---
|
||||||
|
--- Usage:
|
||||||
|
---
|
||||||
|
--- `local builtin = require('telescope.builtin')`
|
||||||
|
--- `local themes = require('telescope.themes')`
|
||||||
|
--- `builtin.find_files(themes.get_ivy())`
|
||||||
|
--- </pre>
|
||||||
|
function themes.get_ivy(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
|
||||||
|
return vim.tbl_deep_extend("force", {
|
||||||
|
theme = "ivy",
|
||||||
|
|
||||||
|
sorting_strategy = "ascending",
|
||||||
|
|
||||||
|
preview_title = "",
|
||||||
|
|
||||||
|
layout_strategy = "bottom_pane",
|
||||||
|
layout_config = {
|
||||||
|
height = 25,
|
||||||
|
},
|
||||||
|
|
||||||
|
border = true,
|
||||||
|
borderchars = {
|
||||||
|
"z",
|
||||||
|
prompt = { "─", " ", " ", " ", "─", "─", " ", " " },
|
||||||
|
results = { " " },
|
||||||
|
-- results = { "a", "b", "c", "d", "e", "f", "g", "h" },
|
||||||
|
preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰"},
|
||||||
|
},
|
||||||
|
}, opts)
|
||||||
|
end
|
||||||
|
|
||||||
return themes
|
return themes
|
||||||
|
|||||||
31
scratch/ivy.lua
Normal file
31
scratch/ivy.lua
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
RELOAD('telescope')
|
||||||
|
require('telescope.builtin').find_files(require('telescope.themes').get_ivy { previewer = false })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ docs.test = function()
|
|||||||
"./lua/telescope/actions/state.lua",
|
"./lua/telescope/actions/state.lua",
|
||||||
"./lua/telescope/actions/set.lua",
|
"./lua/telescope/actions/set.lua",
|
||||||
"./lua/telescope/previewers/init.lua",
|
"./lua/telescope/previewers/init.lua",
|
||||||
|
"./lua/telescope/themes.lua",
|
||||||
}
|
}
|
||||||
|
|
||||||
table.sort(input_files, function(a, b)
|
table.sort(input_files, function(a, b)
|
||||||
|
|||||||
Reference in New Issue
Block a user