Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8f0eb3db4f | ||
|
13350f872a | ||
|
c8915f828f | ||
|
88070489f3 | ||
|
d1ef5c6755 | ||
|
e98c5e7a12 | ||
|
6c83683a4a | ||
|
3bf2359392 | ||
|
bb5ea3a993 | ||
|
7d9cc21b6e | ||
|
e3865da563 | ||
|
881423e461 | ||
|
b6dbcd8eba | ||
|
7720ed3102 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -673,7 +673,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reel-moby"
|
name = "reel-moby"
|
||||||
version = "1.0.0"
|
version = "1.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "reel-moby"
|
name = "reel-moby"
|
||||||
version = "1.0.0"
|
version = "1.2.1"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 64 KiB |
28
src/common/display_duration_ext.rs
Normal file
28
src/common/display_duration_ext.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
pub trait DisplayDurationExt {
|
||||||
|
/// displays a duration in a human readable form
|
||||||
|
fn display(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DisplayDurationExt for chrono::Duration {
|
||||||
|
fn display(&self) -> String {
|
||||||
|
if self.num_weeks() == 52 {
|
||||||
|
format!("{} Year", (self.num_weeks() / 52) as i32)
|
||||||
|
} else if self.num_weeks() > 103 {
|
||||||
|
format!("{} Years", (self.num_weeks() / 52) as i32)
|
||||||
|
} else if self.num_days() == 1 {
|
||||||
|
format!("{} Day", self.num_days())
|
||||||
|
} else if self.num_days() > 1 {
|
||||||
|
format!("{} Days", self.num_days())
|
||||||
|
} else if self.num_hours() == 1 {
|
||||||
|
format!("{} Hour", self.num_hours())
|
||||||
|
} else if self.num_hours() > 1 {
|
||||||
|
format!("{} Hours", self.num_hours())
|
||||||
|
} else if self.num_minutes() == 1 {
|
||||||
|
format!("{} Minute", self.num_minutes())
|
||||||
|
} else if self.num_minutes() > 1 {
|
||||||
|
format!("{} Minutes", self.num_minutes())
|
||||||
|
} else {
|
||||||
|
format!("{} Seconds", self.num_seconds())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
src/common/mod.rs
Normal file
1
src/common/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod display_duration_ext;
|
@ -1,6 +1,7 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
mod common;
|
||||||
mod repo;
|
mod repo;
|
||||||
mod repository;
|
mod repository;
|
||||||
mod ui;
|
mod ui;
|
||||||
@ -9,10 +10,6 @@ mod widget;
|
|||||||
/// helps you searching or updating tags of your used docker images
|
/// helps you searching or updating tags of your used docker images
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
/// Show architectures of images and their sizes
|
|
||||||
#[structopt(short, long)]
|
|
||||||
verbose: bool,
|
|
||||||
|
|
||||||
/// A custom path to a docker-compose file
|
/// A custom path to a docker-compose file
|
||||||
#[structopt(short, long, parse(from_os_str))]
|
#[structopt(short, long, parse(from_os_str))]
|
||||||
file: Option<PathBuf>,
|
file: Option<PathBuf>,
|
||||||
|
113
src/repo.rs
113
src/repo.rs
@ -30,7 +30,7 @@ pub enum Repo {
|
|||||||
/// the second &str will the the identifier for the image
|
/// the second &str will the the identifier for the image
|
||||||
pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
|
pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\./:]+)").unwrap();
|
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\-\./:]+)").unwrap();
|
||||||
}
|
}
|
||||||
let caps = match REGEX.captures(input) {
|
let caps = match REGEX.captures(input) {
|
||||||
Some(caps) => caps,
|
Some(caps) => caps,
|
||||||
@ -103,58 +103,79 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_repo_without_tag() {
|
fn test_split_repo_without_tag() {
|
||||||
use crate::repo::split_repo_without_tag as test_fn;
|
let input: Vec<(&str, Result<Repo, Error>)> = vec![
|
||||||
assert_eq!(test_fn(""), Err(Error::MisformedInput));
|
("", Err(Error::MisformedInput)),
|
||||||
assert_eq!(test_fn("NGINX"), Err(Error::MisformedInput));
|
("NGINX", Err(Error::MisformedInput)),
|
||||||
assert_eq!(test_fn("nginx"), Ok(Repo::Project("nginx".into())));
|
("nginx", Ok(Repo::Project("nginx".into()))),
|
||||||
assert_eq!(
|
(
|
||||||
test_fn("library/nginx"),
|
"library/nginx",
|
||||||
Ok(Repo::WithOrga("library".into(), "nginx".into()))
|
Ok(Repo::WithOrga("library".into(), "nginx".into())),
|
||||||
);
|
),
|
||||||
assert_eq!(
|
(
|
||||||
test_fn("ghcr.io/library/nginx"),
|
"ghcr.io/library/nginx",
|
||||||
Ok(Repo::WithServer(
|
Ok(Repo::WithServer(
|
||||||
"ghcr.io".into(),
|
"ghcr.io".into(),
|
||||||
"library".into(),
|
"library".into(),
|
||||||
"nginx".into(),
|
"nginx".into(),
|
||||||
))
|
)),
|
||||||
);
|
),
|
||||||
|
(
|
||||||
|
"te-st/test-hypen",
|
||||||
|
Ok(Repo::WithOrga("te-st".into(), "test-hypen".into())),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"test/test.dot",
|
||||||
|
Ok(Repo::WithOrga("test".into(), "test.dot".into())),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
for i in input {
|
||||||
|
assert_eq!(super::split_repo_without_tag(i.0), i.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_match_yaml_image() {
|
fn test_match_yaml_image() {
|
||||||
use crate::repo::match_yaml_image as test_fn;
|
let input: Vec<(&str, Result<(&str, &str), Error>)> = vec![
|
||||||
assert_eq!(test_fn(""), Err(Error::NoTagFound));
|
("", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn("version: '2'"), Err(Error::NoTagFound));
|
("version: '2'", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn("image: "), Err(Error::NoTagFound));
|
("image: ", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn(" image: "), Err(Error::NoTagFound));
|
(" image: ", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn(" image: nginx"), Ok((" image: ", "nginx")));
|
(" image: nginx", Ok((" image: ", "nginx"))),
|
||||||
assert_eq!(
|
(" image: library/nginx", Ok((" image: ", "library/nginx"))),
|
||||||
test_fn(" image: library/nginx"),
|
(
|
||||||
Ok((" image: ", "library/nginx"))
|
" image: gchr.io/library/nginx",
|
||||||
);
|
Ok((" image: ", "gchr.io/library/nginx")),
|
||||||
assert_eq!(
|
),
|
||||||
test_fn(" image: ghcr.io/library/nginx"),
|
(" image: nginx # comment", Ok((" image: ", "nginx"))),
|
||||||
Ok((" image: ", "ghcr.io/library/nginx"))
|
(" image: test-hyphen", Ok((" image: ", "test-hyphen"))),
|
||||||
);
|
(" image: test.dot", Ok((" image: ", "test.dot"))),
|
||||||
assert_eq!(test_fn("# image: nginx"), Err(Error::NoTagFound));
|
];
|
||||||
assert_eq!(
|
|
||||||
test_fn(" image: nginx #comment"),
|
for i in input {
|
||||||
Ok((" image: ", "nginx"))
|
assert_eq!(super::match_yaml_image(i.0), i.1);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_tag_from_repo() {
|
fn test_split_tag_from_repo() {
|
||||||
use crate::repo::split_tag_from_repo as test_fn;
|
let input: Vec<(&str, Result<(&str, &str), super::Error>)> = vec![
|
||||||
assert_eq!(test_fn("nginx"), Ok(("nginx", "")));
|
("nginx", Ok(("nginx", ""))),
|
||||||
assert_eq!(test_fn("library/nginx"), Ok(("library/nginx", "")));
|
("library/nginx", Ok(("library/nginx", ""))),
|
||||||
assert_eq!(
|
("ghcr.io/library/nginx", Ok(("ghcr.io/library/nginx", ""))),
|
||||||
test_fn("ghcr.io/library/nginx"),
|
("nginx:", Ok(("nginx", ""))),
|
||||||
Ok(("ghcr.io/library/nginx", ""))
|
("nginx:1", Ok(("nginx", "1"))),
|
||||||
);
|
("nginx:latest", Ok(("nginx", "latest"))),
|
||||||
assert_eq!(test_fn("nginx:"), Ok(("nginx", "")));
|
("hy-phen:latest", Ok(("hy-phen", "latest"))),
|
||||||
assert_eq!(test_fn("nginx:1"), Ok(("nginx", "1")));
|
("test.dot:latest", Ok(("test.dot", "latest"))),
|
||||||
assert_eq!(test_fn("nginx:latest"), Ok(("nginx", "latest")));
|
(
|
||||||
|
"woodpeckerci/woodpecker-server",
|
||||||
|
Ok(("woodpeckerci/woodpecker-server", "")),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
for i in input {
|
||||||
|
assert_eq!(super::split_tag_from_repo(i.0), i.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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),
|
||||||
})
|
})
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use crate::repository::Error;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Token {
|
|
||||||
token: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct Ghcr {
|
|
||||||
tags: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ghcr {
|
|
||||||
/// fetches tag information with a repository name in the form of organization/repository or library/repository in the case of official images from docker
|
|
||||||
pub fn create_repo(repo: &str) -> Result<super::Repo, Error> {
|
|
||||||
let request_token = format!("https://ghcr.io/token?scope=repository:{}:pull", repo);
|
|
||||||
let response = match reqwest::blocking::get(request_token) {
|
|
||||||
Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))),
|
|
||||||
Ok(response) => response,
|
|
||||||
};
|
|
||||||
|
|
||||||
let token = match response.json::<Token>() {
|
|
||||||
Err(e) => return Err(Error::Converting(format!("invalid token json: {}", e))),
|
|
||||||
Ok(token) => token.token,
|
|
||||||
};
|
|
||||||
|
|
||||||
let request = format!("https://ghcr.io/v2/{}/tags/list?n=100", repo);
|
|
||||||
let client = reqwest::blocking::Client::new();
|
|
||||||
let response = match client
|
|
||||||
.get(request)
|
|
||||||
.header(reqwest::header::AUTHORIZATION, format!("Bearer {}", token))
|
|
||||||
.send()
|
|
||||||
{
|
|
||||||
// let response = match reqwest::blocking::get(url) {
|
|
||||||
Ok(result) => result,
|
|
||||||
Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))),
|
|
||||||
};
|
|
||||||
|
|
||||||
//convert it to json
|
|
||||||
let tags = match response.json::<Self>() {
|
|
||||||
Ok(result) => result,
|
|
||||||
Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))),
|
|
||||||
};
|
|
||||||
|
|
||||||
if tags.tags.is_empty() {
|
|
||||||
return Err(Error::NoTagsFound);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(super::Repo {
|
|
||||||
tags: tags
|
|
||||||
.tags
|
|
||||||
.iter()
|
|
||||||
.map(|t| super::Tag {
|
|
||||||
name: t.clone(),
|
|
||||||
details: vec![],
|
|
||||||
last_updated: None,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
next_page: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::Ghcr;
|
|
||||||
#[test]
|
|
||||||
fn test_ghcr() {
|
|
||||||
Ghcr::create_repo("ghcr.io/linuxserver/beets").unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
mod dockerhub;
|
mod dockerhub;
|
||||||
mod ghcr;
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
|
|
||||||
|
use crate::common::display_duration_ext::DisplayDurationExt;
|
||||||
use crate::repo;
|
use crate::repo;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -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", dif.display())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,10 +82,10 @@ impl Repo {
|
|||||||
Err(e) => return Err(Error::Converting(format!("{}", e))),
|
Err(e) => return Err(Error::Converting(format!("{}", e))),
|
||||||
};
|
};
|
||||||
|
|
||||||
if registry.unwrap_or_default() == "ghcr.io" {
|
if registry.unwrap_or_default().is_empty() {
|
||||||
ghcr::Ghcr::create_repo(&repo)
|
|
||||||
} else {
|
|
||||||
dockerhub::DockerHub::create_repo(&repo)
|
dockerhub::DockerHub::create_repo(&repo)
|
||||||
|
} else {
|
||||||
|
return Err(Error::Converting("This registry is not supported".into()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,29 +109,6 @@ impl Repo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// converts a given duration to a readable string
|
|
||||||
fn format_time_nice(time: chrono::Duration) -> String {
|
|
||||||
if time.num_weeks() == 52 {
|
|
||||||
format!("{} Jahr", (time.num_weeks() / 52) as i32)
|
|
||||||
} else if time.num_weeks() > 103 {
|
|
||||||
format!("{} Jahren", (time.num_weeks() / 52) as i32)
|
|
||||||
} else if time.num_days() == 1 {
|
|
||||||
format!("{} Tag", time.num_days())
|
|
||||||
} else if time.num_days() > 1 {
|
|
||||||
format!("{} Tagen", time.num_days())
|
|
||||||
} else if time.num_hours() == 1 {
|
|
||||||
format!("{} Stunde", time.num_hours())
|
|
||||||
} else if time.num_hours() > 1 {
|
|
||||||
format!("{} Stunden", time.num_hours())
|
|
||||||
} else if time.num_minutes() == 1 {
|
|
||||||
format!("{} Minute", time.num_minutes())
|
|
||||||
} else if time.num_minutes() > 1 {
|
|
||||||
format!("{} Minuten", time.num_minutes())
|
|
||||||
} else {
|
|
||||||
format!("{} Sekunden", time.num_seconds())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// checks the repo name and may add a prefix for official images
|
/// checks the repo name and may add a prefix for official images
|
||||||
pub fn check_repo(name: &str) -> Result<String, Error> {
|
pub fn check_repo(name: &str) -> Result<String, Error> {
|
||||||
let repo = match repo::split_tag_from_repo(name) {
|
let repo = match repo::split_tag_from_repo(name) {
|
||||||
|
@ -54,13 +54,7 @@ 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 = opt.repo.as_deref();
|
||||||
None => (
|
|
||||||
"enter a repository here or select one from file widget",
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
Some(repo) => (String::as_str(repo), true),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut ui = Ui {
|
let mut ui = Ui {
|
||||||
state: State::SelectService,
|
state: State::SelectService,
|
||||||
@ -71,7 +65,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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,26 +49,18 @@ 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 = opt.repo.as_deref();
|
||||||
None => (
|
|
||||||
repo_entry::RepoEntry::new(
|
|
||||||
"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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,10 +26,14 @@ impl Details {
|
|||||||
let mut lines = vec![format!("{:^10}|{:^6}|{:^6}", "ARCH", "OS", "SIZE")];
|
let mut lines = vec![format!("{:^10}|{:^6}|{:^6}", "ARCH", "OS", "SIZE")];
|
||||||
for d in &self.details {
|
for d in &self.details {
|
||||||
lines.push(format!(
|
lines.push(format!(
|
||||||
"{:^10}|{:^6}|{:^6}",
|
"{:^10}|{:^6}|{:^6}MB",
|
||||||
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)
|
d.size.unwrap_or_default() / 1024 / 1024,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
lines
|
lines
|
||||||
|
@ -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,9 +59,14 @@ 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.text = String::new();
|
||||||
|
} else {
|
||||||
|
self.text.pop();
|
||||||
|
}
|
||||||
self.changed = true;
|
self.changed = true;
|
||||||
}
|
}
|
||||||
Key::Esc => {
|
Key::Esc => {
|
||||||
|
Loading…
Reference in New Issue
Block a user