v0.26.3
https://github.com/ratatui/ratatui/releases/tag/v0.26.3
Ratatui Forum ๐
We are happy to announce a brand new Ratatui Forum ๐ญ for Rust & TUI enthusiasts.
Join here: https://forum.ratatui.rs
Here you can get help with your Rust/Ratatui questions and share your projects!
Fix Unicode Truncation Bug ๐
If you are using Ratatui 0.26.2 you might have hit this bug:
panic occurred at
ratatui-0.26.2/src/text/line.rs:477:59byte index 51 is not a char boundary; it is inside โใงโ (bytes 49..52) of๐ฆ RFC8628 OAuth 2.0 Device Authorization GrantใงCLIใใGithubใฎaccess tokenใๅๅพใใ
This issue was introduced in this PR and now fixed
with 0.26.3!
#[test]fn truncation_works_with_emoji() { let line = Line::raw( "123456789๐ฆ"); let mut buf = Buffer::empty(Rect::new(0, 0, 10, 1)); line.render(buf.area, &mut buf); assert_buffer_eq!(buf, Buffer::with_lines(vec!["123456789 "]));}- Details: https://github.com/ratatui/ratatui/issues/1032
- Implementation: https://github.com/ratatui/ratatui/pull/1089
Color: Better Serialization ๐จ
Color::Rgb will now be serialized as the hex representation of their value.
For example, Color::Rgb(255, 0, 255) would be serialized as "#FF00FF" rather than
{"Rgb": [255, 0, 255]}:
let json_rgb = serde_json::to_string(&Color::Rgb(255, 0, 255))?;assert_eq!(json_rgb, r##""#FF00FF""##);assert_eq!( serde_json::from_str::<Color>(&json_rgb)?, Color::Rgb(255, 0, 255));Similarly, Color::Indexed will now be serialized as just the string of the index.
For example, with serde_json, Color::Indexed(10) would be serialized as "10" rather than
{"Indexed": 10}:
let json_indexed = serde_json::to_string(&Color::Indexed(10))?;assert_eq!(json_indexed, r#""10""#);assert_eq!( serde_json::from_str::<Color>(&json_indexed)?, Color::Indexed(10));Faster Rendering ๐
We sped up combined foreground and background color changes for the crossterm backend by up to
20%! ๐ฅ
For more information, see:
I changed the SetColors command to write both colors at once with a single write instead of multiple writes that more bytes. This led to a 15-25% fps increase when testing the colors_rgb example on iTerm2 on an M2 Macbook Pro.
Deprecate assert_buffer_eq macro ๐ซ
assert_buffer_eq is now
deprecated in favor of the standard assert_eq macro:
assert_buffer_eq!(actual, expected);assert_eq!(actual, expected);We also introduced TestBackend::assert_buffer_lines for checking if TestBackendโs buffer is
equal to the expected lines.
Here is an example usage:
#[test]fn buffer() { let backend = TestBackend::new(10, 2); backend.assert_buffer_lines([" "; 2]);}So the usage can be simplified as follows:
backend.assert_buffer(&Buffer::with_lines([" "; 2]));backend.assert_buffer_lines([" "; 2]);Use Block::bordered ๐ฆ
Throughout the codebase we switched to the new way of creating bordered Blocks: Block::bordered
Block::default().borders(Borders::ALL);Block::bordered();This was added in 0.26 and it requires one less import!
Exposed Error Type ๐
Have you ever tried to wrap ParseColorError in your custom error implementation?
9 | ParseColor(ratatui::style::color::ParseColorError), | ^^^^^ --------------- struct `ParseColorError` is not publicly re-exported | | | private moduleThis is now possible since ParseColorError is re-exported as ratatui::style::ParseColorError!
Constants โพ๏ธ
We made improvements in some widgets to make use of constant functions and types:
- Make
TableState::newconstant (#1040) - Change canvas map data to const instead of static (#1037)
- Use constant function for calendar (#1039)
Other ๐ผ
- Improve performance!
- Changed user_input example to work with multi-byte unicode chars (#1069)
- Handle ZWSP (allow wrapping at zero width whitespace) (#1074)
- Fix the Debug panic in Buffer (#1098)
- Track caller for index_of method of Buffer (#1046)
- Simplify test cases using
rstest(#1095) - Enable and fix some clippy lints (including
clippy::cargo_common_metadataandclippy::cargo) - Update crate metadata such as keywords and homepage