Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update display config methods #823

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
fa38539
First attempt: add hierarchy and {padding=...} option
l-kershaw May 7, 2021
757fdc2
Update layout strategies to use new method
l-kershaw May 7, 2021
289b894
Update the validate layout_config function for hierarchy
l-kershaw May 7, 2021
b82c743
validate_layout_config: only check the given strategy
l-kershaw May 7, 2021
f558a53
Switch to included version of deepcopy
l-kershaw May 8, 2021
fc485ce
[docgen] Update doc/telescope.txt
May 8, 2021
f6722c1
Add layout_defaults
l-kershaw May 8, 2021
eec0a4d
Merge branch 'display_config' of https://github.com/l-kershaw/telesco…
l-kershaw May 8, 2021
e5a4364
Improve layout diagrams
l-kershaw May 8, 2021
d762448
[docgen] Update doc/telescope.txt
May 8, 2021
e4c797f
Add documentation for size resolver functions
l-kershaw May 8, 2021
0f3c9ee
[docgen] Update doc/telescope.txt
May 8, 2021
9d4fab8
Add resolver functions file to docgen
l-kershaw May 8, 2021
bd40df7
[docgen] Update doc/telescope.txt
May 8, 2021
911003c
Correct links to resolver functions
l-kershaw May 8, 2021
5d29e35
[docgen] Update doc/telescope.txt
May 8, 2021
245be0a
Remove get_width_opt, now handled by validate_layout_config
l-kershaw May 12, 2021
e710e46
Add documentation for defaults affecting layout
l-kershaw May 13, 2021
3256829
[docgen] Update doc/telescope.txt
May 13, 2021
f46d9b2
Rename `layout_defaults` to `layout_config`
l-kershaw May 14, 2021
c651f21
[docgen] Update doc/telescope.txt
May 14, 2021
e269210
Changes suggested by tjdevries
l-kershaw May 16, 2021
a8a97f6
Merge branch 'master' into display_config
l-kershaw May 16, 2021
7ba80ce
Fix typo
l-kershaw May 16, 2021
5b2fdef
Add resolving to `bottom_pane` strategy
l-kershaw May 16, 2021
bec87e3
Improve documentation for `resolve_height` and `resolve_width`
l-kershaw May 16, 2021
87ffc50
Small changes to documentation
l-kershaw May 16, 2021
eddc27b
Attempt to add functionality from PR #773
l-kershaw May 16, 2021
97dd75e
[docgen] Update doc/telescope.txt
May 16, 2021
c9da4d2
Message instead of error when using 'layout_default'
l-kershaw May 17, 2021
2c1d42f
Allow layout_config keys if they are valid for any layout_strategy
l-kershaw May 17, 2021
cc2c8b5
Merge branch 'display_config' of https://github.com/l-kershaw/telesco…
l-kershaw May 17, 2021
ee7e175
[docgen] Update doc/telescope.txt
May 17, 2021
5c45e79
feat: much code
tjdevries May 19, 2021
0cace86
Add layout function descriptions + some small changes
l-kershaw May 19, 2021
450d150
Refactor setting options using `config.set_defaults`
l-kershaw May 20, 2021
6ca31e2
Linting
l-kershaw May 20, 2021
33ce376
First attempt at `layout_default` inheritance tests
l-kershaw May 20, 2021
743601c
Second attempt at `layout_default` inheritance tests
l-kershaw May 20, 2021
904b8eb
Add more `layout_config` inheritance tests
l-kershaw May 21, 2021
557485e
Implements a smarter table extend for `layout_config`
l-kershaw May 24, 2021
9699e68
wip: preview_cutoff and prompt_position
tjdevries May 31, 2021
87b67d3
[WIP]: Wed 09 Jun 2021 08:48:06 AM EDT
tjdevries Jun 9, 2021
617d62e
working on docs and clarifications
tjdevries Jun 9, 2021
28f3b27
[docgen] Update doc/telescope.txt
Jun 9, 2021
3a1ce1f
Resolve `preview_cutoff` (first attempt)
l-kershaw Jun 9, 2021
172bd53
[docgen] Update doc/telescope.txt
Jun 9, 2021
b037cb1
Linting
l-kershaw Jun 9, 2021
dba65d3
Revert "Resolve `preview_cutoff` (first attempt)"
l-kershaw Jun 10, 2021
337c997
Revert "[docgen] Update doc/telescope.txt"
l-kershaw Jun 10, 2021
4935eae
Switch `preview_cutoff` to check lines for `center` and `vertical` st…
l-kershaw Jun 10, 2021
9863e71
[docgen] Update doc/telescope.txt
Jun 10, 2021
8a0d26b
Reduce duplicated layout info in readme
l-kershaw Jun 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ require('telescope').setup{
selection_strategy = "reset",
sorting_strategy = "descending",
layout_strategy = "horizontal",
layout_defaults = {
layout_config = {
l-kershaw marked this conversation as resolved.
Show resolved Hide resolved
horizontal = {
mirror = false,
},
Expand Down Expand Up @@ -204,7 +204,7 @@ EOF
| `sorting_strategy` | Where first selection should be located. | descending/ascending |
| `layout_strategy` | How the telescope is drawn. | [supported layouts](https://github.com/nvim-telescope/telescope.nvim/wiki/Layouts) |
| `winblend` | How transparent is the telescope window should be. | NUM |
| `layout_defaults` | Extra settings for fine-tuning how your layout looks | [supported settings](https://github.com/nvim-telescope/telescope.nvim/wiki/Layouts#layout-defaults) |
| `layout_config` | Extra settings for fine-tuning how your layout looks | [supported settings](https://github.com/nvim-telescope/telescope.nvim/wiki/Layouts#layout-defaults) |
| `width` | TODO | NUM |
| `preview_cutoff` | TODO | NUM |
| `results_height` | TODO | NUM |
Expand Down
177 changes: 139 additions & 38 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,40 @@ telescope.setup({opts}) *telescope.setup()*

Default: ' '

*telescope.defaults.layout_config*
layout_config: ~
Determines the default configuration values for layout strategies.
See |telescope.layout| for details of the configurations options for
each strategy.

Allows setting defaults for all strategies as top level options and
for overriding for specific options.
For example, the default values below set the default width to 80% of
the screen width for all strategies except 'center', which has width
of 50% of the screen width.

Default:
{
width = 0.8,
horizontal = {
height = 0.9,
},
vertical = {
height = 0.9,
},
center = {
width = 0.5
}
}


*telescope.defaults.layout_strategy*
layout_strategy: ~
Determines the default layout of Telescope pickers.
See |telescope.layout| for details of the available strategies.

Default: 'horizontal'

*telescope.defaults.prompt_prefix*
prompt_prefix: ~
Will be shown in front of the prompt.
Expand Down Expand Up @@ -304,6 +338,46 @@ action_state.get_current_picker({prompt_bufnr})*action_state.get_current_picker(



================================================================================
*telescope.resolve*

Provides "resolver functions" to allow more customisable inputs for options.

resolver.resolve_height() *resolver.resolve_height()*
Converts input to a function that returns the height. The input must take
one of four forms:
1. 0 <= number < 1 This means total height as a percentage.
2. 1 <= number This means total height as a fixed number.
3. function Must have signature: function(self, max_columns, max_lines):
number
4. table of the form: {padding = `foo`} where `foo` has one of the previous
three forms. The height is then set to be the remaining space after
padding. The returned function will have signature: function(self,
max_columns, max_lines): number



resolver.resolve_width() *resolver.resolve_width()*
Converts input to a function that returns the width. The input must take
one of four forms:
1. 0 <= number < 1 This means total width as a percentage.
2. 1 <= number This means total width as a fixed number.
3. function Must have signature: function(self, max_columns, max_lines):
number
4. table of the form: {padding = `foo`} where `foo` has one of the previous
three forms. The height is then set to be the remaining space after
padding. The returned function will have signature: function(self,
max_columns, max_lines): number



resolver.win_option() *resolver.win_option()*
Win option always returns a table with preview, results, and prompt. It
handles many different ways. Some examples are as follows:




================================================================================
*telescope.previewers*

Expand Down Expand Up @@ -616,11 +690,13 @@ horizontal and vertical layouts):
- If using vertical: if `true`, swaps the location of the results and
prompt windows

- width_padding:
- How many cells to pad the width of Telescope's layout window
- width:
- How wide to make Telescope's layout window
- Resolvable: see |resolver.resolve_width()|

- height_padding:
- How many cells to pad the height of Telescope's layout window
- height:
- How tall to make Telescope's layout window
- Resolvable: see |resolver.resolve_height()|

- preview_width:
- Change the width of Telescope's preview window
Expand All @@ -629,48 +705,73 @@ horizontal and vertical layouts):
- Change the scrolling speed of the previewer

layout_strategies.horizontal() *layout_strategies.horizontal()*
Horizontal previewer

+-------------+--------------+
| | |
| Results | |
| | Preview |
| | |
+-------------| |
| Prompt | |
+-------------+--------------+
Horizontal previewer has two columns, one for the preview and one for the
prompt and results.

┌──────────────────────────────────────────────────┐
│ │
│ ┌───────────────────┐┌───────────────────┐ │
│ │ ││ │ │
│ │ ││ │ │
│ │ ││ │ │
│ │ Results ││ │ │
│ │ ││ Preview │ │
│ │ ││ │ │
│ │ ││ │ │
│ └───────────────────┘│ │ │
│ ┌───────────────────┐│ │ │
│ │ Prompt ││ │ │
│ └───────────────────┘└───────────────────┘ │
│ │
└──────────────────────────────────────────────────┘



layout_strategies.center() *layout_strategies.center()*
Centered layout wih smaller default sizes (I think)

+--------------+
| Preview |
+--------------+
| Prompt |
+--------------+
| Result |
| Result |
| Result |
+--------------+
Centered layout with a combined block of the prompt and results aligned to
the middle of the screen. The preview window is then placed in the
remaining space above. Particularly useful for creating dropdown menus (try
using `theme=get_dropdown`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to consider linking to a part of the documentation that talks about using a theme here, as I think there is generally some confusion on how to use a theme for new users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added links here but docgen doesn't seem to be working for me right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, I missed that in my review. That's a bit odd why it's not picking them up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't miss them, I added them after your review

Yeh, not sure why it's not updating


┌──────────────────────────────────────────────────┐
│ ┌────────────────────────────────────────┐ │
│ | Preview | │
│ | Preview | │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
│ | Prompt | │
│ ├────────────────────────────────────────┤ │
│ | Result | │
│ | Result | │
│ └────────────────────────────────────────┘ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────┘



layout_strategies.vertical() *layout_strategies.vertical()*
Vertical perviewer stacks the items on top of each other.

+-----------------+
| Previewer |
| Previewer |
| Previewer |
+-----------------+
| Result |
| Result |
| Result |
+-----------------+
| Prompt |
+-----------------+
Vertical previewer stacks the items on top of each other. Particularly
useful with thinner windows.

┌──────────────────────────────────────────────────┐
│ │
│ ┌────────────────────────────────────────┐ │
│ | Preview | │
│ | Preview | │
│ | Preview | │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
│ | Result | │
│ | Result | │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
│ | Prompt | │
│ └────────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────┘



Expand Down
49 changes: 44 additions & 5 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,54 @@ function config.set_defaults(defaults)
- "cycle" (default)
- "limit"]])

set("layout_strategy", "horizontal")
set("layout_defaults", {})

set("width", 0.75)
set("layout_strategy", "horizontal", [[
Determines the default layout of Telescope pickers.
See |telescope.layout| for details of the available strategies.

Default: 'horizontal']])
set("layout_config", {
width = 0.8,
horizontal = {
height = 0.9,
},
vertical = {
height = 0.9,
},
center = {
width = 0.5
}
},[[
Determines the default configuration values for layout strategies.
See |telescope.layout| for details of the configurations options for
each strategy.

Allows setting defaults for all strategies as top level options and
for overriding for specific options.
For example, the default values below set the default width to 80% of
the screen width for all strategies except 'center', which has width
of 50% of the screen width.

Default:
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can we get this generated from the value above?

like layou_config_default = { ... } , and then use vim.inspect so that it doesn't get out of date?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the best way to do this is.
Also, it might make it easier for the explanation that goes along with it to get out of date.

width = 0.8,
horizontal = {
height = 0.9,
},
vertical = {
height = 0.9,
},
center = {
width = 0.5
}
}
]])

-- set("width", 0.75)
set("winblend", 0)
set("prompt_position", "bottom")
set("preview_cutoff", 120)

set("results_height", 1)
set("results_height", 5)
set("results_width", 0.8)

set("prompt_prefix", "> ", [[
Expand Down
63 changes: 60 additions & 3 deletions lua/telescope/config/resolve.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---@tag telescope.resolve

---@brief [[
--- Provides "resolver functions" to allow more customisable inputs for options.
---@brief ]]

--[[

Expand Down Expand Up @@ -40,7 +45,7 @@ height =

3. function(picker, columns, lines)
-> returns one of the above options
return max.min(110, max_rows * .5)
return math.min(110, max_rows * .5)

if columns > 120 then
return 110
Expand Down Expand Up @@ -88,8 +93,7 @@ That's the next step to scrolling.
local get_default = require('telescope.utils').get_default

local resolver = {}

local _resolve_map = {
local _simple_resolve_map = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably easier to understand by just doing _resolve_map = {} and then each of the following with _resolve_map[function() ...] = ... etc.

I don't think we need to do the copy thing, right?

Or is this because only some keys are considered "simple"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, I was getting some issues where the padding case in _resolve_map was referring back to _resolve_map.

I don't seem to be getting those issues now, so I've changed to just using _resolve_map instead of _simple_resolve_map.
I'll keep an eye out for any issues re-emerging.

-- Booleans
[function(val) return val == false end] = function(selector, val)
return function(...)
Expand Down Expand Up @@ -128,6 +132,44 @@ local _resolve_map = {
end,
}

-- Make a copy of the "simple" _resolve_map that we can add to to make the "full" _resolve_map.
local _resolve_map = vim.deepcopy(_simple_resolve_map)

-- Add padding option
_resolve_map[function(val) return type(val) == 'table' and val['padding'] ~= nil end] = function(selector, val)
local resolve_pad = function(value)
for k, v in pairs(_simple_resolve_map) do
if k(value) then
return v(selector, value)
end
end

error('invalid configuration option for padding:' .. tostring(value))
end

return function(...)
local selected = select(selector, ...)
local padding = resolve_pad(val['padding'])
return math.floor(selected - 2 * padding(...))
end
end


--- Converts input to a function that returns the height.
--- The input must take one of four forms:
--- 1. 0 <= number < 1
--- This means total height as a percentage.
--- 2. 1 <= number
--- This means total height as a fixed number.
--- 3. function
--- Must have signature:
--- function(self, max_columns, max_lines): number
--- 4. table of the form:
--- {padding = `foo`}
--- where `foo` has one of the previous three forms.
--- The height is then set to be the remaining space after padding.
--- The returned function will have signature:
--- function(self, max_columns, max_lines): number
resolver.resolve_height = function(val)
for k, v in pairs(_resolve_map) do
if k(val) then
Expand All @@ -138,6 +180,21 @@ resolver.resolve_height = function(val)
error('invalid configuration option for height:' .. tostring(val))
end

--- Converts input to a function that returns the width.
--- The input must take one of four forms:
--- 1. 0 <= number < 1
--- This means total width as a percentage.
--- 2. 1 <= number
--- This means total width as a fixed number.
--- 3. function
--- Must have signature:
--- function(self, max_columns, max_lines): number
--- 4. table of the form:
--- {padding = `foo`}
--- where `foo` has one of the previous three forms.
--- The height is then set to be the remaining space after padding.
--- The returned function will have signature:
--- function(self, max_columns, max_lines): number
resolver.resolve_width = function(val)
for k, v in pairs(_resolve_map) do
if k(val) then
Expand Down
Loading