Compare commits

...

5 Commits

Author SHA1 Message Date
Thomas Eppers
3bf2359392 added the ability to instantly delete default text in RepoEntry; simplified some code
All checks were successful
continuous-integration/woodpecker the build was successful
2021-11-25 17:08:22 +01:00
Thomas Eppers
bb5ea3a993 add variant information back to details view 2021-11-25 16:42:26 +01:00
Thomas Eppers
7d9cc21b6e removed old code 2021-11-25 14:06:43 +01:00
Thomas Eppers
e3865da563 removed old code; switched output to english 2021-11-25 14:02:56 +01:00
Thomas Eppers
881423e461 updated screenshot 2021-11-25 13:37:46 +01:00
8 changed files with 40 additions and 62 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -27,11 +27,8 @@ impl Images {
.images .images
.iter() .iter()
.map(|d| super::TagDetails { .map(|d| super::TagDetails {
arch: Some(format!( arch: Some(d.architecture.clone()),
"{}{}", variant: Some(d.variant.clone().unwrap_or_default()),
d.architecture.clone(),
d.variant.clone().unwrap_or_default()
)),
os: Some(d.os.clone()), os: Some(d.os.clone()),
size: Some(d.size), size: Some(d.size),
}) })

View File

@ -33,7 +33,6 @@ impl Ghcr {
.header(reqwest::header::AUTHORIZATION, format!("Bearer {}", token)) .header(reqwest::header::AUTHORIZATION, format!("Bearer {}", token))
.send() .send()
{ {
// let response = match reqwest::blocking::get(url) {
Ok(result) => result, Ok(result) => result,
Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))), Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))),
}; };

View File

@ -30,25 +30,11 @@ impl fmt::Display for Error {
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub struct TagDetails { pub struct TagDetails {
pub arch: Option<String>, pub arch: Option<String>,
pub variant: Option<String>,
pub os: Option<String>, pub os: Option<String>,
pub size: Option<usize>, pub size: Option<usize>,
} }
impl fmt::Display for TagDetails {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let size = match self.size {
None => "".to_string(),
Some(s) => (s / 1024 / 1024).to_string(),
};
write!(
f,
"{}|{}MB",
self.arch.as_ref().unwrap_or(&"".to_string()),
size
)
}
}
#[derive(Clone)] #[derive(Clone)]
pub struct Tag { pub struct Tag {
name: String, name: String,
@ -62,22 +48,13 @@ impl Tag {
} }
pub fn get_name_with_details(&self) -> String { pub fn get_name_with_details(&self) -> String {
//architecture infos
let mut arch = String::new();
for image in self.details.iter().take(1) {
arch.push_str(&format!("{}", image));
}
for image in self.details.iter().skip(1) {
arch.push_str(&format!(", {}", image));
}
let dif = match &self.last_updated { let dif = match &self.last_updated {
None => "".to_string(), None => "".to_string(),
Some(last_updated) => { Some(last_updated) => {
let now = chrono::Utc::now(); let now = chrono::Utc::now();
let rfc3339 = DateTime::parse_from_rfc3339(last_updated).unwrap(); let rfc3339 = DateTime::parse_from_rfc3339(last_updated).unwrap();
let dif = now - rfc3339.with_timezone(&chrono::Utc); let dif = now - rfc3339.with_timezone(&chrono::Utc);
format!(" vor {}", format_time_nice(dif)) format!(", {} old", format_time_nice(dif))
} }
}; };
@ -135,23 +112,23 @@ impl Repo {
/// converts a given duration to a readable string /// converts a given duration to a readable string
fn format_time_nice(time: chrono::Duration) -> String { fn format_time_nice(time: chrono::Duration) -> String {
if time.num_weeks() == 52 { if time.num_weeks() == 52 {
format!("{} Jahr", (time.num_weeks() / 52) as i32) format!("{} Year", (time.num_weeks() / 52) as i32)
} else if time.num_weeks() > 103 { } else if time.num_weeks() > 103 {
format!("{} Jahren", (time.num_weeks() / 52) as i32) format!("{} Years", (time.num_weeks() / 52) as i32)
} else if time.num_days() == 1 { } else if time.num_days() == 1 {
format!("{} Tag", time.num_days()) format!("{} Day", time.num_days())
} else if time.num_days() > 1 { } else if time.num_days() > 1 {
format!("{} Tagen", time.num_days()) format!("{} Days", time.num_days())
} else if time.num_hours() == 1 { } else if time.num_hours() == 1 {
format!("{} Stunde", time.num_hours()) format!("{} Hour", time.num_hours())
} else if time.num_hours() > 1 { } else if time.num_hours() > 1 {
format!("{} Stunden", time.num_hours()) format!("{} Hours", time.num_hours())
} else if time.num_minutes() == 1 { } else if time.num_minutes() == 1 {
format!("{} Minute", time.num_minutes()) format!("{} Minute", time.num_minutes())
} else if time.num_minutes() > 1 { } else if time.num_minutes() > 1 {
format!("{} Minuten", time.num_minutes()) format!("{} Minutes", time.num_minutes())
} else { } else {
format!("{} Sekunden", time.num_seconds()) format!("{} Seconds", time.num_seconds())
} }
} }

View File

@ -54,12 +54,9 @@ impl std::iter::Iterator for State {
impl Ui { impl Ui {
pub fn run(opt: &Opt) { pub fn run(opt: &Opt) {
let (repo_id, load_repo) = match &opt.repo { let repo_id = match &opt.repo {
None => ( None => None,
"enter a repository here or select one from file widget", Some(repo) => Some(String::as_str(repo)),
false,
),
Some(repo) => (String::as_str(repo), true),
}; };
let mut ui = Ui { let mut ui = Ui {
@ -71,7 +68,7 @@ impl Ui {
info: info::Info::new("Select image of edit Repository"), info: info::Info::new("Select image of edit Repository"),
}; };
if load_repo { if opt.repo.is_none() {
ui.tags = tag_list::TagList::with_repo_name(ui.repo.get()); ui.tags = tag_list::TagList::with_repo_name(ui.repo.get());
} }

View File

@ -49,26 +49,21 @@ pub struct NoYaml {
impl NoYaml { impl NoYaml {
pub fn run(opt: &Opt) { pub fn run(opt: &Opt) {
let (repo, load_repo) = match &opt.repo { let repo_id = match &opt.repo {
None => ( None => None,
repo_entry::RepoEntry::new( Some(repo) => Some(String::as_str(repo)),
"enter a repository or select one from docker-compose.yml",
),
false,
),
Some(repo_id) => (repo_entry::RepoEntry::new(repo_id), true),
}; };
let mut ui = NoYaml { let mut ui = NoYaml {
state: State::EditRepo, state: State::EditRepo,
repo, repo: repo_entry::RepoEntry::new(repo_id),
tags: tag_list::TagList::with_status("Tags are empty"), tags: tag_list::TagList::with_status("Tags are empty"),
details: details::Details::new(), details: details::Details::new(),
info: info::Info::new("could not find a docker-compose file"), info: info::Info::new("could not find a docker-compose file"),
}; };
// load tags if a repository was given thorugh paramter // load tags if a repository was given thorugh paramter
if load_repo { if opt.repo.is_none() {
ui.tags = tag_list::TagList::with_repo_name(ui.repo.get()); ui.tags = tag_list::TagList::with_repo_name(ui.repo.get());
} }

View File

@ -27,7 +27,11 @@ impl Details {
for d in &self.details { for d in &self.details {
lines.push(format!( lines.push(format!(
"{:^10}|{:^6}|{:^6}", "{:^10}|{:^6}|{:^6}",
d.arch.clone().unwrap_or_default(), format!(
"{}{}",
d.arch.clone().unwrap_or_default(),
d.variant.clone().unwrap_or_default()
),
d.os.clone().unwrap_or_default(), d.os.clone().unwrap_or_default(),
format!("{}MB", d.size.unwrap_or_default() / 1024 / 1024) format!("{}MB", d.size.unwrap_or_default() / 1024 / 1024)
)); ));

View File

@ -7,14 +7,17 @@ pub struct RepoEntry {
text: String, text: String,
old_text: String, old_text: String,
changed: bool, changed: bool,
default_text: bool,
} }
impl RepoEntry { impl RepoEntry {
pub fn new(text: &str) -> Self { pub fn new(text: Option<&str>) -> Self {
let default_text = "enter a repository here or select one from file widget";
Self { Self {
text: String::from(text), text: String::from(text.unwrap_or(default_text)),
old_text: String::from(text), old_text: String::from(text.unwrap_or(default_text)),
changed: false, changed: false,
default_text: text.is_none(),
} }
} }
@ -56,10 +59,16 @@ impl RepoEntry {
Key::Char(c) => { Key::Char(c) => {
self.text.push(c); self.text.push(c);
self.changed = true; self.changed = true;
self.default_text = false;
} }
Key::Backspace => { Key::Backspace => {
self.text.pop(); if self.default_text {
self.changed = true; self.text = String::new();
self.changed = true;
} else {
self.text.pop();
self.changed = true;
}
} }
Key::Esc => { Key::Esc => {
self.text = self.old_text.clone(); self.text = self.old_text.clone();