Compare commits
6 Commits
6d40b03fbf
...
e1d9cbe8c9
Author | SHA1 | Date | |
---|---|---|---|
|
e1d9cbe8c9 | ||
|
987606d264 | ||
|
b59c5f4ead | ||
|
e3c6e01036 | ||
|
a725161638 | ||
|
62f784fdb9 |
@ -5,6 +5,8 @@ use crate::repository::Error;
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
struct ImageDetails {
|
||||
architecture: String,
|
||||
os: String,
|
||||
variant: Option<String>,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
@ -25,7 +27,12 @@ impl Images {
|
||||
.images
|
||||
.iter()
|
||||
.map(|d| super::TagDetails {
|
||||
arch: Some(d.architecture.clone()),
|
||||
arch: Some(format!(
|
||||
"{}{}",
|
||||
d.architecture.clone(),
|
||||
d.variant.clone().unwrap_or_default()
|
||||
)),
|
||||
os: Some(d.os.clone()),
|
||||
size: Some(d.size),
|
||||
})
|
||||
.collect(),
|
||||
|
@ -27,10 +27,11 @@ impl fmt::Display for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct TagDetails {
|
||||
arch: Option<String>,
|
||||
size: Option<usize>,
|
||||
pub arch: Option<String>,
|
||||
pub os: Option<String>,
|
||||
pub size: Option<usize>,
|
||||
}
|
||||
|
||||
impl fmt::Display for TagDetails {
|
||||
@ -69,11 +70,6 @@ impl Tag {
|
||||
for image in self.details.iter().skip(1) {
|
||||
arch.push_str(&format!(", {}", image));
|
||||
}
|
||||
let arch = if !arch.is_empty() {
|
||||
format!(" [{}]", arch)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let dif = match &self.last_updated {
|
||||
None => "".to_string(),
|
||||
@ -86,7 +82,11 @@ impl Tag {
|
||||
};
|
||||
|
||||
if dif.is_empty() {}
|
||||
format!("{}{}{}", self.name, dif, arch)
|
||||
format!("{}{}", self.name, dif)
|
||||
}
|
||||
|
||||
pub fn get_details(&self) -> &Vec<TagDetails> {
|
||||
&self.details
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ pub struct Ui {
|
||||
repo: crate::widget::repo_entry::RepoEntry,
|
||||
tags: crate::widget::tag_list::TagList,
|
||||
services: crate::widget::service_switcher::ServiceSwitcher,
|
||||
details: crate::widget::details::Details,
|
||||
info: crate::widget::info::Info,
|
||||
}
|
||||
|
||||
@ -66,6 +67,7 @@ impl Ui {
|
||||
repo: repo_entry::RepoEntry::new(repo_id),
|
||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
||||
services: service_switcher::ServiceSwitcher::new(&opt.file).unwrap(),
|
||||
details: crate::widget::details::Details::new(),
|
||||
info: info::Info::new("Select image of edit Repository"),
|
||||
};
|
||||
|
||||
@ -90,7 +92,7 @@ impl Ui {
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Min(9),
|
||||
Constraint::Length(10),
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(7),
|
||||
Constraint::Length(2),
|
||||
@ -103,7 +105,12 @@ impl Ui {
|
||||
rect.render_stateful_widget(list, chunks[0], state);
|
||||
rect.render_widget(ui.repo.render(ui.state == State::EditRepo), chunks[1]);
|
||||
let (list, state) = ui.tags.render(ui.state == State::SelectTag);
|
||||
rect.render_stateful_widget(list, chunks[2], state);
|
||||
let more_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Min(15), Constraint::Length(28)].as_ref())
|
||||
.split(chunks[2]);
|
||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||
rect.render_widget(ui.info.render(), chunks[3]);
|
||||
})
|
||||
.unwrap();
|
||||
@ -182,7 +189,10 @@ impl Ui {
|
||||
}
|
||||
State::SelectService => (),
|
||||
State::EditRepo => (),
|
||||
State::SelectTag => ui.tags.handle_input(Key::Up),
|
||||
State::SelectTag => {
|
||||
ui.tags.handle_input(Key::Up);
|
||||
ui.details = ui.tags.create_detail_widget();
|
||||
}
|
||||
},
|
||||
Ok(Key::Down) => match ui.state {
|
||||
State::SelectService if ui.services.find_next_match() => {
|
||||
@ -203,7 +213,10 @@ impl Ui {
|
||||
}
|
||||
State::SelectService => (),
|
||||
State::EditRepo => (),
|
||||
State::SelectTag => ui.tags.handle_input(Key::Down),
|
||||
State::SelectTag => {
|
||||
ui.tags.handle_input(Key::Down);
|
||||
ui.details = ui.tags.create_detail_widget();
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use tui::backend::TermionBackend;
|
||||
use tui::layout::{Constraint, Direction, Layout};
|
||||
use tui::Terminal;
|
||||
|
||||
use crate::widget::details;
|
||||
use crate::widget::info;
|
||||
use crate::widget::repo_entry;
|
||||
use crate::widget::tag_list;
|
||||
@ -42,6 +43,7 @@ pub struct NoYaml {
|
||||
state: State,
|
||||
repo: repo_entry::RepoEntry,
|
||||
tags: tag_list::TagList,
|
||||
details: details::Details,
|
||||
info: info::Info,
|
||||
}
|
||||
|
||||
@ -61,6 +63,7 @@ impl NoYaml {
|
||||
state: State::EditRepo,
|
||||
repo,
|
||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
||||
details: details::Details::new(),
|
||||
info: info::Info::new("could not find a docker-compose file"),
|
||||
};
|
||||
|
||||
@ -96,7 +99,12 @@ impl NoYaml {
|
||||
|
||||
rect.render_widget(ui.repo.render(ui.state == State::EditRepo), chunks[0]);
|
||||
let (list, state) = ui.tags.render(ui.state == State::SelectTag);
|
||||
rect.render_stateful_widget(list, chunks[1], state);
|
||||
let more_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Min(15), Constraint::Length(28)].as_ref())
|
||||
.split(chunks[1]);
|
||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||
rect.render_widget(ui.info.render(), chunks[2]);
|
||||
})
|
||||
.unwrap();
|
||||
@ -137,11 +145,17 @@ impl NoYaml {
|
||||
},
|
||||
Ok(Key::Up) => match ui.state {
|
||||
State::EditRepo => (),
|
||||
State::SelectTag => ui.tags.handle_input(Key::Up),
|
||||
State::SelectTag => {
|
||||
ui.tags.handle_input(Key::Up);
|
||||
ui.details = ui.tags.create_detail_widget();
|
||||
}
|
||||
},
|
||||
Ok(Key::Down) => match ui.state {
|
||||
State::EditRepo => (),
|
||||
State::SelectTag => ui.tags.handle_input(Key::Down),
|
||||
State::SelectTag => {
|
||||
ui.tags.handle_input(Key::Down);
|
||||
ui.details = ui.tags.create_detail_widget();
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
57
src/widget/details.rs
Normal file
57
src/widget/details.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use tui::style::{Color, Style};
|
||||
use tui::widgets::{Block, Borders, List};
|
||||
|
||||
use crate::repository;
|
||||
|
||||
pub struct Details {
|
||||
details: Vec<repository::TagDetails>,
|
||||
}
|
||||
|
||||
impl Details {
|
||||
pub fn new() -> Self {
|
||||
Self { details: vec![] }
|
||||
}
|
||||
|
||||
pub fn with_list(details: &[crate::repository::TagDetails]) -> Self {
|
||||
let mut detail = Self {
|
||||
details: details.to_owned(),
|
||||
};
|
||||
|
||||
detail.details.sort_by(|a, b| a.arch.cmp(&b.arch));
|
||||
detail.details.dedup();
|
||||
detail
|
||||
}
|
||||
|
||||
pub fn get_details(&self) -> Vec<String> {
|
||||
let mut lines = vec![format!("{:^10}|{:^6}|{:^6}", "ARCH", "OS", "SIZE")];
|
||||
for d in &self.details {
|
||||
lines.push(format!(
|
||||
"{:^10}|{:^6}|{:^6}",
|
||||
d.arch.clone().unwrap_or_default(),
|
||||
d.os.clone().unwrap_or_default(),
|
||||
format!("{}MB", d.size.unwrap_or_default() / 1024 / 1024)
|
||||
));
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
pub fn render(&self) -> List {
|
||||
let items: Vec<tui::widgets::ListItem> = self
|
||||
.get_details()
|
||||
.iter()
|
||||
.map(|l| {
|
||||
tui::widgets::ListItem::new(l.to_string())
|
||||
.style(Style::default().fg(Color::White).bg(Color::Black))
|
||||
})
|
||||
.collect();
|
||||
|
||||
List::new(items)
|
||||
.block(
|
||||
Block::default()
|
||||
.title("Details")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default()),
|
||||
)
|
||||
.style(Style::default().fg(Color::White).bg(Color::Black))
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod details;
|
||||
pub mod info;
|
||||
pub mod repo_entry;
|
||||
pub mod service_switcher;
|
||||
|
@ -116,6 +116,18 @@ impl TagList {
|
||||
(items, &mut self.state)
|
||||
}
|
||||
|
||||
pub fn create_detail_widget(&self) -> crate::widget::details::Details {
|
||||
use crate::widget::details::Details;
|
||||
|
||||
match self.state.selected() {
|
||||
None => Details::new(),
|
||||
Some(i) => match &self.lines[i] {
|
||||
Line::Image(t) => Details::with_list(t.get_details()),
|
||||
_ => Details::new(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_input(&mut self, key: termion::event::Key) {
|
||||
match key {
|
||||
Key::Down => self.next(),
|
||||
|
Loading…
Reference in New Issue
Block a user