take a generic object for displaying in the info widget
This commit is contained in:
parent
72fd5ec46f
commit
79577de0f9
@ -28,6 +28,16 @@ pub enum State {
|
|||||||
SelectService,
|
SelectService,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for State {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
State::EditRepo => write!(f, "Edit repository"),
|
||||||
|
State::SelectTag => write!(f, "Select a tag"),
|
||||||
|
State::SelectService => write!(f, "Select a image"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::iter::Iterator for State {
|
impl std::iter::Iterator for State {
|
||||||
type Item = Self;
|
type Item = Self;
|
||||||
|
|
||||||
@ -103,13 +113,14 @@ impl Ui {
|
|||||||
Ok(Key::Ctrl('q')) => break 'core, //quit program without saving
|
Ok(Key::Ctrl('q')) => break 'core, //quit program without saving
|
||||||
Ok(Key::Char('\t')) => {
|
Ok(Key::Char('\t')) => {
|
||||||
ui.state.next();
|
ui.state.next();
|
||||||
|
ui.info.set_info(&ui.state);
|
||||||
}
|
}
|
||||||
Ok(Key::Ctrl('s')) => match ui.services.save() {
|
Ok(Key::Ctrl('s')) => match ui.services.save() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
ui.info.set_info(&format!("{}", e));
|
ui.info.set_info(&format!("{}", e));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ok(_) => ui.info.set_info("Saved compose file"),
|
Ok(_) => ui.info.set_text("Saved compose file"),
|
||||||
},
|
},
|
||||||
Ok(Key::Ctrl('r')) => {
|
Ok(Key::Ctrl('r')) => {
|
||||||
ui.repo.confirm();
|
ui.repo.confirm();
|
||||||
@ -139,7 +150,7 @@ impl Ui {
|
|||||||
Ok(Key::Char(key)) => match ui.state {
|
Ok(Key::Char(key)) => match ui.state {
|
||||||
State::SelectService => (),
|
State::SelectService => (),
|
||||||
State::EditRepo => {
|
State::EditRepo => {
|
||||||
ui.info.set_info("Editing Repository");
|
ui.info.set_text("Editing Repository");
|
||||||
ui.repo.handle_input(Key::Char(key));
|
ui.repo.handle_input(Key::Char(key));
|
||||||
}
|
}
|
||||||
State::SelectTag => (),
|
State::SelectTag => (),
|
||||||
@ -147,7 +158,7 @@ impl Ui {
|
|||||||
Ok(Key::Backspace) => match ui.state {
|
Ok(Key::Backspace) => match ui.state {
|
||||||
State::SelectService => (),
|
State::SelectService => (),
|
||||||
State::EditRepo => {
|
State::EditRepo => {
|
||||||
ui.info.set_info("Editing Repository");
|
ui.info.set_text("Editing Repository");
|
||||||
ui.repo.handle_input(Key::Backspace);
|
ui.repo.handle_input(Key::Backspace);
|
||||||
}
|
}
|
||||||
State::SelectTag => (),
|
State::SelectTag => (),
|
||||||
|
@ -17,6 +17,15 @@ pub enum State {
|
|||||||
SelectTag,
|
SelectTag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for State {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
State::EditRepo => write!(f, "Edit repository"),
|
||||||
|
State::SelectTag => write!(f, "Select a tag"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::iter::Iterator for State {
|
impl std::iter::Iterator for State {
|
||||||
type Item = Self;
|
type Item = Self;
|
||||||
|
|
||||||
@ -97,6 +106,7 @@ impl NoYaml {
|
|||||||
Ok(Key::Ctrl('q')) => break 'core,
|
Ok(Key::Ctrl('q')) => break 'core,
|
||||||
Ok(Key::Char('\t')) => {
|
Ok(Key::Char('\t')) => {
|
||||||
ui.state.next();
|
ui.state.next();
|
||||||
|
ui.info.set_info(&ui.state);
|
||||||
}
|
}
|
||||||
Ok(Key::Ctrl('r')) => {
|
Ok(Key::Ctrl('r')) => {
|
||||||
ui.repo.confirm();
|
ui.repo.confirm();
|
||||||
@ -111,7 +121,7 @@ impl NoYaml {
|
|||||||
},
|
},
|
||||||
Ok(Key::Char(key)) => match ui.state {
|
Ok(Key::Char(key)) => match ui.state {
|
||||||
State::EditRepo => {
|
State::EditRepo => {
|
||||||
ui.info.set_info("Editing Repository");
|
ui.info.set_text("Editing Repository");
|
||||||
ui.repo.handle_input(Key::Char(key));
|
ui.repo.handle_input(Key::Char(key));
|
||||||
}
|
}
|
||||||
State::SelectTag => {
|
State::SelectTag => {
|
||||||
@ -120,7 +130,7 @@ impl NoYaml {
|
|||||||
},
|
},
|
||||||
Ok(Key::Backspace) => match ui.state {
|
Ok(Key::Backspace) => match ui.state {
|
||||||
State::EditRepo => {
|
State::EditRepo => {
|
||||||
ui.info.set_info("Editing Repository");
|
ui.info.set_text("Editing Repository");
|
||||||
ui.repo.handle_input(Key::Backspace);
|
ui.repo.handle_input(Key::Backspace);
|
||||||
}
|
}
|
||||||
State::SelectTag => (),
|
State::SelectTag => (),
|
||||||
|
@ -27,7 +27,11 @@ impl Info {
|
|||||||
.highlight_style(Style::default().bg(Color::Black))
|
.highlight_style(Style::default().bg(Color::Black))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_info(&mut self, info: &str) {
|
pub fn set_text(&mut self, info: &str) {
|
||||||
self.info = String::from(info);
|
self.info = String::from(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_info(&mut self, text: &dyn std::fmt::Display) {
|
||||||
|
self.info = format!("{}", text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user