create new ctor for TagList

This commit is contained in:
Thomas Eppers 2021-08-29 00:23:40 +02:00
parent 7748212878
commit 30f3050c6c
3 changed files with 15 additions and 13 deletions

View File

@ -3,5 +3,5 @@ mod ui;
mod widget;
fn main() {
ui::Ui::run();
ui::Ui::run("rocketchat/rocket.chat");
}

View File

@ -11,7 +11,6 @@ use tui::Terminal;
use crate::tags;
use crate::widget::repo_entry;
use crate::widget::tag_list;
// use crate::widget::Widget;
pub struct Ui {
state: State,
@ -26,12 +25,13 @@ pub enum State {
}
impl Ui {
pub fn run() {
pub fn run(repo_id: &str) {
let mut ui = Ui {
state: State::EditRepo,
repo: repo_entry::RepoEntry::new("This is a text"),
tags: tag_list::TagList::new(vec![String::from("editing Repository")]),
repo: repo_entry::RepoEntry::new(repo_id),
tags: tag_list::TagList::new(vec![String::from("Fetching Tags")]),
};
ui.tags = tag_list::TagList::new_with_result(tags::Tags::get_tags(ui.repo.get()));
//setup tui
let stdout = io::stdout().into_raw_mode().unwrap();
@ -74,14 +74,8 @@ impl Ui {
Ok(Key::Char('\n')) => {
if ui.state == State::EditRepo {
ui.repo.confirm();
match tags::Tags::get_tags(ui.repo.get()) {
Ok(lines) => ui.tags = tag_list::TagList::new(lines),
Err(_) => {
ui.tags = tag_list::TagList::new_line(
"Error fetich tags. Is there a typo in the Repository?",
);
}
}
ui.tags =
tag_list::TagList::new_with_result(tags::Tags::get_tags(ui.repo.get()));
}
}
Ok(Key::Char(key)) => {

View File

@ -2,6 +2,7 @@ use termion::event::Key;
use tui::style::{Color, Style};
use tui::widgets::{Block, Borders, List, ListState};
use crate::tags::Error;
use crate::ui::State;
pub struct TagList {
@ -24,6 +25,13 @@ impl TagList {
}
}
pub fn new_with_result(result: Result<Vec<String>, Error>) -> Self {
match result {
Ok(lines) => Self::new(lines),
Err(_) => Self::new_line("Error fetching tags. Is there a typo in the Repository?"),
}
}
pub fn render(&mut self, state: &State) -> (List, &mut ListState) {
let border_style = if state == &State::SelectTag {
Style::default().fg(Color::Green)