-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
feat: add a way to spawn populated LineEditor #6007
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -811,7 +811,6 @@ impl<'term> LineEditor<'term> { | |
} | ||
|
||
fn read_line_impl(&mut self, host: &mut dyn LineEditorHost) -> Result<Option<String>> { | ||
self.line.clear(); | ||
Comment on lines
813
to
-814
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I didn't spot this initially. I think this is a big semantic change that breaks behavior. You can probably see this in the debug overlay (ctrl-shift-L) if you type in What I think should be done here is to adjust this method: 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());
} Then, refactor: pub fn read_line(&mut self, host: &mut dyn LineEditorHost) -> Result<Option<String>> into pub fn read_line_with_optional_initial_value(&mut self, host: &mut dyn LineEditorHost, initial_value: Option<&str>) -> Result<Option<String>> that calls the above function: ...
let res = self.read_line_impl(host, initial_value);
... Then finally add back the original method, but make it call the refactored one: pub fn read_line(&mut self, host: &mut dyn LineEditorHost) -> Result<Option<String>> {
self.read_line_with_optional_initial_value(host, None)
} Note that the public methods on this struct need to have doc comments because they are part of the public API that is published to https://docs.rs/termwiz/latest/termwiz/lineedit/struct.LineEditor.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
From what I can test, it does not appear as if removal of this line causes old contents to appear anywhere; I tested various combinations of launching REPL, custom editor, pressing enter, cancelling input with Esc and Ctrl+C and other things. If I read the code correctly, in every instance where a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The termwiz crate is a public export and used by others, so just looking at the usage within wezterm is not sufficient to determine that nothing is impacted by this change. I went ahead and merged this with my suggested changes. Thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense. Thank you for reviewing this |
||
self.history_pos = None; | ||
self.bottom_line = None; | ||
self.clear_completion(); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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)?; | ||||||||||||
Comment on lines
+71
to
74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the above changes, this would become:
Suggested change
|
||||||||||||
|
||||||||||||
promise::spawn::spawn_into_main_thread(async move { | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's tag this with the version it was introduced with: