1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
use super::Text;
use std::borrow::Borrow;
pub fn print_ribbon(text: Text) {
print!("\u{1b}Pzribbon;{}\u{1b}\\", text.serialize());
}
pub fn print_ribbon_with_coordinates(
text: Text,
x: usize,
y: usize,
width: Option<usize>,
height: Option<usize>,
) {
let width = width.map(|w| w.to_string()).unwrap_or_default();
let height = height.map(|h| h.to_string()).unwrap_or_default();
print!(
"\u{1b}Pzribbon;{}/{}/{}/{};{}\u{1b}\\",
x,
y,
width,
height,
text.serialize()
);
}
pub fn serialize_ribbon(text: &Text) -> String {
format!("\u{1b}Pzribbon;{}\u{1b}\\", text.serialize())
}
pub fn serialize_ribbon_with_coordinates(
text: &Text,
x: usize,
y: usize,
width: Option<usize>,
height: Option<usize>,
) -> String {
let width = width.map(|w| w.to_string()).unwrap_or_default();
let height = height.map(|h| h.to_string()).unwrap_or_default();
format!(
"\u{1b}Pzribbon;{}/{}/{}/{};{}\u{1b}\\",
x,
y,
width,
height,
text.serialize()
)
}
pub fn serialize_ribbon_line<I>(ribbons: I) -> String
where
I: IntoIterator,
I::Item: Borrow<Text>,
{
ribbons
.into_iter()
.map(|r| serialize_ribbon(r.borrow()))
.collect()
}
pub fn serialize_ribbon_line_with_coordinates<I>(
ribbons: I,
x: usize,
y: usize,
width: Option<usize>,
height: Option<usize>,
) -> String
where
I: IntoIterator,
I::Item: Borrow<Text>,
{
let mut ribbons = ribbons.into_iter();
let Some(first) = ribbons.next() else {
return String::new();
};
let mut result = serialize_ribbon_with_coordinates(first.borrow(), x, y, width, height);
result.push_str(&serialize_ribbon_line(ribbons));
result
}
|