Compare commits

..

No commits in common. "45f2bb64b04c6f98556487610d9cf53c8cc6c735" and "c9a8c637c47164bfcf0eda02306121de04f569c7" have entirely different histories.

7 changed files with 27 additions and 30 deletions

2
Cargo.lock generated
View File

@ -673,7 +673,7 @@ dependencies = [
[[package]] [[package]]
name = "reel-moby" name = "reel-moby"
version = "0.10.0" version = "0.9.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"lazy_static", "lazy_static",

View File

@ -1,7 +1,7 @@
[package] [package]
name = "reel-moby" name = "reel-moby"
version = "0.10.0" version = "0.9.0"
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -69,7 +69,7 @@ pub fn split_tag_from_repo(input: &str) -> Result<(&str, &str), Error> {
pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> { pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> {
let repo = repo.trim(); let repo = repo.trim();
let split_repo: Vec<&str> = repo.split('/').collect(); let split_repo: Vec<&str> = repo.split("/").collect();
match split_repo.len() { match split_repo.len() {
1 => { 1 => {
let regex = regex::Regex::new(r"[a-z0-9]+").unwrap(); let regex = regex::Regex::new(r"[a-z0-9]+").unwrap();

View File

@ -102,6 +102,7 @@ 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')) => { Ok(Key::Char('\t')) => {
ui.state.next(); ui.state.next();
()
} }
Ok(Key::Ctrl('s')) => match ui.services.save() { Ok(Key::Ctrl('s')) => match ui.services.save() {
Err(e) => { Err(e) => {
@ -128,7 +129,7 @@ impl Ui {
} }
Ok(tag) => tag, Ok(tag) => tag,
}; };
repo.push(':'); repo.push_str(":");
repo.push_str(&tag); repo.push_str(&tag);
ui.services.change_current_line(repo); ui.services.change_current_line(repo);
} }

View File

@ -107,7 +107,10 @@ impl NoYaml {
ui.repo.confirm(); ui.repo.confirm();
ui.tags = tag_list::TagList::with_repo_name(ui.repo.get()); ui.tags = tag_list::TagList::with_repo_name(ui.repo.get());
} }
State::SelectTag => ui.tags.handle_input(Key::Char('\n')), State::SelectTag => {
ui.tags.get_selected();
()
}
}, },
Ok(Key::Char(key)) => match ui.state { Ok(Key::Char(key)) => match ui.state {
State::EditRepo => { State::EditRepo => {

View File

@ -104,7 +104,10 @@ impl ServiceSwitcher {
/// finds the next image tag in given file /// finds the next image tag in given file
pub fn find_next_match(&mut self) -> bool { pub fn find_next_match(&mut self) -> bool {
let current_line: usize = self.state.selected().unwrap_or(0); let current_line: usize = match self.state.selected() {
None => 0,
Some(i) => i,
};
let mut i = (current_line + 1) % self.list.len(); let mut i = (current_line + 1) % self.list.len();
loop { loop {
@ -128,7 +131,10 @@ impl ServiceSwitcher {
/// finds the previous image tag in given file /// finds the previous image tag in given file
pub fn find_previous_match(&mut self) -> bool { pub fn find_previous_match(&mut self) -> bool {
let current_line: usize = self.state.selected().unwrap_or(0); let current_line: usize = match self.state.selected() {
None => 0,
Some(i) => i,
};
let mut i: usize = if current_line == 0 { let mut i: usize = if current_line == 0 {
self.list.len() - 1 self.list.len() - 1
@ -159,10 +165,10 @@ impl ServiceSwitcher {
/// return the repository from currently selected row /// return the repository from currently selected row
pub fn extract_repo(&self) -> Result<String, Error> { pub fn extract_repo(&self) -> Result<String, Error> {
match self.state.selected() { match self.state.selected() {
None => Err(Error::NoneSelected), None => return Err(Error::NoneSelected),
Some(i) => match repo::match_yaml_image(&self.list[i]) { Some(i) => match repo::match_yaml_image(&self.list[i]) {
Err(_) => Err(Error::Parsing(String::from("Nothing found"))), Err(_) => return Err(Error::Parsing(String::from("Nothing found"))),
Ok((_, repo)) => Ok(repo.to_string()), Ok((_, repo)) => return Ok(repo.to_string()),
}, },
} }
} }

View File

@ -25,7 +25,6 @@ impl fmt::Display for Error {
enum Line { enum Line {
Status(String), Status(String),
Image(tags::Images), Image(tags::Images),
NextPage(String),
} }
impl fmt::Display for Line { impl fmt::Display for Line {
@ -33,7 +32,6 @@ impl fmt::Display for Line {
match self { match self {
Line::Status(s) => write!(f, "{}", s), Line::Status(s) => write!(f, "{}", s),
Line::Image(i) => write!(f, "{}", i), Line::Image(i) => write!(f, "{}", i),
Line::NextPage(s) => write!(f, "{}", s),
} }
} }
} }
@ -70,7 +68,7 @@ impl TagList {
match tags.next_page() { match tags.next_page() {
Err(_) => (), Err(_) => (),
Ok(new_tags) => { Ok(new_tags) => {
lines.push(Line::NextPage(String::from("load more tags"))); lines.push(Line::Status(String::from("load more tags")));
tags = new_tags; tags = new_tags;
} }
}; };
@ -117,35 +115,24 @@ impl TagList {
match key { match key {
Key::Down => self.next(), Key::Down => self.next(),
Key::Up => self.previous(), 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<String, Error> { pub fn get_selected(&mut self) -> Result<String, Error> {
match self.state.selected() { match self.state.selected() {
None => Err(Error::NoneSelected), None => Err(Error::NoneSelected),
Some(i) => match &self.lines[i] { Some(i) if i == self.lines.len() - 1 => {
Line::Status(_) => Err(Error::SelectedStatus),
Line::Image(i) => Ok(i.tag_name.clone()),
Line::NextPage(_) => {
self.load_next_page(); self.load_next_page();
Err(Error::NextPageSelected) Err(Error::NextPageSelected)
} }
Some(i) => match &self.lines[i] {
Line::Status(_) => Err(Error::SelectedStatus),
Line::Image(i) => Ok(i.tag_name.clone()),
}, },
} }
} }
/// load new tags from the next page
fn load_next_page(&mut self) { fn load_next_page(&mut self) {
match &self.tags { match &self.tags {
Some(tags) => match tags.next_page() { Some(tags) => match tags.next_page() {
@ -176,7 +163,7 @@ impl TagList {
/// select next tag /// select next tag
fn next(&mut self) { fn next(&mut self) {
match self.state.selected() { match self.state.selected() {
None if !self.lines.is_empty() => self.state.select(Some(0)), None if self.lines.len() > 0 => self.state.select(Some(0)),
None => (), None => (),
Some(i) if i == self.lines.len() - 1 => self.state.select(Some(0)), Some(i) if i == self.lines.len() - 1 => self.state.select(Some(0)),
Some(i) => self.state.select(Some(i + 1)), Some(i) => self.state.select(Some(i + 1)),
@ -186,7 +173,7 @@ impl TagList {
/// select previous tag /// select previous tag
fn previous(&mut self) { fn previous(&mut self) {
match self.state.selected() { match self.state.selected() {
None if !self.lines.is_empty() => self.state.select(Some(self.lines.len())), None if self.lines.len() > 0 => self.state.select(Some(self.lines.len())),
None => (), None => (),
Some(i) if i == 0 => self.state.select(Some(self.lines.len() - 1)), Some(i) if i == 0 => self.state.select(Some(self.lines.len() - 1)),
Some(i) => self.state.select(Some(i - 1)), Some(i) => self.state.select(Some(i - 1)),