Only print one line per item if only one field is set to be printed in verbose mode
This commit is contained in:
parent
d0c7bcda58
commit
c7d3b2582e
1 changed files with 19 additions and 11 deletions
|
@ -35,7 +35,10 @@ pub enum VerboseField {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VerboseField {
|
impl VerboseField {
|
||||||
fn print_field(&self, item: &Item, terminal: &mut console::Term, args: &crate::cli::CliArgs) -> bool {
|
fn print_field(&self, item: &Item, terminal: &mut console::Term, args: &crate::cli::CliArgs, needs_prompt: bool) -> bool {
|
||||||
|
if needs_prompt {
|
||||||
|
write!(terminal, " {}", args.prompt).expect(TERMINAL_WRITE_ERROR);
|
||||||
|
}
|
||||||
match self {
|
match self {
|
||||||
Self::ShowFieldValue(f) => {
|
Self::ShowFieldValue(f) => {
|
||||||
if let Some(field) = item.field(f) {
|
if let Some(field) = item.field(f) {
|
||||||
|
@ -44,14 +47,13 @@ impl VerboseField {
|
||||||
if field_str.len() >= max_len {
|
if field_str.len() >= max_len {
|
||||||
write!(
|
write!(
|
||||||
terminal,
|
terminal,
|
||||||
" {}{}: `{}[...]`",
|
"{}: `{}[...]`",
|
||||||
args.prompt,
|
|
||||||
f,
|
f,
|
||||||
&field_str[..max_len - 5]
|
&field_str[..max_len - 5]
|
||||||
)
|
)
|
||||||
.expect(TERMINAL_WRITE_ERROR);
|
.expect(TERMINAL_WRITE_ERROR);
|
||||||
} else {
|
} else {
|
||||||
write!(terminal, " {}{}: `{}`", args.prompt, f, field_str).expect(TERMINAL_WRITE_ERROR);
|
write!(terminal, "{}: `{}`", f, field_str).expect(TERMINAL_WRITE_ERROR);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,7 +63,7 @@ impl VerboseField {
|
||||||
Self::ShowFieldType(f) => {
|
Self::ShowFieldType(f) => {
|
||||||
if let Some(field) = item.field(f) {
|
if let Some(field) = item.field(f) {
|
||||||
let field_str = field.type_str();
|
let field_str = field.type_str();
|
||||||
write!(terminal, " {}{}: {}", args.prompt, f, field_str).expect(TERMINAL_WRITE_ERROR);
|
write!(terminal, "{}: {}", f, field_str).expect(TERMINAL_WRITE_ERROR);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -74,14 +76,13 @@ impl VerboseField {
|
||||||
if field_str.len() >= max_len {
|
if field_str.len() >= max_len {
|
||||||
write!(
|
write!(
|
||||||
terminal,
|
terminal,
|
||||||
" {}{}: {}[...]]",
|
"{}: {}[...]]",
|
||||||
args.prompt,
|
|
||||||
f,
|
f,
|
||||||
&field_str[..max_len - 5]
|
&field_str[..max_len - 5]
|
||||||
)
|
)
|
||||||
.expect(TERMINAL_WRITE_ERROR);
|
.expect(TERMINAL_WRITE_ERROR);
|
||||||
} else {
|
} else {
|
||||||
write!(terminal, " {}{}: {}", args.prompt, f, field_str).expect(TERMINAL_WRITE_ERROR);
|
write!(terminal, "{}: {}", f, field_str).expect(TERMINAL_WRITE_ERROR);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
@ -96,17 +97,24 @@ impl Verbosity {
|
||||||
pub fn print_item(&self, item: &Item, terminal: &mut console::Term, args: &crate::cli::CliArgs) {
|
pub fn print_item(&self, item: &Item, terminal: &mut console::Term, args: &crate::cli::CliArgs) {
|
||||||
Self::item_prompt(terminal, args);
|
Self::item_prompt(terminal, args);
|
||||||
if self.debug {
|
if self.debug {
|
||||||
writeln!(terminal, "--\\/-- \\/ --\\/--").expect(TERMINAL_WRITE_ERROR);
|
|
||||||
if self.field_handlers.is_empty() {
|
if self.field_handlers.is_empty() {
|
||||||
let mut fields: Vec<_> = item.iter().collect();
|
let mut fields: Vec<_> = item.iter().collect();
|
||||||
fields.sort();
|
fields.sort();
|
||||||
|
let fields_gt_1 = fields.len() > 1;
|
||||||
|
if fields_gt_1 { writeln!(terminal, "--\\/-- \\/ --\\/--").expect(TERMINAL_WRITE_ERROR); }
|
||||||
for field in fields {
|
for field in fields {
|
||||||
VerboseField::ShowFieldValue(field.to_owned()).print_field(item, terminal, args);
|
VerboseField::ShowFieldValue(field.to_owned()).print_field(item, terminal, args, fields_gt_1);
|
||||||
|
writeln!(terminal, "").expect(TERMINAL_WRITE_ERROR);
|
||||||
|
}
|
||||||
|
} else if self.field_handlers.len() == 1 {
|
||||||
|
let has_printed = self.field_handlers.get(0).unwrap().print_field(item, terminal, args, false);
|
||||||
|
if has_printed {
|
||||||
writeln!(terminal, "").expect(TERMINAL_WRITE_ERROR);
|
writeln!(terminal, "").expect(TERMINAL_WRITE_ERROR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
writeln!(terminal, "--\\/-- \\/ --\\/--").expect(TERMINAL_WRITE_ERROR);
|
||||||
for vf in &self.field_handlers {
|
for vf in &self.field_handlers {
|
||||||
let has_printed = vf.print_field(item, terminal, args);
|
let has_printed = vf.print_field(item, terminal, args, true);
|
||||||
if has_printed {
|
if has_printed {
|
||||||
writeln!(terminal, "").expect(TERMINAL_WRITE_ERROR);
|
writeln!(terminal, "").expect(TERMINAL_WRITE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue