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.tags = tag_list::TagList::with_repo(ui.repo.get());
}
Ok(Key::Ctrl('n')) => ui.tags.next_page(),
Ok(Key::Ctrl('p')) => ui.tags.prev_page(),
Ok(Key::Ctrl('n')) => match ui.tags.next_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 {
State::EditRepo => {
ui.repo.confirm();

View File

@ -11,6 +11,8 @@ use crate::ui::State;
pub enum Error {
NoneSelected,
NoTags,
NoNextPage,
NoPrevPage,
}
impl fmt::Display for Error {
@ -18,6 +20,8 @@ impl fmt::Display for Error {
match self {
Error::NoTags => write!(f, "There are no tags"),
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
pub fn next_page(&mut self) {
pub fn next_page(&mut self) -> Result<(), Error> {
match &self.typ {
Type::Status(_) => (),
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(())
}
/// display previous page if possible
pub fn prev_page(&mut self) {
pub fn prev_page(&mut self) -> Result<(), Error> {
match &self.typ {
Type::Status(_) => (),
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(())
}
/// get a list of tag names with info