-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rewrote the line / span rendering code to take into account how multi-byte / wide emoji characters are truncated when rendering into areas that cannot accommodate them in the available space - Added comprehensive coverage over the edge cases - Adds a benchmark to ensure perf Fixes: #1032 Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de> Co-authored-by: EdJoPaTo <[email protected]>
- Loading branch information
1 parent
3cc29bd
commit 699c2d7
Showing
4 changed files
with
399 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::hint::black_box; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use ratatui::{ | ||
buffer::Buffer, | ||
layout::{Alignment, Rect}, | ||
style::Stylize, | ||
text::Line, | ||
widgets::Widget, | ||
}; | ||
|
||
fn line_render(criterion: &mut Criterion) { | ||
for alignment in [Alignment::Left, Alignment::Center, Alignment::Right] { | ||
let mut group = criterion.benchmark_group(format!("line_render/{alignment}")); | ||
group.sample_size(1000); | ||
|
||
let line = &Line::from(vec![ | ||
"This".red(), | ||
" ".green(), | ||
"is".italic(), | ||
" ".blue(), | ||
"SPARTA!!".bold(), | ||
]) | ||
.alignment(alignment); | ||
|
||
for width in [0, 3, 4, 6, 7, 10, 42] { | ||
let area = Rect::new(0, 0, width, 1); | ||
|
||
group.bench_function(width.to_string(), |bencher| { | ||
let mut buffer = Buffer::empty(area); | ||
bencher.iter(|| black_box(line).render(area, &mut buffer)); | ||
}); | ||
} | ||
group.finish(); | ||
} | ||
} | ||
|
||
criterion_group!(benches, line_render); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.