1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-22 21:01:36 +03:00

feat: add a way to spawn populated LineEditor

feat: support pre-filled content in prompts

docs: document new PromptInputLine parameter

fix: remove reset of line contents
This commit is contained in:
Eduard Korchmar 2024-08-21 20:35:33 +02:00 committed by Wez Furlong
parent de0ecc60eb
commit b59cc5b008
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
5 changed files with 12 additions and 2 deletions

View File

@ -457,6 +457,9 @@ pub struct QuickSelectArguments {
#[derive(Debug, Clone, PartialEq, FromDynamic, ToDynamic)]
pub struct PromptInputLine {
pub action: Box<KeyAssignment>,
/// Optional label to pre-fill the input line with
#[dynamic(default)]
pub initial_value: Option<String>,
/// Descriptive text to show ahead of prompt
#[dynamic(default)]
pub description: String,

View File

@ -8,7 +8,7 @@ from the user.
When the user enters the line, emits an event that allows you to act
upon the input.
`PromptInputLine` accepts three fields:
`PromptInputLine` accepts four fields:
* `description` - the text to show at the top of the display area. You may
embed escape sequences and/or use [wezterm.format](../wezterm/format.md).
@ -20,6 +20,9 @@ upon the input.
anything, or CTRL-C to cancel the input.
* `prompt` - the text to show as the prompt. You may embed escape sequences
and/or use [wezterm.format](../wezterm/format.md). Defaults to: `"> "`. {{since('nightly', inline=True)}}
* `initial_value` - optional. If provided, the initial content of the input
field will be set to this value. The user may edit it prior to submitting
the input.
## Example of interactively renaming the current tab
@ -34,6 +37,7 @@ config.keys = {
mods = 'CTRL|SHIFT',
action = act.PromptInputLine {
description = 'Enter new name for tab',
initial_value = 'My Tab Name',
action = wezterm.action_callback(function(window, pane, line)
-- line will be `nil` if they hit escape without entering anything
-- An empty string if they just hit enter

View File

@ -39,6 +39,7 @@ wezterm.on('augment-command-palette', function(window, pane)
action = act.PromptInputLine {
description = 'Enter new name for tab',
initial_value = 'My Tab Name',
action = wezterm.action_callback(function(window, pane, line)
if line then
window:active_tab():set_title(line)

View File

@ -811,7 +811,6 @@ impl<'term> LineEditor<'term> {
}
fn read_line_impl(&mut self, host: &mut dyn LineEditorHost) -> Result<Option<String>> {
self.line.clear();
self.history_pos = None;
self.bottom_line = None;
self.clear_completion();

View File

@ -68,6 +68,9 @@ pub fn show_line_prompt_overlay(
let mut host = PromptHost::new();
let mut editor = LineEditor::new(&mut term);
editor.set_prompt(&args.prompt);
if let Some(value) = &args.initial_value {
editor.set_line_and_cursor(value, value.len());
}
let line = editor.read_line(&mut host)?;
promise::spawn::spawn_into_main_thread(async move {