use crate::args::CliArgs;
use termcinema_engine::{LayoutSpec, TextAlign, VerticalAlign};
pub(crate) fn build_layout(args: &CliArgs) -> LayoutSpec {
LayoutSpec {
width: args.width,
height: args.height,
padding: args.padding.or(Some(10)),
line_spacing: args.line_spacing,
align: Some(parse_align(args.align.as_deref())),
v_align: Some(parse_v_align(args.v_align.as_deref())),
}
}
fn parse_align(input: Option<&str>) -> TextAlign {
match input.unwrap_or("left").to_lowercase().as_str() {
"left" => TextAlign::Left,
"center" => TextAlign::Center,
"right" => TextAlign::Right,
invalid => {
eprintln!(
"⚠️ Invalid align value '{}'. Falling back to 'left'.",
invalid
);
TextAlign::Left
}
}
}
fn parse_v_align(input: Option<&str>) -> VerticalAlign {
match input.unwrap_or("middle").to_lowercase().as_str() {
"top" => VerticalAlign::Top,
"middle" => VerticalAlign::Middle,
"bottom" => VerticalAlign::Bottom,
invalid => {
eprintln!(
"⚠️ Invalid v_align value '{}'. Falling back to 'middle'.",
invalid
);
VerticalAlign::Middle
}
}
}