feat: update envelop format
This commit is contained in:
@@ -75,7 +75,7 @@ pub fn info_single(path: &PathBuf, cmd_info: &CmdInfo) -> XResult<()> {
|
|||||||
envelops.iter().enumerate().for_each(|(i, envelop)| {
|
envelops.iter().enumerate().for_each(|(i, envelop)| {
|
||||||
infos.push(format!("{}: {}",
|
infos.push(format!("{}: {}",
|
||||||
header(&format!("Envelop #{}", i + 1)),
|
header(&format!("Envelop #{}", i + 1)),
|
||||||
util_envelop::format_envelop_with_type_with(envelop, &config, Some(10))
|
util_envelop::format_envelop(envelop, &config)
|
||||||
));
|
));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
|
use rust_util::iff;
|
||||||
|
|
||||||
use crate::config::{TinyEncryptConfig, TinyEncryptConfigEnvelop};
|
use crate::config::{TinyEncryptConfig, TinyEncryptConfigEnvelop};
|
||||||
use crate::spec::TinyEncryptEnvelop;
|
use crate::spec::TinyEncryptEnvelop;
|
||||||
|
|
||||||
pub fn format_envelop(envelop: &TinyEncryptEnvelop, config: &Option<TinyEncryptConfig>) -> String {
|
pub fn format_envelop(envelop: &TinyEncryptEnvelop, config: &Option<TinyEncryptConfig>) -> String {
|
||||||
format_envelop_with_type_with(envelop, config, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn format_envelop_with_type_with(envelop: &TinyEncryptEnvelop, config: &Option<TinyEncryptConfig>, type_width: Option<usize>) -> String {
|
|
||||||
let config_envelop = config.as_ref().and_then(|c| c.find_by_kid(&envelop.kid));
|
let config_envelop = config.as_ref().and_then(|c| c.find_by_kid(&envelop.kid));
|
||||||
let envelop_kid = config_envelop.and_then(|e| e.sid.as_ref())
|
let envelop_kid = config_envelop.and_then(|e| e.sid.as_ref())
|
||||||
.map(|sid| format!(", Sid: {}", sid))
|
.map(|sid| format!(", Sid: {}", sid))
|
||||||
@@ -14,7 +12,7 @@ pub fn format_envelop_with_type_with(envelop: &TinyEncryptEnvelop, config: &Opti
|
|||||||
let desc = envelop_desc.as_ref()
|
let desc = envelop_desc.as_ref()
|
||||||
.map(|desc| format!(", Desc: {}", desc))
|
.map(|desc| format!(", Desc: {}", desc))
|
||||||
.unwrap_or_else(|| "".to_string());
|
.unwrap_or_else(|| "".to_string());
|
||||||
format!("{}{}{}", with_with(&envelop.r#type.get_upper_name(), type_width), envelop_kid, desc)
|
format!("{}{}{}", with_with(&envelop.r#type.get_upper_name(), 10), envelop_kid, desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_envelop_desc(envelop: &TinyEncryptEnvelop, config_envelop: &Option<&TinyEncryptConfigEnvelop>) -> Option<String> {
|
fn get_envelop_desc(envelop: &TinyEncryptEnvelop, config_envelop: &Option<&TinyEncryptConfigEnvelop>) -> Option<String> {
|
||||||
@@ -27,13 +25,6 @@ fn get_envelop_desc(envelop: &TinyEncryptEnvelop, config_envelop: &Option<&TinyE
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_with(s: &str, width: Option<usize>) -> String {
|
fn with_with(s: &str, width: usize) -> String {
|
||||||
match width {
|
iff!(s.len() < width, format!("{}{}", s, " ".repeat(width - s.len())), s.to_string())
|
||||||
None => s.to_string(),
|
|
||||||
Some(w) => if s.len() < w {
|
|
||||||
format!("{}{}", s, " ".repeat(w - s.len()))
|
|
||||||
} else {
|
|
||||||
s.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user