created specific UiEvents; moved code from asnyc_tag_list to ui files
This commit is contained in:
parent
1f2a098c26
commit
646e48a208
@ -50,7 +50,8 @@ impl std::iter::Iterator for State {
|
||||
|
||||
pub enum UiEvent {
|
||||
NewRepo(String),
|
||||
TagInput(termion::event::Key),
|
||||
TagPrevious,
|
||||
TagNext,
|
||||
Quit,
|
||||
}
|
||||
|
||||
@ -69,23 +70,25 @@ impl Ui {
|
||||
let mut ui = ui.lock().unwrap();
|
||||
ui.tags = list;
|
||||
}
|
||||
Ok(UiEvent::TagInput(key)) => {
|
||||
let (fetch_new, mut tags) = {
|
||||
let mut ui_data = ui.lock().unwrap();
|
||||
if (key == Key::Down || key == Key::Char('j'))
|
||||
&& ui_data.tags.at_end_of_list()
|
||||
{
|
||||
ui_data.info.set_text("Fetching more tags...");
|
||||
(true, ui_data.tags.clone())
|
||||
Ok(UiEvent::TagPrevious) => {
|
||||
let mut ui = ui.lock().unwrap();
|
||||
ui.tags.previous();
|
||||
}
|
||||
Ok(UiEvent::TagNext) => {
|
||||
let (fetched_new_tags, mut tags) = {
|
||||
let mut ui = ui.lock().unwrap();
|
||||
if ui.tags.at_end_of_list() {
|
||||
ui.info.set_text("Fetching more tags...");
|
||||
(true, ui.tags.clone())
|
||||
} else {
|
||||
(false, ui_data.tags.clone())
|
||||
(false, ui.tags.clone())
|
||||
}
|
||||
};
|
||||
tags.handle_input(key).await;
|
||||
tags.next().await;
|
||||
let mut ui = ui.lock().unwrap();
|
||||
ui.tags = tags;
|
||||
ui.details = ui.tags.create_detail_widget();
|
||||
if fetch_new {
|
||||
if fetched_new_tags {
|
||||
ui.info.set_text("Fetching tags done");
|
||||
}
|
||||
}
|
||||
@ -178,11 +181,11 @@ impl Ui {
|
||||
ui_data.repo.handle_input(Key::Backspace);
|
||||
}
|
||||
Ok(Key::Up) | Ok(Key::Char('k')) if ui_data.state == State::SelectTag => {
|
||||
sender.send(UiEvent::TagInput(Key::Up)).unwrap();
|
||||
sender.send(UiEvent::TagPrevious).unwrap();
|
||||
ui_data.details = ui_data.tags.create_detail_widget();
|
||||
}
|
||||
Ok(Key::Down) | Ok(Key::Char('j')) if ui_data.state == State::SelectTag => {
|
||||
sender.send(UiEvent::TagInput(Key::Down)).unwrap();
|
||||
sender.send(UiEvent::TagNext).unwrap();
|
||||
ui_data.details = ui_data.tags.create_detail_widget();
|
||||
}
|
||||
Ok(Key::Char(key)) if ui_data.state == State::EditRepo => {
|
||||
|
@ -56,7 +56,8 @@ impl std::iter::Iterator for State {
|
||||
|
||||
pub enum UiEvent {
|
||||
NewRepo(String),
|
||||
TagInput(termion::event::Key),
|
||||
TagPrevious,
|
||||
TagNext,
|
||||
Quit,
|
||||
}
|
||||
|
||||
@ -75,23 +76,25 @@ impl Ui {
|
||||
let mut ui = ui.lock().unwrap();
|
||||
ui.tags = list;
|
||||
}
|
||||
Ok(UiEvent::TagInput(key)) => {
|
||||
let (fetch_new, mut tags) = {
|
||||
let mut ui_data = ui.lock().unwrap();
|
||||
if (key == Key::Down || key == Key::Char('j'))
|
||||
&& ui_data.tags.at_end_of_list()
|
||||
{
|
||||
ui_data.info.set_text("Fetching more tags...");
|
||||
(true, ui_data.tags.clone())
|
||||
Ok(UiEvent::TagPrevious) => {
|
||||
let mut ui = ui.lock().unwrap();
|
||||
ui.tags.previous();
|
||||
}
|
||||
Ok(UiEvent::TagNext) => {
|
||||
let (fetched_new_tags, mut tags) = {
|
||||
let mut ui = ui.lock().unwrap();
|
||||
if ui.tags.at_end_of_list() {
|
||||
ui.info.set_text("Fetching more tags...");
|
||||
(true, ui.tags.clone())
|
||||
} else {
|
||||
(false, ui_data.tags.clone())
|
||||
(false, ui.tags.clone())
|
||||
}
|
||||
};
|
||||
tags.handle_input(key).await;
|
||||
tags.next().await;
|
||||
let mut ui = ui.lock().unwrap();
|
||||
ui.tags = tags;
|
||||
ui.details = ui.tags.create_detail_widget();
|
||||
if fetch_new {
|
||||
if fetched_new_tags {
|
||||
ui.info.set_text("Fetching tags done");
|
||||
}
|
||||
}
|
||||
@ -255,10 +258,10 @@ impl Ui {
|
||||
}
|
||||
}
|
||||
Ok(Key::Up) | Ok(Key::Char('k')) if ui_data.state == State::SelectTag => {
|
||||
sender.send(UiEvent::TagInput(Key::Up)).unwrap();
|
||||
sender.send(UiEvent::TagPrevious).unwrap();
|
||||
}
|
||||
Ok(Key::Down) | Ok(Key::Char('j')) if ui_data.state == State::SelectTag => {
|
||||
sender.send(UiEvent::TagInput(Key::Down)).unwrap();
|
||||
sender.send(UiEvent::TagNext).unwrap();
|
||||
}
|
||||
Ok(Key::Char(key)) if ui_data.state == State::EditRepo => {
|
||||
ui_data.info.set_text("Editing Repository");
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::fmt;
|
||||
|
||||
use termion::event::Key;
|
||||
use tui::style::{Color, Style};
|
||||
use tui::widgets::{Block, Borders, List, ListState};
|
||||
|
||||
@ -137,24 +136,6 @@ impl TagList {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_input(&mut self, key: termion::event::Key) {
|
||||
match key {
|
||||
Key::Down => self.next().await,
|
||||
Key::Up => self.previous(),
|
||||
Key::Char('\n') => self.select().await,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
/// loads new tags when matching line is selected
|
||||
async fn select(&mut self) {
|
||||
if let Some(i) = self.state.selected() {
|
||||
if let Line::NextPage(_) = &self.lines[i] {
|
||||
self.load_next_page().await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_selected(&mut self) -> Result<String, Error> {
|
||||
match self.state.selected() {
|
||||
None => Err(Error::NoneSelected),
|
||||
@ -167,7 +148,7 @@ impl TagList {
|
||||
}
|
||||
|
||||
/// load new tags from the next page
|
||||
async fn load_next_page(&mut self) {
|
||||
pub async fn load_next_page(&mut self) {
|
||||
match &self.tags {
|
||||
Some(tags) => match tags.next_page().await {
|
||||
None => (),
|
||||
@ -200,7 +181,7 @@ impl TagList {
|
||||
}
|
||||
|
||||
/// select next tag
|
||||
async fn next(&mut self) {
|
||||
pub async fn next(&mut self) {
|
||||
if let Some(Line::Status(_)) = self.lines.get(0) {
|
||||
return;
|
||||
}
|
||||
@ -213,7 +194,7 @@ impl TagList {
|
||||
}
|
||||
|
||||
/// select previous tag
|
||||
fn previous(&mut self) {
|
||||
pub fn previous(&mut self) {
|
||||
if let Some(Line::Status(_)) = self.lines.get(0) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user