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

PromptInputLine: fixup per code review

Apply my suggestions from code review.

closes: https://github.com/wez/wezterm/pull/6007
This commit is contained in:
Wez Furlong 2024-09-22 14:44:05 -07:00
parent b59cc5b008
commit 67603e73e0
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 21 additions and 7 deletions

View File

@ -22,7 +22,7 @@ upon the input.
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.
the input. {{since('nightly', inline=True)}}
## Example of interactively renaming the current tab

View File

@ -299,6 +299,14 @@ impl<'term> LineEditor<'term> {
/// accepted, or until an error is detected.
/// Returns Ok(None) if the editor was cancelled eg: via CTRL-C.
pub fn read_line(&mut self, host: &mut dyn LineEditorHost) -> Result<Option<String>> {
self.read_line_with_optional_initial_value(host, None)
}
pub fn read_line_with_optional_initial_value(
&mut self,
host: &mut dyn LineEditorHost,
initial_value: Option<&str>,
) -> Result<Option<String>> {
ensure!(
self.state == EditorState::Inactive,
"recursive call to read_line!"
@ -311,7 +319,7 @@ impl<'term> LineEditor<'term> {
self.terminal.set_raw_mode()?;
self.state = EditorState::Editing;
let res = self.read_line_impl(host);
let res = self.read_line_impl(host, initial_value);
self.state = EditorState::Inactive;
if let Some(move_end) = self.move_to_editor_end.take() {
@ -810,7 +818,15 @@ impl<'term> LineEditor<'term> {
Ok(())
}
fn read_line_impl(&mut self, host: &mut dyn LineEditorHost) -> Result<Option<String>> {
fn read_line_impl(
&mut self,
host: &mut dyn LineEditorHost,
initial_value: Option<&str>,
) -> Result<Option<String>> {
self.line.clear();
if let Some(value) = initial_value {
self.line.set_line_and_cursor(value, value.len());
}
self.history_pos = None;
self.bottom_line = None;
self.clear_completion();

View File

@ -68,10 +68,8 @@ 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)?;
let line =
editor.read_line_with_optional_initial_value(&mut host, args.initial_value.as_deref())?;
promise::spawn::spawn_into_main_thread(async move {
trampoline(name, window, pane, line);