Use styled chunks of text instead of plain strings

This commit is contained in:
Joscha 2022-07-04 10:55:25 +02:00
parent 761519c1a7
commit 9b0d80873f
8 changed files with 209 additions and 66 deletions

View file

@ -7,53 +7,45 @@ fn draw(f: &mut Frame) {
f.write(
Pos::new(0, 0),
"Writing over wide graphemes removes the entire overwritten grapheme.",
ContentStyle::default(),
);
let under = ContentStyle::default().white().on_dark_blue();
let over = ContentStyle::default().black().on_dark_yellow();
for i in 0..6 {
let delta = i - 2;
f.write(Pos::new(2 + i * 7, 2), "a😀", under);
f.write(Pos::new(2 + i * 7, 3), "a😀", under);
f.write(Pos::new(2 + i * 7, 4), "a😀", under);
f.write(Pos::new(2 + i * 7 + delta, 3), "b", over);
f.write(Pos::new(2 + i * 7 + delta, 4), "😈", over);
f.write(Pos::new(2 + i * 7, 2), ("a😀", under));
f.write(Pos::new(2 + i * 7, 3), ("a😀", under));
f.write(Pos::new(2 + i * 7, 4), ("a😀", under));
f.write(Pos::new(2 + i * 7 + delta, 3), ("b", over));
f.write(Pos::new(2 + i * 7 + delta, 4), ("😈", over));
}
f.write(
Pos::new(0, 6),
"Wide graphemes at the edges of the screen apply their style, but are not",
ContentStyle::default(),
);
f.write(
Pos::new(0, 7),
"actually rendered.",
ContentStyle::default(),
);
f.write(Pos::new(0, 7), "actually rendered.");
let x1 = -1;
let x2 = f.size().width as i32 / 2 - 3;
let x3 = f.size().width as i32 - 5;
f.write(Pos::new(x1, 9), "123456", under);
f.write(Pos::new(x1, 10), "😀😀😀", under);
f.write(Pos::new(x2, 9), "123456", under);
f.write(Pos::new(x2, 10), "😀😀😀", under);
f.write(Pos::new(x3, 9), "123456", under);
f.write(Pos::new(x3, 10), "😀😀😀", under);
f.write(Pos::new(x1, 9), ("123456", under));
f.write(Pos::new(x1, 10), ("😀😀😀", under));
f.write(Pos::new(x2, 9), ("123456", under));
f.write(Pos::new(x2, 10), ("😀😀😀", under));
f.write(Pos::new(x3, 9), ("123456", under));
f.write(Pos::new(x3, 10), ("😀😀😀", under));
let scientist = "👩‍🔬";
f.write(
Pos::new(0, 12),
"Most terminals ignore the zero width joiner and display this female",
ContentStyle::default(),
);
f.write(
Pos::new(0, 13),
"scientist emoji as a woman and a microscope: 👩‍🔬",
ContentStyle::default(),
);
for i in 0..(f.width(scientist) + 4) {
f.write(Pos::new(2, 15 + i as i32), scientist, under);
f.write(Pos::new(i as i32, 15 + i as i32), "x", over);
f.write(Pos::new(2, 15 + i as i32), (scientist, under));
f.write(Pos::new(i as i32, 15 + i as i32), ("x", over));
}
}