Use styled chunks of text instead of plain strings
This commit is contained in:
parent
761519c1a7
commit
9b0d80873f
8 changed files with 209 additions and 66 deletions
|
|
@ -6,13 +6,14 @@ use toss::terminal::Terminal;
|
|||
fn draw(f: &mut Frame) {
|
||||
f.write(
|
||||
Pos::new(0, 0),
|
||||
"Hello world!",
|
||||
ContentStyle::default().green(),
|
||||
("Hello world!", ContentStyle::default().green()),
|
||||
);
|
||||
f.write(
|
||||
Pos::new(0, 1),
|
||||
"Press any key to exit",
|
||||
ContentStyle::default().on_dark_blue(),
|
||||
(
|
||||
"Press any key to exit",
|
||||
ContentStyle::default().on_dark_blue(),
|
||||
),
|
||||
);
|
||||
f.show_cursor(Pos::new(16, 0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crossterm::event::Event;
|
||||
use crossterm::style::ContentStyle;
|
||||
use toss::frame::{Frame, Pos};
|
||||
use toss::styled::Styled;
|
||||
use toss::terminal::Terminal;
|
||||
|
||||
fn draw(f: &mut Frame) {
|
||||
|
|
@ -18,13 +18,10 @@ fn draw(f: &mut Frame) {
|
|||
);
|
||||
|
||||
let breaks = f.wrap(text, f.size().width.into());
|
||||
let lines = toss::split_at_indices(text, &breaks);
|
||||
for (i, line) in lines.iter().enumerate() {
|
||||
f.write(
|
||||
Pos::new(0, i as i32),
|
||||
line.trim_end(),
|
||||
ContentStyle::default(),
|
||||
);
|
||||
let lines = Styled::default().then(text).split_at_indices(&breaks);
|
||||
for (i, mut line) in lines.into_iter().enumerate() {
|
||||
line.trim_end();
|
||||
f.write(Pos::new(0, i as i32), line);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue