changed handling input a bit; j and k can select now; show more info when
fetching tags
This commit is contained in:
parent
935a9e5709
commit
70cf17f1c7
@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
use std::{io, thread};
|
use std::{io, thread};
|
||||||
|
|
||||||
use crate::repository;
|
use crate::repository;
|
||||||
use crate::widget::async_tag_list;
|
use crate::widget::async_tag_list::{self, TagList};
|
||||||
use crate::widget::info;
|
use crate::widget::info;
|
||||||
use crate::widget::repo_entry;
|
use crate::widget::repo_entry;
|
||||||
use crate::widget::service_switcher;
|
use crate::widget::service_switcher;
|
||||||
@ -18,7 +18,7 @@ use crate::Opt;
|
|||||||
pub struct Ui {
|
pub struct Ui {
|
||||||
state: State,
|
state: State,
|
||||||
repo: repo_entry::RepoEntry,
|
repo: repo_entry::RepoEntry,
|
||||||
tags: async_tag_list::TagList,
|
tags: TagList,
|
||||||
services: service_switcher::ServiceSwitcher,
|
services: service_switcher::ServiceSwitcher,
|
||||||
details: crate::widget::details::Details,
|
details: crate::widget::details::Details,
|
||||||
info: info::Info,
|
info: info::Info,
|
||||||
@ -67,7 +67,11 @@ impl Ui {
|
|||||||
match event.recv() {
|
match event.recv() {
|
||||||
Ok(UiEvent::Quit) => break,
|
Ok(UiEvent::Quit) => break,
|
||||||
Ok(UiEvent::NewRepo(name)) => {
|
Ok(UiEvent::NewRepo(name)) => {
|
||||||
let list = async_tag_list::TagList::with_repo_name(name).await;
|
{
|
||||||
|
let mut ui = ui.lock().unwrap();
|
||||||
|
ui.tags = TagList::with_status("fetching new tags...");
|
||||||
|
}
|
||||||
|
let list = TagList::with_repo_name(name).await;
|
||||||
let mut ui = ui.lock().unwrap();
|
let mut ui = ui.lock().unwrap();
|
||||||
ui.tags = list;
|
ui.tags = list;
|
||||||
}
|
}
|
||||||
@ -79,6 +83,7 @@ impl Ui {
|
|||||||
tags.handle_input(key).await;
|
tags.handle_input(key).await;
|
||||||
let mut ui = ui.lock().unwrap();
|
let mut ui = ui.lock().unwrap();
|
||||||
ui.tags = tags;
|
ui.tags = tags;
|
||||||
|
ui.details = ui.tags.create_detail_widget();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let mut ui = ui.lock().unwrap();
|
let mut ui = ui.lock().unwrap();
|
||||||
@ -94,7 +99,7 @@ impl Ui {
|
|||||||
let ui = Arc::new(Mutex::new(Ui {
|
let ui = Arc::new(Mutex::new(Ui {
|
||||||
state: State::SelectService,
|
state: State::SelectService,
|
||||||
repo: repo_entry::RepoEntry::new(repo_id),
|
repo: repo_entry::RepoEntry::new(repo_id),
|
||||||
tags: async_tag_list::TagList::with_status("no tags"),
|
tags: TagList::with_status("no tags"),
|
||||||
services: switcher,
|
services: switcher,
|
||||||
details: crate::widget::details::Details::new(),
|
details: crate::widget::details::Details::new(),
|
||||||
info: info::Info::new("Select image or edit Repository"),
|
info: info::Info::new("Select image or edit Repository"),
|
||||||
@ -179,35 +184,24 @@ impl Ui {
|
|||||||
ui_data.repo.confirm();
|
ui_data.repo.confirm();
|
||||||
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
||||||
}
|
}
|
||||||
Ok(Key::Char('\n')) => match ui_data.state {
|
Ok(Key::Char('\n')) if ui_data.state == State::SelectTag => {
|
||||||
State::EditRepo => {
|
let mut repo = ui_data.repo.get();
|
||||||
ui_data.repo.confirm();
|
let tag = match ui_data.tags.get_selected() {
|
||||||
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
Err(async_tag_list::Error::NextPageSelected) => continue,
|
||||||
}
|
Err(e) => {
|
||||||
State::SelectTag => {
|
ui_data.info.set_info(&format!("{}", e));
|
||||||
let mut repo = ui_data.repo.get();
|
continue;
|
||||||
let tag = match ui_data.tags.get_selected() {
|
}
|
||||||
Err(async_tag_list::Error::NextPageSelected) => continue,
|
Ok(tag) => tag,
|
||||||
Err(e) => {
|
};
|
||||||
ui_data.info.set_info(&format!("{}", e));
|
repo.push(':');
|
||||||
continue;
|
repo.push_str(&tag);
|
||||||
}
|
ui_data.services.change_current_line(repo);
|
||||||
Ok(tag) => tag,
|
}
|
||||||
};
|
Ok(Key::Char('\n')) if ui_data.state == State::EditRepo => {
|
||||||
repo.push(':');
|
ui_data.repo.confirm();
|
||||||
repo.push_str(&tag);
|
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
||||||
ui_data.services.change_current_line(repo);
|
}
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
Ok(Key::Char(key)) => match ui_data.state {
|
|
||||||
State::SelectService => (),
|
|
||||||
State::EditRepo => {
|
|
||||||
ui_data.info.set_text("Editing Repository");
|
|
||||||
ui_data.repo.handle_input(Key::Char(key));
|
|
||||||
}
|
|
||||||
State::SelectTag => (),
|
|
||||||
},
|
|
||||||
Ok(Key::Backspace) => match ui_data.state {
|
Ok(Key::Backspace) => match ui_data.state {
|
||||||
State::SelectService => (),
|
State::SelectService => (),
|
||||||
State::EditRepo => {
|
State::EditRepo => {
|
||||||
@ -216,59 +210,54 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
State::SelectTag => (),
|
State::SelectTag => (),
|
||||||
},
|
},
|
||||||
Ok(Key::Up) => {
|
Ok(Key::Up) | Ok(Key::Char('k'))
|
||||||
let state = ui_data.state.clone();
|
if ui_data.state == State::SelectService
|
||||||
match state {
|
&& ui_data.services.find_previous_match() =>
|
||||||
State::SelectService if ui_data.services.find_previous_match() => {
|
{
|
||||||
match ui_data.services.extract_repo() {
|
match ui_data.services.extract_repo() {
|
||||||
Err(e) => ui_data.info.set_info(&format!("{}", e)),
|
Err(e) => ui_data.info.set_info(&format!("{}", e)),
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
let repo = match repository::check_repo(&s) {
|
let repo = match repository::check_repo(&s) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
ui_data.info.set_info(&format!("{}", e));
|
ui_data.info.set_info(&format!("{}", e));
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
Ok(s) => s,
|
|
||||||
};
|
|
||||||
ui_data.repo.set(repo.to_string());
|
|
||||||
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
Ok(s) => s,
|
||||||
}
|
};
|
||||||
State::SelectService | State::EditRepo => (),
|
ui_data.repo.set(repo.to_string());
|
||||||
State::SelectTag => {
|
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
||||||
sender.send(UiEvent::TagInput(Key::Up)).unwrap();
|
|
||||||
ui_data.details = ui_data.tags.create_detail_widget();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Key::Down) => {
|
Ok(Key::Down) | Ok(Key::Char('j'))
|
||||||
let state = ui_data.state.clone();
|
if ui_data.state == State::SelectService
|
||||||
match state {
|
&& ui_data.services.find_next_match() =>
|
||||||
State::SelectService if ui_data.services.find_next_match() => {
|
{
|
||||||
match ui_data.services.extract_repo() {
|
match ui_data.services.extract_repo() {
|
||||||
Err(e) => ui_data.info.set_info(&format!("{}", e)),
|
Err(e) => ui_data.info.set_info(&format!("{}", e)),
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
let repo = match repository::check_repo(&s) {
|
let repo = match repository::check_repo(&s) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
ui_data.info.set_info(&format!("{}", e));
|
ui_data.info.set_info(&format!("{}", e));
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
Ok(s) => s,
|
|
||||||
};
|
|
||||||
ui_data.repo.set(repo.to_string());
|
|
||||||
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
Ok(s) => s,
|
||||||
}
|
};
|
||||||
State::SelectService => (),
|
ui_data.repo.set(repo.to_string());
|
||||||
State::EditRepo => (),
|
sender.send(UiEvent::NewRepo(ui_data.repo.get())).unwrap();
|
||||||
State::SelectTag => {
|
|
||||||
sender.send(UiEvent::TagInput(Key::Down)).unwrap();
|
|
||||||
ui_data.details = ui_data.tags.create_detail_widget();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(Key::Up) | Ok(Key::Char('k')) if ui_data.state == State::SelectTag => {
|
||||||
|
sender.send(UiEvent::TagInput(Key::Up)).unwrap();
|
||||||
|
}
|
||||||
|
Ok(Key::Down) | Ok(Key::Char('j')) if ui_data.state == State::SelectTag => {
|
||||||
|
sender.send(UiEvent::TagInput(Key::Down)).unwrap();
|
||||||
|
}
|
||||||
|
Ok(Key::Char(key)) if ui_data.state == State::EditRepo => {
|
||||||
|
ui_data.info.set_text("Editing Repository");
|
||||||
|
ui_data.repo.handle_input(Key::Char(key));
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user