WIP saving
This commit is contained in:
parent
73e57dc11d
commit
9023e0b0ed
16
src/ui.rs
16
src/ui.rs
@ -84,7 +84,12 @@ impl Ui {
|
|||||||
match receiver.try_recv() {
|
match receiver.try_recv() {
|
||||||
Ok(Key::Ctrl('q')) => break 'core, //quit program without saving
|
Ok(Key::Ctrl('q')) => break 'core, //quit program without saving
|
||||||
Ok(Key::Char('\t')) => ui.state = ui.state.next(),
|
Ok(Key::Char('\t')) => ui.state = ui.state.next(),
|
||||||
Ok(Key::Ctrl('s')) => ui.services.save(),
|
Ok(Key::Ctrl('s')) => {
|
||||||
|
match ui.services.save() {
|
||||||
|
Err(_) => (), //TODO proper error handling
|
||||||
|
Ok(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(Key::Char('\n')) => match ui.state {
|
Ok(Key::Char('\n')) => match ui.state {
|
||||||
State::EditRepo => {
|
State::EditRepo => {
|
||||||
ui.repo.confirm();
|
ui.repo.confirm();
|
||||||
@ -119,9 +124,16 @@ impl Ui {
|
|||||||
Err(_) => ui.tags = tag_list::TagList::new_line("no image found"),
|
Err(_) => ui.tags = tag_list::TagList::new_line("no image found"),
|
||||||
Ok(s) => ui.repo.set(s),
|
Ok(s) => ui.repo.set(s),
|
||||||
}
|
}
|
||||||
|
} else if ui.state == State::SelectTag {
|
||||||
|
ui.tags.handle_input(&ui.state, Key::Up);
|
||||||
|
//update repo widget
|
||||||
|
let mut repo = ui.services.extract_repo().unwrap();
|
||||||
|
let tag = ui.tags.get().unwrap();
|
||||||
|
repo.push_str(":");
|
||||||
|
repo.push_str(&tag);
|
||||||
|
ui.repo.set(repo);
|
||||||
}
|
}
|
||||||
ui.repo.handle_input(&ui.state, Key::Up);
|
ui.repo.handle_input(&ui.state, Key::Up);
|
||||||
ui.tags.handle_input(&ui.state, Key::Up);
|
|
||||||
}
|
}
|
||||||
Ok(Key::Down) => {
|
Ok(Key::Down) => {
|
||||||
if ui.state == State::SelectService && ui.services.find_next_match() {
|
if ui.state == State::SelectService && ui.services.find_next_match() {
|
||||||
|
@ -149,15 +149,26 @@ impl ServiceSwitcher {
|
|||||||
pub fn change_current_line(&mut self, repo_with_tag: String) {
|
pub fn change_current_line(&mut self, repo_with_tag: String) {
|
||||||
match self.state.selected() {
|
match self.state.selected() {
|
||||||
None => (),
|
None => (),
|
||||||
Some(i) => self.list[i] = repo_with_tag,
|
Some(i) => {
|
||||||
|
let caps = match self.regex.captures(&self.list[i]) {
|
||||||
|
None => return,
|
||||||
|
Some(cap) => cap,
|
||||||
|
};
|
||||||
|
let mut line = caps.get(1).unwrap().as_str().to_string();
|
||||||
|
line.push_str(": ");
|
||||||
|
line.push_str(&repo_with_tag);
|
||||||
|
self.list[i] = line;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self) {
|
pub fn save(&self) -> Result<(), std::io::Error> {
|
||||||
let name = "docker-compose.yml";
|
let name = "docker-compose.yml2";
|
||||||
let mut file = File::open(name).unwrap();
|
let mut file = File::create(name)?;
|
||||||
for line in &self.list {
|
for line in &self.list {
|
||||||
file.write_all(line.as_bytes()).unwrap();
|
file.write_all(line.as_bytes())?;
|
||||||
|
file.write_all("\n".as_bytes())?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user