Skip to content

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.

ratatui-forum

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:59 byte 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 "]));
}

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 module

This 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::new constant (#1040)
  • Change canvas map data to const instead of static (#1037)
  • Use constant function for calendar (#1039)

Other ๐Ÿ’ผ

  • Improve performance!
    • Simplify Buffer::filled with macro (#1036)
    • Avoid allocating memory when using split ergonomic utils (#1105)
  • 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_metadata and clippy::cargo)
  • Update crate metadata such as keywords and homepage

๐Ÿง€