diff --git a/src/ui.rs b/src/ui.rs index d6d70f9..8f09daa 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -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(); diff --git a/src/widget/tag_list.rs b/src/widget/tag_list.rs index a74c829..7de4408 100644 --- a/src/widget/tag_list.rs +++ b/src/widget/tag_list.rs @@ -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