Add support for max_preview_height
setting (#1088)
This commit is contained in:
parent
8b05b15355
commit
d7f8929656
3 changed files with 27 additions and 9 deletions
|
@ -158,6 +158,7 @@ pub struct Settings {
|
||||||
pub inline_height: u16,
|
pub inline_height: u16,
|
||||||
pub invert: bool,
|
pub invert: bool,
|
||||||
pub show_preview: bool,
|
pub show_preview: bool,
|
||||||
|
pub max_preview_height: u16,
|
||||||
pub show_help: bool,
|
pub show_help: bool,
|
||||||
pub exit_mode: ExitMode,
|
pub exit_mode: ExitMode,
|
||||||
pub word_jump_mode: WordJumpMode,
|
pub word_jump_mode: WordJumpMode,
|
||||||
|
@ -369,6 +370,7 @@ impl Settings {
|
||||||
.set_default("style", "auto")?
|
.set_default("style", "auto")?
|
||||||
.set_default("inline_height", 0)?
|
.set_default("inline_height", 0)?
|
||||||
.set_default("show_preview", false)?
|
.set_default("show_preview", false)?
|
||||||
|
.set_default("max_preview_height", 4)?
|
||||||
.set_default("show_help", true)?
|
.set_default("show_help", true)?
|
||||||
.set_default("invert", false)?
|
.set_default("invert", false)?
|
||||||
.set_default("exit_mode", "return-original")?
|
.set_default("exit_mode", "return-original")?
|
||||||
|
|
|
@ -300,9 +300,14 @@ impl State {
|
||||||
.max_by(|h1, h2| h1.command.len().cmp(&h2.command.len()));
|
.max_by(|h1, h2| h1.command.len().cmp(&h2.command.len()));
|
||||||
longest_command.map_or(0, |v| {
|
longest_command.map_or(0, |v| {
|
||||||
std::cmp::min(
|
std::cmp::min(
|
||||||
4,
|
settings.max_preview_height,
|
||||||
(v.command.len() as u16 + preview_width - 1 - border_size)
|
v.command
|
||||||
/ (preview_width - border_size),
|
.split('\n')
|
||||||
|
.map(|line| {
|
||||||
|
(line.len() as u16 + preview_width - 1 - border_size)
|
||||||
|
/ (preview_width - border_size)
|
||||||
|
})
|
||||||
|
.sum(),
|
||||||
)
|
)
|
||||||
}) + border_size * 2
|
}) + border_size * 2
|
||||||
} else if compact {
|
} else if compact {
|
||||||
|
@ -488,12 +493,15 @@ impl State {
|
||||||
} else {
|
} else {
|
||||||
use itertools::Itertools as _;
|
use itertools::Itertools as _;
|
||||||
let s = &results[selected].command;
|
let s = &results[selected].command;
|
||||||
s.char_indices()
|
s.split('\n')
|
||||||
|
.flat_map(|line| {
|
||||||
|
line.char_indices()
|
||||||
.step_by(preview_width.into())
|
.step_by(preview_width.into())
|
||||||
.map(|(i, _)| i)
|
.map(|(i, _)| i)
|
||||||
.chain(Some(s.len()))
|
.chain(Some(line.len()))
|
||||||
.tuple_windows()
|
.tuple_windows()
|
||||||
.map(|(a, b)| &s[a..b])
|
.map(|(a, b)| &line[a..b])
|
||||||
|
})
|
||||||
.join("\n")
|
.join("\n")
|
||||||
};
|
};
|
||||||
let preview = if compact {
|
let preview = if compact {
|
||||||
|
|
|
@ -196,6 +196,14 @@ Configure whether or not to show a preview of the selected command.
|
||||||
|
|
||||||
Useful when the command is longer than the terminal width and is cut off.
|
Useful when the command is longer than the terminal width and is cut off.
|
||||||
|
|
||||||
|
### `max_preview_height`
|
||||||
|
|
||||||
|
Configure the maximum height of the preview to show.
|
||||||
|
|
||||||
|
Useful when you have long scripts in your history that you want to distinguish by more than the first few lines.
|
||||||
|
|
||||||
|
Defaults to `4`.
|
||||||
|
|
||||||
### `show_help`
|
### `show_help`
|
||||||
|
|
||||||
Configure whether or not to show the help row, which includes the current Atuin version (and whether an update is available), a keymap hint, and the total amount of commands in your history.
|
Configure whether or not to show the help row, which includes the current Atuin version (and whether an update is available), a keymap hint, and the total amount of commands in your history.
|
||||||
|
|
Loading…
Reference in a new issue