pub(super) fn html_body(elevator: &str) -> String {
format!(
r#"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1">
<title>ASCII Elevator Shaft</title>
<style>
body {{
font-family: monospace;
white-space: pre;
background-color: #f4f4f4;
padding: 20px;
}}
</style>
</head>
<body>
This is an elevator:
<pre>
{}
</pre>
</body>
</html>
"#,
elevator
)
}
pub(super) fn elevator_ascii(min: i8, max: i8, level: i8, content: &str) -> String {
let floor_count: usize = (max - min + 1).unsigned_abs() as usize;
let mut result = String::with_capacity(floor_count * 40);
let content_width = content.len() + 2;
let single_floor = |first: char, inside: char, data: &mut String| {
data.push(first);
for _ in 0..content_width {
data.push(inside);
}
data.push(first);
};
single_floor('+', '-', &mut result);
result.push('\n');
for floor in (min..=max).rev() {
if floor == level {
result.push_str("|[");
result.push_str(content);
result.push_str("]|");
} else {
single_floor('|', ' ', &mut result);
}
result.push_str(&format!("{floor:4}"));
result.push('\n');
}
single_floor('+', '-', &mut result);
result.push('\n');
result
}