Skip to content

feat: Consistent and sensible layout_config #922

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

Merged
merged 13 commits into from
Jul 1, 2021
34 changes: 1 addition & 33 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,5 @@ Plug 'nvim-telescope/telescope.nvim'
call plug#end()

autocmd VimEnter * PlugClean! | PlugUpdate --sync | close
lua << EOF

require('telescope').setup{
defaults = {
vimgrep_arguments = {
'rg',
'--color=never',
'--no-heading',
'--with-filename',
'--line-number',
'--column',
'--smart-case'
},
prompt_position = "bottom",
prompt_prefix = ">",
selection_strategy = "reset",
sorting_strategy = "descending",
layout_strategy = "horizontal",
layout_defaults = {},
file_ignore_patterns = {},
shorten_path = true,
winblend = 0,
width = 0.75,
preview_cutoff = 120,
results_height = 1,
results_width = 0.8,
border = {},
borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰'},
color_devicons = true,
use_less = true,
}
}
EOF
lua require('telescope').setup()
```
72 changes: 37 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ require('telescope').setup{
'--column',
'--smart-case'
},
prompt_position = "bottom",
prompt_prefix = "> ",
selection_caret = "> ",
entry_prefix = " ",
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "descending",
layout_strategy = "horizontal",
layout_defaults = {
layout_config = {
horizontal = {
mirror = false,
},
Expand All @@ -159,10 +158,6 @@ require('telescope').setup{
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
shorten_path = true,
winblend = 0,
width = 0.75,
preview_cutoff = 120,
results_height = 1,
results_width = 0.8,
border = {},
borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' },
color_devicons = true,
Expand Down Expand Up @@ -196,24 +191,19 @@ EOF

| Keys | Description | Options |
|------------------------|-------------------------------------------------------|----------------------------|
| `prompt_position` | Where the prompt should be located. | top/bottom |
| `prompt_prefix` | What should the prompt prefix be. | string |
| `selection_caret` | What should the selection caret be. | string |
| `entry_prefix` | What should be shown in front of every entry. (current selection excluded) | string|
| `initial_mode` | The initial mode when a prompt is opened. | insert/normal |
| `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) |
| `width` | TODO | NUM |
| `preview_cutoff` | TODO | NUM |
| `results_height` | TODO | NUM |
| `results_width` | TODO | NUM |
| `layout_config` | Extra settings for fine-tuning how your layout looks | [supported settings](https://github.com/nvim-telescope/telescope.nvim/wiki/Layouts#layout-defaults) |
| `sorting_strategy` | Where first selection should be located. | descending/ascending |
| `scroll_strategy` | How to behave when the when there are no more item next/prev | cycle, nil |
| `winblend` | How transparent is the telescope window should be. | number |
| `borderchars` | The border chars, it gives border telescope window | dict |
| `color_devicons` | Whether to color devicons or not | boolean |
| `use_less` | Whether to use less with bat or less/cat if bat not installed | boolean |
| `set_env` | Set environment variables for previewer | dict |
| `scroll_strategy` | How to behave when the when there are no more item next/prev | cycle, nil |
| `file_previewer` | What telescope previewer to use for files. | [Previewers](#previewers) |
| `grep_previewer` | What telescope previewer to use for grep and similar | [Previewers](#previewers) |
| `qflist_previewer` | What telescope previewer to use for qflist | [Previewers](#previewers) |
Expand Down Expand Up @@ -446,7 +436,7 @@ Built-in functions. Ready to be bound to any key you like. :smile:
| `builtin.current_buffer_fuzzy_find` | Live fuzzy search inside of the currently open buffer |
| `builtin.current_buffer_tags` | Lists all of the tags for the currently open buffer, with a preview |

### LSP Pickers
### Neovim LSP Pickers

| Functions | Description |
|---------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
Expand Down Expand Up @@ -644,7 +634,6 @@ Picker:new{
selection_strategy = "reset", -- follow, reset, row
border = {},
borderchars = {"─", "│", "─", "│", "┌", "┐", "┘", "└"},
preview_cutoff = 120,
default_selection_index = 1, -- Change the index of the initial selection row
}
```
Expand Down Expand Up @@ -677,24 +666,37 @@ end
### Layout (display)
<!-- TODO need some work -->

`Resolvable`:
1. 0 <= number < 1:
- This means total height as a percentage
2. 1 <= number:
- This means total height as a fixed number
3. function(picker, columns, lines):
- returns one of the above options
- `return max.min(110, max_rows * .5)`

```lua
layout_strategies.horizontal = function(self, max_columns, max_lines)
local layout_config = validate_layout_config(self.layout_config or {}, {
width_padding = "How many cells to pad the width",
height_padding = "How many cells to pad the height",
preview_width = "(Resolvable): Determine preview width",
})
...
end
Layout can be configured by choosing a specific `layout_strategy` and
specifying a particular `layout_config` for that strategy.
For more details on available strategies and configuration options,
see `:help telescope.layout`.

Some options for configuring sizes in layouts are "resolvable".
This means that they can take different forms, and will be interpreted differently according to which form they take.
For example, if we wanted to set the `width` of a picker using the `vertical`
layout strategy to 50% of the screen width, we would specify that width
as `0.5`, but if we wanted to specify the `width` to be exactly 80
characters wide, we would specify it as `80`.
For more details on resolving sizes, see `:help telescope.resolve`.

As an example, if we wanted to specify the layout strategy and width,
but only for this instance, we could do something like:
```
:lua require('telescope.builtin').find_files({layout_strategy='vertical',layout_config={width=0.5}})
```
or if we wanted to change the width for every time we use the `vertical`
layout strategy, we could add the following to our `setup()` call:
```
require('telescope').setup({
defaults = {
layout_config = {
vertical = { width = 0.5 }
-- other layout configuration here
},
-- other defaults configuration here
},
-- other configuration values here
})
```

## Vim Commands
Expand Down
Loading