Compare commits
2 Commits
c9a8c637c4
...
45f2bb64b0
Author | SHA1 | Date | |
---|---|---|---|
|
45f2bb64b0 | ||
|
a718f6f8fb |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -673,7 +673,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reel-moby"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
|
@ -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
|
||||
|
@ -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> {
|
||||
let repo = repo.trim();
|
||||
let split_repo: Vec<&str> = repo.split("/").collect();
|
||||
let split_repo: Vec<&str> = repo.split('/').collect();
|
||||
match split_repo.len() {
|
||||
1 => {
|
||||
let regex = regex::Regex::new(r"[a-z0-9]+").unwrap();
|
||||
|
@ -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) => {
|
||||
@ -129,7 +128,7 @@ impl Ui {
|
||||
}
|
||||
Ok(tag) => tag,
|
||||
};
|
||||
repo.push_str(":");
|
||||
repo.push(':');
|
||||
repo.push_str(&tag);
|
||||
ui.services.change_current_line(repo);
|
||||
}
|
||||
|
@ -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 => {
|
||||
|
@ -104,10 +104,7 @@ impl ServiceSwitcher {
|
||||
|
||||
/// finds the next image tag in given file
|
||||
pub fn find_next_match(&mut self) -> bool {
|
||||
let current_line: usize = match self.state.selected() {
|
||||
None => 0,
|
||||
Some(i) => i,
|
||||
};
|
||||
let current_line: usize = self.state.selected().unwrap_or(0);
|
||||
|
||||
let mut i = (current_line + 1) % self.list.len();
|
||||
loop {
|
||||
@ -131,10 +128,7 @@ impl ServiceSwitcher {
|
||||
|
||||
/// finds the previous image tag in given file
|
||||
pub fn find_previous_match(&mut self) -> bool {
|
||||
let current_line: usize = match self.state.selected() {
|
||||
None => 0,
|
||||
Some(i) => i,
|
||||
};
|
||||
let current_line: usize = self.state.selected().unwrap_or(0);
|
||||
|
||||
let mut i: usize = if current_line == 0 {
|
||||
self.list.len() - 1
|
||||
@ -165,10 +159,10 @@ impl ServiceSwitcher {
|
||||
/// return the repository from currently selected row
|
||||
pub fn extract_repo(&self) -> Result<String, Error> {
|
||||
match self.state.selected() {
|
||||
None => return Err(Error::NoneSelected),
|
||||
None => Err(Error::NoneSelected),
|
||||
Some(i) => match repo::match_yaml_image(&self.list[i]) {
|
||||
Err(_) => return Err(Error::Parsing(String::from("Nothing found"))),
|
||||
Ok((_, repo)) => return Ok(repo.to_string()),
|
||||
Err(_) => Err(Error::Parsing(String::from("Nothing found"))),
|
||||
Ok((_, repo)) => Ok(repo.to_string()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Error> {
|
||||
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() {
|
||||
@ -163,7 +176,7 @@ impl TagList {
|
||||
/// select next tag
|
||||
fn next(&mut self) {
|
||||
match self.state.selected() {
|
||||
None if self.lines.len() > 0 => self.state.select(Some(0)),
|
||||
None if !self.lines.is_empty() => self.state.select(Some(0)),
|
||||
None => (),
|
||||
Some(i) if i == self.lines.len() - 1 => self.state.select(Some(0)),
|
||||
Some(i) => self.state.select(Some(i + 1)),
|
||||
@ -173,7 +186,7 @@ impl TagList {
|
||||
/// select previous tag
|
||||
fn previous(&mut self) {
|
||||
match self.state.selected() {
|
||||
None if self.lines.len() > 0 => self.state.select(Some(self.lines.len())),
|
||||
None if !self.lines.is_empty() => self.state.select(Some(self.lines.len())),
|
||||
None => (),
|
||||
Some(i) if i == 0 => self.state.select(Some(self.lines.len() - 1)),
|
||||
Some(i) => self.state.select(Some(i - 1)),
|
||||
|
Loading…
Reference in New Issue
Block a user