# Breaking Changes This document contains a list of breaking changes in each version and some notes to help migrate between versions. It is compiled manually from the commit history and changelog. We also tag PRs on GitHub with a [breaking change] label. [breaking change]: (https://github.com/ratatui/ratatui/issues?q=label%3A%22breaking+change%22) ## Summary This is a quick summary of the sections below: - [v0.28.0](#v0280) ⁻ `Backend::size` returns `Size` instead of `Rect` - `Backend` trait migrates to `get/set_cursor_position` - Ratatui now requires Crossterm 0.28.0 - `Axis::labels` now accepts `IntoIterator>` - `Layout::init_cache` no longer returns bool and takes a `NonZeroUsize` instead of `usize` - `ratatui::terminal` module is now private - `ToText` no longer has a lifetime - `Frame::size` is deprecated and renamed to `Frame::area` - [v0.27.0](#v0270) - List no clamps the selected index to list - Prelude items added / removed - 'termion' updated to 4.0 - `Rect::inner` takes `Margin` directly instead of reference - `Buffer::filled` takes `Cell` directly instead of reference - `Stylize::bg()` now accepts `Into` - Removed deprecated `List::start_corner` - `LineGauge::gauge_style` is deprecated - [v0.26.0](#v0260) - `Flex::Start` is the new default flex mode for `Layout` - `patch_style` & `reset_style` now consume and return `Self` - Removed deprecated `Block::title_on_bottom` - `Line` now has an extra `style` field which applies the style to the entire line - `Block` style methods cannot be created in a const context - `Tabs::new()` now accepts `IntoIterator>>` - `Table::new` now accepts `IntoIterator>>`. - [v0.25.0](#v0250) - Removed `Axis::title_style` and `Buffer::set_background` - `List::new()` now accepts `IntoIterator>>` - `Table::new()` now requires specifying the widths - `Table::widths()` now accepts `IntoIterator>` - Layout::new() now accepts direction and constraint parameters - The default `Tabs::highlight_style` is now `Style::new().reversed()` - [v0.24.0](#v0240) - MSRV is now 1.70.0 - `ScrollbarState`: `position`, `content_length`, and `viewport_content_length` are now `usize` - `BorderType`: `line_symbols` is now `border_symbols` and returns `symbols::border::set` - `Frame<'a, B: Backend>` is now `Frame<'a>` - `Stylize` shorthands for `String` now consume the value and return `Span<'static>` - `Spans` is removed - [v0.23.0](#v0230) - `Scrollbar`: `track_symbol` now takes `Option<&str>` - `Scrollbar`: symbols moved to `symbols` module - MSRV is now 1.67.0 - [v0.22.0](#v0220) - `serde` representation of `Borders` and `Modifiers` has changed - [v0.21.0](#v0210) - MSRV is now 1.65.0 - `terminal::ViewPort` is now an enum - `"".as_ref()` must be annotated to implement `Into>` - `Marker::Block` renders as a block char instead of a bar char - [v0.20.0](#v0200) - MSRV is now 1.63.0 - `List` no longer ignores empty strings ## v0.28.0 ### `Backend::size` returns `Size` instead of `Rect` ([#1254]) [#1254]: https://github.com/ratatui/ratatui/pull/1254 The `Backend::size` method returns a `Size` instead of a `Rect`. There is no need for the position here as it was always 0,0. ### `Backend` trait migrates to `get/set_cursor_position` ([#1284]) [#1284]: https://github.com/ratatui/ratatui/pull/1284 If you just use the types implementing the `Backend` trait, you will see deprecation hints but nothing is a breaking change for you. If you implement the Backend trait yourself, you need to update the implementation and add the `get/set_cursor_position` method. You can remove the `get/set_cursor` methods as they are deprecated and a default implementation for them exists. ### Ratatui now requires Crossterm 0.28.0 ([#1278]) [#1278]: https://github.com/ratatui/ratatui/pull/1278 Crossterm is updated to version 0.28.0, which is a semver incompatible version with the previous version (0.27.0). Ratatui re-exports the version of crossterm that it is compatible with under `ratatui::crossterm`, which can be used to avoid incompatible versions in your dependency list. ### `Axis::labels()` now accepts `IntoIterator>` ([#1273] and [#1283]) [#1273]: https://github.com/ratatui/ratatui/pull/1173 [#1283]: https://github.com/ratatui/ratatui/pull/1283 Previously Axis::labels accepted `Vec`. Any code that uses conversion methods that infer the type will need to be rewritten as the compiler cannot infer the correct type. ```diff - Axis::default().labels(vec!["a".into(), "b".into()]) + Axis::default().labels(["a", "b"]) ``` ### `Layout::init_cache` no longer returns bool and takes a `NonZeroUsize` instead of `usize` ([#1245]) [#1245]: https://github.com/ratatui/ratatui/pull/1245 ```diff - let is_initialized = Layout::init_cache(100); + Layout::init_cache(NonZeroUsize::new(100).unwrap()); ``` ### `ratatui::terminal` module is now private ([#1160]) [#1160]: https://github.com/ratatui/ratatui/pull/1160 The `terminal` module is now private and can not be used directly. The types under this module are exported from the root of the crate. This reduces clashes with other modules in the backends that are also named terminal, and confusion about module exports for newer Rust users. ```diff - use ratatui::terminal::{CompletedFrame, Frame, Terminal, TerminalOptions, ViewPort}; + use ratatui::{CompletedFrame, Frame, Terminal, TerminalOptions, ViewPort}; ``` ### `ToText` no longer has a lifetime ([#1234]) [#1234]: https://github.com/ratatui/ratatui/pull/1234 This change simplifies the trait and makes it easier to implement. ### `Frame::size` is deprecated and renamed to `Frame::area` [#1293]: https://github.com/ratatui/ratatui/pull/1293 `Frame::size` is renamed to `Frame::area` as it's the more correct name. ## [v0.27.0](https://github.com/ratatui/ratatui/releases/tag/v0.27.0) ### List no clamps the selected index to list ([#1159]) [#1149]: https://github.com/ratatui/ratatui/pull/1149 The `List` widget now clamps the selected index to the bounds of the list when navigating with `first`, `last`, `previous`, and `next`, as well as when setting the index directly with `select`. Previously selecting an index past the end of the list would show treat the list as having a selection which was not visible. Now the last item in the list will be selected instead. ### Prelude items added / removed ([#1149]) 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 two `style` methods and a `set_style` method. - `symbols::Marker` - this item is used by code that needs to draw to the `Canvas` 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. This may cause conflicts for types defined elsewhere with a similar name. To update your app: ```diff // if your app uses Styled::style() or Styled::set_style(): -use ratatui::prelude::*; +use ratatui::{prelude::*, style::Styled}; // if your app uses symbols::Marker: -use ratatui::prelude::*; +use ratatui::{prelude::*, symbols::Marker} // if your app uses terminal::{CompletedFrame, TerminalOptions, Viewport} -use ratatui::prelude::*; +use ratatui::{prelude::*, terminal::{CompletedFrame, TerminalOptions, Viewport}}; // to disambiguate existing types named Position or Size: - use some_crate::{Position, Size}; - let size: Size = ...; - let position: Position = ...; + let size: some_crate::Size = ...; + let position: some_crate::Position = ...; ``` ### Termion is updated to 4.0 [#1106] Changelog: A change is only necessary if you were matching on all variants of the `MouseEvent` enum without a wildcard. In this case, you need to either handle the two new variants, `MouseLeft` and `MouseRight`, or add a wildcard. [#1106]: https://github.com/ratatui/ratatui/pull/1106 ### `Rect::inner` takes `Margin` directly instead of reference ([#1008]) [#1008]: https://github.com/ratatui/ratatui/pull/1008 `Margin` needs to be passed without reference now. ```diff -let area = area.inner(&Margin { +let area = area.inner(Margin { vertical: 0, horizontal: 2, }); ``` ### `Buffer::filled` takes `Cell` directly instead of reference ([#1148]) [#1148]: https://github.com/ratatui/ratatui/pull/1148 `Buffer::filled` moves the `Cell` instead of taking a reference. ```diff -Buffer::filled(area, &Cell::new("X")); +Buffer::filled(area, Cell::new("X")); ``` ### `Stylize::bg()` now accepts `Into` ([#1103]) [#1103]: https://github.com/ratatui/ratatui/pull/1103 Previously, `Stylize::bg()` accepted `Color` but now accepts `Into`. This allows more flexible types from calling scopes, though it can break some type inference in the calling scope. ### Remove deprecated `List::start_corner` and `layout::Corner` ([#759]) [#759]: https://github.com/ratatui/ratatui/pull/759 `List::start_corner` was deprecated in v0.25. Use `List::direction` and `ListDirection` instead. ```diff - 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); ``` ```diff - list.start_corner(Corner::BottomLeft); // becomes + list.direction(ListDirection::BottomToTop); ``` `layout::Corner` was removed entirely. ### `LineGauge::gauge_style` is deprecated ([#565]) [#565]: https://github.com/ratatui/ratatui/pull/1148 `LineGauge::gauge_style` is deprecated and replaced with `LineGauge::filled_style` and `LineGauge::unfilled_style`: ```diff let gauge = LineGauge::default() - .gauge_style(Style::default().fg(Color::Red).bg(Color::Blue) + .filled_style(Style::default().fg(Color::Green)) + .unfilled_style(Style::default().fg(Color::White)); ``` ## [v0.26.0](https://github.com/ratatui/ratatui/releases/tag/v0.26.0) ### `Flex::Start` is the new default flex mode for `Layout` ([#881]) [#881]: https://github.com/ratatui/ratatui/pull/881 Previously, constraints would stretch to fill all available space, violating constraints if necessary. With v0.26.0, `Flex` modes are introduced, and the default is `Flex::Start`, which will align areas associated with constraints to be beginning of the area. With v0.26.0, additionally, `Min` constraints grow to fill excess space. These changes will allow users to build layouts more easily. With v0.26.0, users will most likely not need to change what constraints they use to create existing layouts with `Flex::Start`. However, to get old behavior, use `Flex::Legacy`. ```diff - let rects = Layout::horizontal([Length(1), Length(2)]).split(area); // becomes + let rects = Layout::horizontal([Length(1), Length(2)]).flex(Flex::Legacy).split(area); ``` ### `Table::new()` now accepts `IntoIterator>>` ([#774]) [#774]: https://github.com/ratatui/ratatui/pull/774 Previously, `Table::new()` accepted `IntoIterator>`. The argument change to `IntoIterator>>`, This allows more flexible types from calling scopes, though it can some break type inference in the calling scope for empty containers. This can be resolved either by providing an explicit type (e.g. `Vec::::new()`), or by using `Table::default()`. ```diff - let table = Table::new(vec![], widths); // becomes + let table = Table::default().widths(widths); ``` ### `Tabs::new()` now accepts `IntoIterator>>` ([#776]) [#776]: https://github.com/ratatui/ratatui/pull/776 Previously, `Tabs::new()` accepted `Vec` where `T: Into>`. This allows more flexible types from calling scopes, though it can break some type inference in the calling scope. This typically occurs when collecting an iterator prior to calling `Tabs::new`, and can be resolved by removing the call to `.collect()`. ```diff - let tabs = Tabs::new((0.3).map(|i| format!("{i}")).collect()); // becomes + let tabs = Tabs::new((0.3).map(|i| format!("{i}"))); ``` ### Table::default() now sets segment_size to None and column_spacing to ([#751]) [#751]: https://github.com/ratatui/ratatui/pull/751 The default() implementation of Table now sets the column_spacing field to 1 and the segment_size field to `SegmentSize::None`. This will affect the rendering of a small amount of apps. To use the previous default values, call `table.segment_size(Default::default())` and `table.column_spacing(0)`. ### `patch_style` & `reset_style` now consumes and returns `Self` ([#754]) [#754]: https://github.com/ratatui/ratatui/pull/754 Previously, `patch_style` and `reset_style` in `Text`, `Line` and `Span` were using a mutable reference to `Self`. To be more consistent with the rest of `ratatui`, which is using fluent setters, these now take ownership of `Self` and return it. The following example shows how to migrate for `Line`, but the same applies for `Text` and `Span`. ```diff - let mut line = Line::from("foobar"); - line.patch_style(style); // becomes + let line = Line::new("foobar").patch_style(style); ``` ### Remove deprecated `Block::title_on_bottom` ([#757]) `Block::title_on_bottom` was deprecated in v0.22. Use `Block::title` and `Title::position` instead. ```diff - block.title("foobar").title_on_bottom(); + block.title(Title::from("foobar").position(Position::Bottom)); ``` ### `Block` style methods cannot be used in a const context ([#720]) [#720]: https://github.com/ratatui/ratatui/pull/720 Previously the `style()`, `border_style()` and `title_style()` methods could be used to create a `Block` in a constant context. These now accept `Into