-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CLI editors into separate modules
- Moved multiline input functionality to 'multiline_editor.rs' for improved modularity. - Separated user input handling into 'user_input_editor.rs'. - Cleaned up 'utils.rs' by removing editor-specific logic and redirecting imports. - Created an 'editor' directory to encapsulate all editor-related components. This refactor enhances code organization, making the codebase easier to maintain and extend, and prepares for implementing advanced editor features.
- Loading branch information
Christian Stolz
committed
Oct 4, 2024
1 parent
1edc31b
commit ebfc303
Showing
9 changed files
with
43 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
mod multiline_editor; | ||
mod user_input_editor; | ||
|
||
pub use multiline_editor::get_multiline_input; | ||
|
||
pub use user_input_editor::get_user_input; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::cli::style::configure_mad_skin; | ||
use rustyline::{error::ReadlineError, Config, DefaultEditor, EditMode::Emacs}; | ||
|
||
pub fn get_user_input(prompt: &str) -> Result<String, Box<dyn std::error::Error>> { | ||
let config = Config::builder().edit_mode(Emacs).build(); | ||
let mut rl = DefaultEditor::with_config(config)?; | ||
|
||
// Print a styled prompt | ||
let skin = configure_mad_skin(); | ||
skin.print_text("---\n"); | ||
skin.print_text(&format!("**{}**", prompt)); // Make the prompt bold and colored | ||
|
||
// Read a single line of input | ||
match rl.readline("") { | ||
Ok(input) => Ok(input.trim().to_string()), | ||
Err(ReadlineError::Interrupted) => Ok(String::new()), // Return empty string as cancelation | ||
Err(ReadlineError::Eof) => Ok(String::new()), | ||
Err(err) => Err(Box::new(err)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters