diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index 570cef942..c273182ca 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -457,6 +457,9 @@ pub struct QuickSelectArguments { #[derive(Debug, Clone, PartialEq, FromDynamic, ToDynamic)] pub struct PromptInputLine { pub action: Box, + /// Optional label to pre-fill the input line with + #[dynamic(default)] + pub initial_value: Option, /// Descriptive text to show ahead of prompt #[dynamic(default)] pub description: String, diff --git a/docs/config/lua/keyassignment/PromptInputLine.md b/docs/config/lua/keyassignment/PromptInputLine.md index 904cb6a5a..955e19d81 100644 --- a/docs/config/lua/keyassignment/PromptInputLine.md +++ b/docs/config/lua/keyassignment/PromptInputLine.md @@ -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 diff --git a/docs/config/lua/window-events/augment-command-palette.md b/docs/config/lua/window-events/augment-command-palette.md index 9991352cd..0c63ed8db 100644 --- a/docs/config/lua/window-events/augment-command-palette.md +++ b/docs/config/lua/window-events/augment-command-palette.md @@ -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) diff --git a/termwiz/src/lineedit/mod.rs b/termwiz/src/lineedit/mod.rs index 8130a051b..878671b10 100644 --- a/termwiz/src/lineedit/mod.rs +++ b/termwiz/src/lineedit/mod.rs @@ -811,7 +811,6 @@ impl<'term> LineEditor<'term> { } fn read_line_impl(&mut self, host: &mut dyn LineEditorHost) -> Result> { - self.line.clear(); self.history_pos = None; self.bottom_line = None; self.clear_completion(); diff --git a/wezterm-gui/src/overlay/prompt.rs b/wezterm-gui/src/overlay/prompt.rs index 19debe8ef..f67d93ba6 100644 --- a/wezterm-gui/src/overlay/prompt.rs +++ b/wezterm-gui/src/overlay/prompt.rs @@ -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 {