From 30dae5c12b81a6f92be138966d8930fa15612cb0 Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 17 Jan 2025 20:06:28 +0800 Subject: feat: support macro (#1087) --- src/utils/mod.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/utils/mod.rs') diff --git a/src/utils/mod.rs b/src/utils/mod.rs index c880252..ecc81aa 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -112,16 +112,6 @@ pub fn extract_block(input: &str) -> String { } } -pub fn format_option_value(value: &Option) -> String -where - T: std::fmt::Display, -{ - match value { - Some(value) => value.to_string(), - None => "-".to_string(), - } -} - pub fn convert_option_string(value: &str) -> Option { if value.is_empty() { None @@ -199,6 +189,21 @@ pub fn dimmed_text(input: &str) -> String { nu_ansi_term::Style::new().dimmed().paint(input).to_string() } +pub fn multiline_text(input: &str) -> String { + input + .split('\n') + .enumerate() + .map(|(i, v)| { + if i == 0 { + v.to_string() + } else { + format!(".. {v}") + } + }) + .collect::>() + .join("\n") +} + pub fn temp_file(prefix: &str, suffix: &str) -> PathBuf { env::temp_dir().join(format!( "{}-{}{prefix}{}{suffix}", -- cgit v1.2.3