From 9b3e4dd71ec1491e3580e079e9be1b42117a74c9 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Thu, 4 Apr 2024 00:47:24 -0600 Subject: Add better support for aliases Make sure to interpret alias values as their own poems, since aliases can be fairly complex. --- src/poem/anthology/alias.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/poem/anthology/alias.rs') diff --git a/src/poem/anthology/alias.rs b/src/poem/anthology/alias.rs index 96682db..0183ec2 100644 --- a/src/poem/anthology/alias.rs +++ b/src/poem/anthology/alias.rs @@ -10,7 +10,7 @@ use std::collections::HashMap; /// ```sh /// alias vim=nvim /// ``` -pub fn incant(verse: &Verse, aliases: &mut HashMap) -> i32 { +pub fn incant(verse: &Verse, out: &mut String, aliases: &mut HashMap) -> i32 { match verse.clause() { Some(clause) => { for stanza in clause { @@ -22,18 +22,26 @@ pub fn incant(verse: &Verse, aliases: &mut HashMap) -> i32 { } } None => { + let mut lines = Vec::new(); for (key, val) in aliases { - if key.contains(' ') && val.contains(' ') { - println!("'{}'='{}'", key, val); + let line = if key.contains(' ') && val.contains(' ') { + format!("'{}'='{}'", key, val) } else if key.contains(' ') { - println!("'{}'={}", key, val); + format!("'{}'={}", key, val) } else if val.contains(' ') { - println!("{}='{}'", key, val); + format!("{}='{}'", key, val) } else if val.is_empty() { - println!("{}=''", key); + format!("{}=''", key) } else { - println!("{}={}", key, val); - } + format!("{}={}", key, val) + }; + lines.push(line); + } + + if verse.couplet { + *out = lines.join("\n"); + } else { + println!("{}", lines.join("\n")); } } } -- cgit v1.2.3