v0.27.0
https://github.com/ratatui/ratatui/releases/tag/v0.27.0
β οΈ See the breaking changes for this release.
LineGauge: Background Styles π
Section titled βLineGauge: Background Styles πβLineGauge::gauge_style
is now deprecated in favor of filled_style
and unfilled_style
methods
which makes it possible to set the foreground/background styles for different states.
let gauge = LineGauge::default() .filled_style(Style::default().fg(Color::Green)) .unfilled_style(Style::default().fg(Color::White)) .ratio(0.43);
We also added a Line Gauge example:
List: Navigation Methods π§
Section titled βList: Navigation Methods π§βYou can now navigate in the List
widget by using the following methods!
let mut state = ListState::default();state.select_first();state.select_next();state.select_previous();state.select_last();
It also clamps the selected index to the bounds of the list when navigating.
Text: Conversion From Display π
Section titled βText: Conversion From Display πβText
, Span
and Line
now supports conversion from any type that implements the Display
trait!
let text = "line1\nline2".to_text();let span = (6.66).to_span();let line = 42.to_line();
This has been made possible with the newly added ToText
, ToSpan
and ToLine
traits
respectfully.
Palette Colors π¨
Section titled βPalette Colors π¨ββ οΈ This is behind the βpaletteβ feature flag.
You can now use colors from the palette crate in Ratatui!
use palette::{LinSrgb, Srgb};use ratatui::style::Color;
let color = Color::from(Srgb::new(1.0f32, 0.0, 0.0));let color = Color::from(LinSrgb::new(1.0f32, 0.0, 0.0));
New Border Sets πΌοΈ
Section titled βNew Border Sets πΌοΈβborder::EMPTY
Section titled βborder::EMPTYβIt uses an empty space symbol (β)
let block = Block::bordered().title("Title").border_set(border::EMPTY);
ββββββββββ ββββ ββ ββββ ββ ββββ ββββββββββ
This is useful for when you need to allocate space for the border and apply the border style to a block without actually drawing a border. This makes it possible to style the entire title area or a block rather than just the title content.
border::FULL
Section titled βborder::FULLβIt uses a full block symbol (β)
let block = Block::bordered().title("Title").border_set(border::FULL);
βββββxxββxxβββββ
Re-export Backends π€
Section titled βRe-export Backends π€βcrossterm
, termion
, and termwiz
can now be accessed as
ratatui::{crossterm, termion, termwiz}
respectively.
This makes it possible to just add the Ratatui crate as a dependency and use the backend of choice without having to add the backend crates as dependencies.
To update existing code, replace all instances of crossterm::
with ratatui::crossterm::
,
termion::
with ratatui::termion::
, and termwiz::
with ratatui::termwiz::
.
Example for crossterm
:
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
And then you can remove crossterm
from Cargo.toml
!
Update Prelude π
Section titled βUpdate Prelude πβBased on a suggestion on Reddit
we made changes to the prelude
module.
Note: This module allows you to easily use
ratatui
without a huge amount of imports! e.g.use ratatui::prelude::*;
The following items have been removed from the prelude:
style::Styled
- this trait is useful for widgets that want to support the Stylize trait, but it adds complexity as widgets have twostyle
methods and aset_style
method.symbols::Marker
- this item is used by code that needs to draw to theCanvas
widget, but itβs not a common item that would be used by most users of the library.terminal::{CompletedFrame, TerminalOptions, Viewport}
- these items are rarely used by code that needs to interact with the terminal, and theyβre generally only ever used once in any app.
The following items have been added to the prelude:
layout::{Position, Size}
- these items are used by code that needs to interact with the layout system. These are newer items that were added in the last few releases, which should be used more liberally.
Tracing Example π
Section titled βTracing Example πβWondering how to debug TUI apps? Tried println
and it didnβt work? We got you covered!
We added an example that demonstrates how to log to a file:
- Code: https://github.com/ratatui/ratatui/blob/main/examples/tracing.rs
- Related discussion on Ratatui Forum: https://forum.ratatui.rs/t/how-do-you-println-debug-your-tui-programs/66
Hyperlink Example π
Section titled βHyperlink Example πβWe added a proof-of-concept example for using hyperlinks in the terminal.
The code is available here.
Cell: New methods π§
Section titled βCell: New methods π§βYou can now create empty Cell
s like this:
let mut cell = Cell::EMPTY;assert_eq!(cell.symbol(), " ");
We also added a constant Cell:new
method for simplify the construction as follows:
let mut cell = Cell::default();cell.set_symbol("a");let cell = Cell::new("a");
Make Stylize::bg()
generic π
Section titled βMake Stylize::bg() generic πβPreviously, Stylize::bg()
accepted Color
but now accepts Into<Color>
. This allows more
flexible types from calling scopes, though it can break some type inference in the calling scope.
let srgb_color: Srgb<u8> = Srgb::new(255, 0, 0);foo.bg(srgb_color);
Writer Methods on Backends ποΈ
Section titled βWriter Methods on Backends ποΈβcrossterm
and termion
backends now have writer()
and writer_mut()
methods for obtain access
to the underlying writer.
This is useful e.g. if you want to see what has been written so far.
let terminal = Terminal::new(CrosstermBackend::new(Vec::<u8>::new()));let ui = |frame| { ... };
terminal.draw(ui);
let crossterm_backend = terminal.backend();let buffer = crossterm_backend.writer();
Add Missing VHS Tapes πΌ
Section titled βAdd Missing VHS Tapes πΌβWe were missing demos for some of our examples. They are now added!
List: Remove deprecated start_corner()
π«
Section titled βList: Remove deprecated start_corner() π«βList::start_corner
was deprecated back in v0.25.
Use List::direction
and ListDirection
instead:
list.start_corner(Corner::TopLeft); list.start_corner(Corner::TopRight);// This is not an error, BottomRight rendered top to bottom previously list.start_corner(Corner::BottomRight);// all becomes list.direction(ListDirection::TopToBottom);
list.start_corner(Corner::BottomLeft);// becomes list.direction(ListDirection::BottomToTop);
layout::Corner
is also removed entirely.
Padding: Deprecate zero()
π«
Section titled βPadding: Deprecate zero() π«βIt is now a constant!
Padding::zero()Padding::ZERO
Buffer: Improve Performance β‘οΈ
Section titled βBuffer: Improve Performance β‘οΈβBuffer::filled
now moves the cell instead of taking a reference:
Buffer::filled(area, &Cell::new("X"));Buffer::filled(area, Cell::new("X"));
Rect: Improve Performance β‘οΈ
Section titled βRect: Improve Performance β‘οΈβMargin
needs to be passed without reference now:
let area = area.inner(&Margin {let area = area.inner(Margin { vertical: 0, horizontal: 2,});
Other πΌ
Section titled βOther πΌβPosition
andSize
now implementsDisplay
(#1162)- Remove newlines when converting strings to
Line
s (#1191)Line::from("a\nb")
now returns aLine
with twoSpan
s instead of one
- Ensure that zero-width characters are rendered correctly (#1165)
- Respect area width while rendering &str and String (#1177)
- Improve benchmark consistency (#1126)
βI canβt believe it! A real gourmet kitchen, and I get to watch!β β Remy