diff --git a/src/input.rs b/src/input.rs index 5d59b73..58cbb01 100644 --- a/src/input.rs +++ b/src/input.rs @@ -5,6 +5,32 @@ use console::{Key, Term, style}; use fuzzy_matcher::skim::SkimMatcherV2; use itertools::Itertools; +pub fn input_text(term: &mut Term, name: &str) -> Result { + let mut text = "".to_string(); + + write!(term, "{}: {}", name, text)?; + + loop { + term.clear_line()?; + write!(term, "{}: {}", name, text)?; + + let key = term.read_key()?; + match key { + Key::Enter => { + writeln!(term)?; + return Ok(text); + } + Key::Backspace => { + text.pop(); + } + Key::Char(char) => { + text += &char.to_string(); + } + _ => {} + } + } +} + pub fn input_selection(term: &mut Term, data: Vec<(String, T)>, name: &str) -> Result { let mut filter = "".to_string(); diff --git a/src/main.rs b/src/main.rs index 6a4f8ba..ceecd9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use color_eyre::eyre::{Ok, Result}; use console::Term; use itertools::Itertools; -use crate::input::input_selection; +use crate::input::{input_selection, input_text}; use crate::project::Project; mod input; @@ -49,7 +49,7 @@ fn update() -> Result<()> { .collect_vec(); let project = input_selection(&mut term, paths, "Project")?; - let project = Project::new(&project)?; + let mut project = Project::new(&project)?; let services = project .services()? @@ -58,7 +58,9 @@ fn update() -> Result<()> { .collect_vec(); let service = input_selection(&mut term, services, "Service")?; - writeln!(term, "services: {:?}", service)?; + let tag = input_text(&mut term, "Tag")?; + + project.update_service(&service, &tag)?; term.show_cursor()?; diff --git a/src/project.rs b/src/project.rs index 29a548b..563a3a7 100644 --- a/src/project.rs +++ b/src/project.rs @@ -28,4 +28,8 @@ impl Project { .filter_map(|key| key.as_str().map(|text| text.to_string())) .collect()) } + + pub fn update_service(&mut self, _service: &str, _tag: &str) -> Result<()> { + todo!() + } }