use std::collections::HashMap;
use anyhow::Result;
use console::style;
use crate::PromptStepType;
use cliclack::log;
pub fn handle_print(step_type: &PromptStepType, context: &mut HashMap<String, String>) -> Result<()> {
if let PromptStepType::Print { text, loglevel, input } = step_type {
let mut display_text = text.clone();
if let Some(input_key) = input {
if let Some(input_value) = context.get(input_key) {
display_text = display_text.replace(&format!("{{{}}}", input_key), input_value);
}
}
for (key, value) in context {
display_text = display_text.replace(&format!("{{{}}}", key), value);
}
match loglevel.as_deref() {
Some("info") => log::info(&display_text)?,
Some("warning") | Some("warn") => log::warning(&display_text)?,
Some("error") => log::error(&display_text)?,
Some("none") => log::remark(&display_text)?,
None => {
let bar = style("│").bright().black();
for line in display_text.lines() {
println!("{} {}", bar, line);
}
if display_text.ends_with('\n') {
println!("{}", bar);
}
}
_ => log::remark(&display_text)?,
}
}
Ok(())
}