Download crates/forge_main/src/input.rs from SaylorTwift/forgecode: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_main/src/input.rs
- Command line
-
hf download hf://SaylorTwift/forgecode/crates/forge_main/src/input.rs
-
curl -L -o input.rs https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_main/src/input.rs
1.61 kB
| use std::path::PathBuf; | |
| use std::sync::{Arc, Mutex}; | |
| use forge_api::Environment; | |
| use crate::editor::{ForgeEditor, ReadResult}; | |
| use crate::model::{AppCommand, ForgeCommandManager}; | |
| use crate::prompt::ForgePrompt; | |
| use crate::tracker; | |
| /// Console implementation for handling user input via command line. | |
| pub struct Console { | |
| command: Arc<ForgeCommandManager>, | |
| editor: Mutex<ForgeEditor>, | |
| } | |
| impl Console { | |
| /// Creates a new instance of `Console`. | |
| pub fn new( | |
| env: Environment, | |
| custom_history_path: Option<PathBuf>, | |
| command: Arc<ForgeCommandManager>, | |
| ) -> Self { | |
| let editor = Mutex::new(ForgeEditor::new(env, custom_history_path, command.clone())); | |
| Self { command, editor } | |
| } | |
| } | |
| impl Console { | |
| pub async fn prompt(&self, prompt: &mut ForgePrompt) -> anyhow::Result<AppCommand> { | |
| loop { | |
| let mut forge_editor = self.editor.lock().unwrap(); | |
| let user_input = forge_editor.prompt(prompt)?; | |
| drop(forge_editor); | |
| match user_input { | |
| ReadResult::Continue => continue, | |
| ReadResult::Exit => return Ok(AppCommand::Exit), | |
| ReadResult::Empty => continue, | |
| ReadResult::Success(text) => { | |
| tracker::prompt(text.clone()); | |
| return self.command.parse(&text); | |
| } | |
| } | |
| } | |
| } | |
| /// Sets the buffer content for the next prompt | |
| pub fn set_buffer(&self, content: String) { | |
| let mut editor = self.editor.lock().unwrap(); | |
| editor.set_buffer(content); | |
| } | |
| } | |