improved error handling; search tag when using up-key
This commit is contained in:
parent
cb4611d02b
commit
9e8df01096
28
src/ui.rs
28
src/ui.rs
@ -41,10 +41,9 @@ impl Ui {
|
|||||||
let mut ui = Ui {
|
let mut ui = Ui {
|
||||||
state: State::SelectService,
|
state: State::SelectService,
|
||||||
repo: repo_entry::RepoEntry::new(repo_id),
|
repo: repo_entry::RepoEntry::new(repo_id),
|
||||||
tags: tag_list::TagList::with_status("Fetching Tags"),
|
tags: tag_list::TagList::with_status("Select image or edit Repository"),
|
||||||
services: service_switcher::ServiceSwitcher::new(),
|
services: service_switcher::ServiceSwitcher::new(),
|
||||||
};
|
};
|
||||||
ui.tags = tag_list::TagList::with_repo(ui.repo.get());
|
|
||||||
|
|
||||||
//setup tui
|
//setup tui
|
||||||
let stdout = io::stdout().into_raw_mode().unwrap();
|
let stdout = io::stdout().into_raw_mode().unwrap();
|
||||||
@ -84,7 +83,10 @@ 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')) => ui.state = ui.state.next(),
|
Ok(Key::Char('\t')) => ui.state = ui.state.next(),
|
||||||
Ok(Key::Ctrl('s')) => match ui.services.save() {
|
Ok(Key::Ctrl('s')) => match ui.services.save() {
|
||||||
Err(_) => continue,
|
Err(e) => {
|
||||||
|
ui.show_info(&format!("{}", e));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
},
|
},
|
||||||
Ok(Key::Char('\n')) => match ui.state {
|
Ok(Key::Char('\n')) => match ui.state {
|
||||||
@ -95,7 +97,10 @@ impl Ui {
|
|||||||
State::SelectTag => {
|
State::SelectTag => {
|
||||||
let mut repo = ui.repo.get();
|
let mut repo = ui.repo.get();
|
||||||
let tag = match ui.tags.get_selected() {
|
let tag = match ui.tags.get_selected() {
|
||||||
Err(_) => continue,
|
Err(e) => {
|
||||||
|
ui.show_info(&format!("{}", e));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Ok(tag) => tag,
|
Ok(tag) => tag,
|
||||||
};
|
};
|
||||||
repo.push_str(":");
|
repo.push_str(":");
|
||||||
@ -121,8 +126,18 @@ impl Ui {
|
|||||||
Ok(Key::Up) => {
|
Ok(Key::Up) => {
|
||||||
if ui.state == State::SelectService && ui.services.find_previous_match() {
|
if ui.state == State::SelectService && ui.services.find_previous_match() {
|
||||||
match ui.services.extract_repo() {
|
match ui.services.extract_repo() {
|
||||||
Err(_) => ui.show_info("No image found"),
|
Err(e) => ui.show_info(&format!("{}", e)),
|
||||||
Ok(s) => ui.repo.set(s),
|
Ok(s) => {
|
||||||
|
let repo = match crate::tags::Tags::check_repo(s) {
|
||||||
|
Err(e) => {
|
||||||
|
ui.show_info(&format!("{}", e));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Ok(s) => s,
|
||||||
|
};
|
||||||
|
ui.repo.set(repo);
|
||||||
|
ui.tags = tag_list::TagList::with_repo(ui.repo.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui.tags.handle_input(&ui.state, Key::Up);
|
ui.tags.handle_input(&ui.state, Key::Up);
|
||||||
@ -141,6 +156,7 @@ impl Ui {
|
|||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
};
|
};
|
||||||
ui.repo.set(repo);
|
ui.repo.set(repo);
|
||||||
|
ui.tags = tag_list::TagList::with_repo(ui.repo.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use tui::widgets::{Block, Borders, List, ListState};
|
|||||||
|
|
||||||
use crate::ui::State;
|
use crate::ui::State;
|
||||||
|
|
||||||
#[derive(Debug, Display)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
NoneSelected,
|
NoneSelected,
|
||||||
Parsing(String),
|
Parsing(String),
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt;
|
||||||
|
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
use tui::style::{Color, Style};
|
use tui::style::{Color, Style};
|
||||||
use tui::widgets::{Block, Borders, List, ListState};
|
use tui::widgets::{Block, Borders, List, ListState};
|
||||||
@ -12,9 +14,18 @@ pub struct TagList {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
NoneSelected,
|
||||||
NoTags,
|
NoTags,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::NoTags => write!(f, "There are no tags"),
|
||||||
|
Error::NoneSelected => write!(f, "No tag selected"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
Status(String),
|
Status(String),
|
||||||
Repo(tags::Tags),
|
Repo(tags::Tags),
|
||||||
@ -34,7 +45,7 @@ impl TagList {
|
|||||||
|
|
||||||
pub fn with_repo(name: String) -> Self {
|
pub fn with_repo(name: String) -> Self {
|
||||||
match tags::Tags::new(name) {
|
match tags::Tags::new(name) {
|
||||||
Err(_) => Self::with_status("Couldn't query tags: no images found"),
|
Err(e) => Self::with_status(&format!("{}", e)),
|
||||||
Ok(tags) => Self::new(Type::Repo(tags)),
|
Ok(tags) => Self::new(Type::Repo(tags)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +68,7 @@ impl TagList {
|
|||||||
match &self.typ {
|
match &self.typ {
|
||||||
Type::Status(_) => Err(Error::NoTags),
|
Type::Status(_) => Err(Error::NoTags),
|
||||||
Type::Repo(_) => match self.state.selected() {
|
Type::Repo(_) => match self.state.selected() {
|
||||||
None => Err(Error::NoTags),
|
None => Err(Error::NoneSelected),
|
||||||
Some(i) => Ok(self.get_names().unwrap()[i].clone()),
|
Some(i) => Ok(self.get_names().unwrap()[i].clone()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user