From 45f2bb64b04c6f98556487610d9cf53c8cc6c735 Mon Sep 17 00:00:00 2001 From: Thomas Eppers Date: Sat, 23 Oct 2021 13:26:09 +0200 Subject: [PATCH] fixed the rest of the clippy warnings; bumped version to 0.10.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/ui/default.rs | 1 - src/ui/no_yaml.rs | 5 +---- src/widget/tag_list.rs | 23 ++++++++++++++++++----- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f1ab77..6c37106 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -673,7 +673,7 @@ dependencies = [ [[package]] name = "reel-moby" -version = "0.9.0" +version = "0.10.0" dependencies = [ "chrono", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index e5a393a..dcfb5aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "reel-moby" -version = "0.9.0" +version = "0.10.0" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/ui/default.rs b/src/ui/default.rs index a76800e..dfb3241 100644 --- a/src/ui/default.rs +++ b/src/ui/default.rs @@ -102,7 +102,6 @@ impl Ui { Ok(Key::Ctrl('q')) => break 'core, //quit program without saving Ok(Key::Char('\t')) => { ui.state.next(); - () } Ok(Key::Ctrl('s')) => match ui.services.save() { Err(e) => { diff --git a/src/ui/no_yaml.rs b/src/ui/no_yaml.rs index dfb9629..06757b5 100644 --- a/src/ui/no_yaml.rs +++ b/src/ui/no_yaml.rs @@ -107,10 +107,7 @@ impl NoYaml { ui.repo.confirm(); ui.tags = tag_list::TagList::with_repo_name(ui.repo.get()); } - State::SelectTag => { - ui.tags.get_selected(); - () - } + State::SelectTag => ui.tags.handle_input(Key::Char('\n')), }, Ok(Key::Char(key)) => match ui.state { State::EditRepo => { diff --git a/src/widget/tag_list.rs b/src/widget/tag_list.rs index c022411..b14e936 100644 --- a/src/widget/tag_list.rs +++ b/src/widget/tag_list.rs @@ -25,6 +25,7 @@ impl fmt::Display for Error { enum Line { Status(String), Image(tags::Images), + NextPage(String), } impl fmt::Display for Line { @@ -32,6 +33,7 @@ impl fmt::Display for Line { match self { Line::Status(s) => write!(f, "{}", s), Line::Image(i) => write!(f, "{}", i), + Line::NextPage(s) => write!(f, "{}", s), } } } @@ -68,7 +70,7 @@ impl TagList { match tags.next_page() { Err(_) => (), Ok(new_tags) => { - lines.push(Line::Status(String::from("load more tags"))); + lines.push(Line::NextPage(String::from("load more tags"))); tags = new_tags; } }; @@ -115,24 +117,35 @@ impl TagList { match key { Key::Down => self.next(), Key::Up => self.previous(), + Key::Char('\n') => self.select(), _ => (), } } + /// loads new tags when matching line is selected + fn select(&mut self) { + if let Some(i) = self.state.selected() { + if let Line::NextPage(_) = &self.lines[i] { + self.load_next_page() + } + } + } + pub fn get_selected(&mut self) -> Result { match self.state.selected() { None => Err(Error::NoneSelected), - Some(i) if i == self.lines.len() - 1 => { - self.load_next_page(); - Err(Error::NextPageSelected) - } Some(i) => match &self.lines[i] { Line::Status(_) => Err(Error::SelectedStatus), Line::Image(i) => Ok(i.tag_name.clone()), + Line::NextPage(_) => { + self.load_next_page(); + Err(Error::NextPageSelected) + } }, } } + /// load new tags from the next page fn load_next_page(&mut self) { match &self.tags { Some(tags) => match tags.next_page() {