added the ability to instantly delete default text in RepoEntry; simplified some code
All checks were successful
continuous-integration/woodpecker the build was successful
All checks were successful
continuous-integration/woodpecker the build was successful
This commit is contained in:
parent
bb5ea3a993
commit
3bf2359392
@ -54,12 +54,9 @@ impl std::iter::Iterator for State {
|
||||
|
||||
impl Ui {
|
||||
pub fn run(opt: &Opt) {
|
||||
let (repo_id, load_repo) = match &opt.repo {
|
||||
None => (
|
||||
"enter a repository here or select one from file widget",
|
||||
false,
|
||||
),
|
||||
Some(repo) => (String::as_str(repo), true),
|
||||
let repo_id = match &opt.repo {
|
||||
None => None,
|
||||
Some(repo) => Some(String::as_str(repo)),
|
||||
};
|
||||
|
||||
let mut ui = Ui {
|
||||
@ -71,7 +68,7 @@ impl Ui {
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -49,26 +49,21 @@ pub struct NoYaml {
|
||||
|
||||
impl NoYaml {
|
||||
pub fn run(opt: &Opt) {
|
||||
let (repo, load_repo) = match &opt.repo {
|
||||
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 repo_id = match &opt.repo {
|
||||
None => None,
|
||||
Some(repo) => Some(String::as_str(repo)),
|
||||
};
|
||||
|
||||
let mut ui = NoYaml {
|
||||
state: State::EditRepo,
|
||||
repo,
|
||||
repo: repo_entry::RepoEntry::new(repo_id),
|
||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
||||
details: details::Details::new(),
|
||||
info: info::Info::new("could not find a docker-compose file"),
|
||||
};
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
@ -7,14 +7,17 @@ pub struct RepoEntry {
|
||||
text: String,
|
||||
old_text: String,
|
||||
changed: bool,
|
||||
default_text: bool,
|
||||
}
|
||||
|
||||
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 {
|
||||
text: String::from(text),
|
||||
old_text: String::from(text),
|
||||
text: String::from(text.unwrap_or(default_text)),
|
||||
old_text: String::from(text.unwrap_or(default_text)),
|
||||
changed: false,
|
||||
default_text: text.is_none(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,11 +59,17 @@ impl RepoEntry {
|
||||
Key::Char(c) => {
|
||||
self.text.push(c);
|
||||
self.changed = true;
|
||||
self.default_text = false;
|
||||
}
|
||||
Key::Backspace => {
|
||||
if self.default_text {
|
||||
self.text = String::new();
|
||||
self.changed = true;
|
||||
} else {
|
||||
self.text.pop();
|
||||
self.changed = true;
|
||||
}
|
||||
}
|
||||
Key::Esc => {
|
||||
self.text = self.old_text.clone();
|
||||
self.changed = false;
|
||||
|
Loading…
Reference in New Issue
Block a user