show errors for next/previous page in info widget

This commit is contained in:
Thomas Eppers 2021-09-08 19:26:07 +02:00
parent d79baa67c6
commit 063ce06aaa
2 changed files with 18 additions and 6 deletions

View File

@ -104,8 +104,14 @@ impl Ui {
ui.repo.confirm(); ui.repo.confirm();
ui.tags = tag_list::TagList::with_repo(ui.repo.get()); ui.tags = tag_list::TagList::with_repo(ui.repo.get());
} }
Ok(Key::Ctrl('n')) => ui.tags.next_page(), Ok(Key::Ctrl('n')) => match ui.tags.next_page() {
Ok(Key::Ctrl('p')) => ui.tags.prev_page(), Err(e) => ui.info.set_info(&format!("{}", e)),
Ok(_) => (),
},
Ok(Key::Ctrl('p')) => match ui.tags.prev_page() {
Err(e) => ui.info.set_info(&format!("{}", e)),
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();

View File

@ -11,6 +11,8 @@ use crate::ui::State;
pub enum Error { pub enum Error {
NoneSelected, NoneSelected,
NoTags, NoTags,
NoNextPage,
NoPrevPage,
} }
impl fmt::Display for Error { impl fmt::Display for Error {
@ -18,6 +20,8 @@ impl fmt::Display for Error {
match self { match self {
Error::NoTags => write!(f, "There are no tags"), Error::NoTags => write!(f, "There are no tags"),
Error::NoneSelected => write!(f, "No tag selected"), Error::NoneSelected => write!(f, "No tag selected"),
Error::NoNextPage => write!(f, "No next page available"),
Error::NoPrevPage => write!(f, "No previous page available"),
} }
} }
} }
@ -55,25 +59,27 @@ impl TagList {
} }
/// display next page if possible /// display next page if possible
pub fn next_page(&mut self) { pub fn next_page(&mut self) -> Result<(), Error> {
match &self.typ { match &self.typ {
Type::Status(_) => (), Type::Status(_) => (),
Type::Repo(tags) => match tags.next_page() { Type::Repo(tags) => match tags.next_page() {
Err(e) => self.typ = Type::Status(format!("{}", e)), Err(e) => return Err(Error::NoNextPage),
Ok(tags) => self.typ = Type::Repo(tags), Ok(tags) => self.typ = Type::Repo(tags),
}, },
} }
Ok(())
} }
/// display previous page if possible /// display previous page if possible
pub fn prev_page(&mut self) { pub fn prev_page(&mut self) -> Result<(), Error> {
match &self.typ { match &self.typ {
Type::Status(_) => (), Type::Status(_) => (),
Type::Repo(tags) => match tags.prev_page() { Type::Repo(tags) => match tags.prev_page() {
Err(e) => self.typ = Type::Status(format!("{}", e)), Err(e) => return Err(Error::NoPrevPage),
Ok(tags) => self.typ = Type::Repo(tags), Ok(tags) => self.typ = Type::Repo(tags),
}, },
} }
Ok(())
} }
/// get a list of tag names with info /// get a list of tag names with info