Add Reedline::has_last_command_context to allow checking if update_last_command_context will fail (#470)

This is necessary to avoid the problem with running executehostcommand keybindings in nushell
right after launching it (without having run actual user-input commands yet).

Since the error types are not exposed outside of the crate, we have to use a check instead of
matching on the error.
This commit is contained in:
unrelentingtech 2022-09-05 12:53:03 +03:00 committed by GitHub
parent 069d902bcb
commit fe889ae5c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -377,6 +377,14 @@ impl Reedline {
self.history.sync()
}
/// Check if any commands have been run.
///
/// When no commands have been run, calling [`Self::update_last_command_context`]
/// does not make sense and is guaranteed to fail with a "No command run" error.
pub fn has_last_command_context(&self) -> bool {
self.history_last_run_id.is_some()
}
/// update the last history item with more information
pub fn update_last_command_context(
&mut self,