These are less stable than the non-ref traits as we have not yet
committed to the exact API. This change moves them to ratatui from
ratatui-core.
To facilitate this:
- implementations of WidgetRef for all internal widgets are removed and
replaced with implementations of Widget for references to those
widgets.
- Widget is now implemented for Option<W> where W: Widget, allowing for
rendering of optional widgets.
- The blanket implementation of Widget for WidgetRef is reversed, to be
a blanket implementation of WidgetRef for all &W where W: Widget.
BREAKING CHANGE: implementations of WidgetRef no longer have a blanket
implementation of Widget, so Widgets should generally implement the
Widget trait on a reference to the widget rather than implementing
WidgetRef directly. This has the advantage of not requiring unstable
features to be enabled.
Part of: https://github.com/ratatui/ratatui/issues/1388
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
All the widgets now live in their own ratatui-widgets crate, but are re-exported in the main ratatui crate.
This makes it easier to use portions of the ratatui library and is part of the effort to modularize
Part of: #1388
---------
Co-authored-by: Orhun Parmaksız <orhun@archlinux.org>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
Bumps [unicode-truncate](https://github.com/Aetf/unicode-truncate) from
1.1.0 to 2.0.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/Aetf/unicode-truncate/releases">unicode-truncate's
releases</a>.</em></p>
<blockquote>
<h2>v2.0.0</h2>
<h3>Fixed</h3>
<ul>
<li><em>(deps)</em> update rust crate unicode-width to 0.2</li>
</ul>
<h3>Other</h3>
<ul>
<li>make release-plz use github app token</li>
<li>[<strong>breaking</strong>] bump MSRV to 1.66</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/Aetf/unicode-truncate/blob/master/CHANGELOG.md">unicode-truncate's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/Aetf/unicode-truncate/compare/v1.1.0...v2.0.0">2.0.0</a>
- 2024-11-10</h2>
<h3>Fixed</h3>
<ul>
<li><em>(deps)</em> update rust crate unicode-width to 0.2</li>
</ul>
<h3>Other</h3>
<ul>
<li>make release-plz use github app token</li>
<li>[<strong>breaking</strong>] bump MSRV to 1.66</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="95b4d26103"><code>95b4d26</code></a>
chore: release v2.0.0</li>
<li><a
href="4c0b472226"><code>4c0b472</code></a>
ci: make release-plz use github app token</li>
<li><a
href="2812162513"><code>2812162</code></a>
build!: bump MSRV to 1.66</li>
<li><a
href="8984d1529a"><code>8984d15</code></a>
fix(deps): update rust crate unicode-width to 0.2</li>
<li><a
href="abd6d916b9"><code>abd6d91</code></a>
fix(deps): update rust crate unicode-segmentation to v1.12.0</li>
<li>See full diff in <a
href="https://github.com/Aetf/unicode-truncate/compare/v1.1.0...v2.0.0">compare
view</a></li>
</ul>
</details>
<br />
[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=unicode-truncate&package-manager=cargo&previous-version=1.1.0&new-version=2.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
</details>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
`install-action` uses `cargo-binstall` to install the pre-built binaries
of `cargo-rdme` (which was released in
https://github.com/orium/cargo-rdme/releases/tag/v1.4.7).
This will make the `check-readme` step faster in CI (now takes only 10
seconds).
The buffer, layout, style, symbols, text, and the top level of widgets
modules are moved to ratatui-core. This is the first step in
modularizing the library so that the core types can be used in other
projects without the need for the backend / widgets types.
This helps reduce the need for updating other crates as often due to
semver changes outside of the core types.
---------
Co-authored-by: Orhun Parmaksız <orhun@archlinux.org>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
Adds two traits `IntoCrossterm` and `FromCrossterm` for converting
between ratatui and crossterm types. This is necessary in order to avoid
the orphan rule when implementing `From` for crossterm types once the
crossterm types are moved to a separate crate.
Similarly Termwiz and Termwiz gain FromTermion, IntoTermion, FromTermwiz
and IntoTermwiz traits.
BREAKING CHANGE: The `From` and `Into` impls for backend types are now
replaced
with specific backend traits.
```diff
+ use ratatui::backend::{FromCrossterm, IntoCrossterm};
let crossterm_color = crossterm::style::Color::Black;
- let ratatui_color = crossterm_color.into();
- let ratatui_color = ratatui::style::Color::from(crossterm_color);
+ let ratatui_color = ratatui::style::Color::from_crossterm(crossterm_color);
- let crossterm_color = ratatui_color.into();
- let crossterm_color = crossterm::style::Color::from(ratatui_color);
+ let crossterm_color = ratatui_color.into_crossterm();
let crossterm_attribute = crossterm::style::types::Attribute::Bold;
- let ratatui_modifier = crossterm_attribute.into();
- let ratatui_modifier = ratatui::style::Modifier::from(crossterm_attribute);
+ let ratatui_modifier = ratatui::style::Modifier::from_crossterm(crossterm_attribute);
- let crossterm_attribute = ratatui_modifier.into();
- let crossterm_attribute = crossterm::style::types::Attribute::from(ratatui_modifier);
+ let crossterm_attribute = ratatui_modifier.into_crossterm();
```
Similar conversions for `ContentStyle` -> `Style` and `Attributes` ->
`Modifier` exist for Crossterm,
and all the Termion and Termwiz types.
---------
Co-authored-by: Orhun Parmaksız <orhun@archlinux.org>
This removes the need for cargo-make and replaces it with a custom xtask
binary. See <https://github.com/matklad/cargo-xtask> for info.
Rearranges the CI workflow to use the new xtask and simplify which
workflows that run.
---------
Co-authored-by: Orhun Parmaksız <orhun@archlinux.org>
This is the first step towards modularization. Handling the move
as a separate step rather than combining it should make it easier
to rebase other PRs when necessary.
---------
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.210 to
1.0.213.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/serde-rs/serde/releases">serde's
releases</a>.</em></p>
<blockquote>
<h2>v1.0.213</h2>
<ul>
<li>Fix support for macro-generated <code>with</code> attributes inside
a newtype struct (<a
href="https://redirect.github.com/serde-rs/serde/issues/2847">#2847</a>)</li>
</ul>
<h2>v1.0.212</h2>
<ul>
<li>Fix hygiene of macro-generated local variable accesses in
serde(with) wrappers (<a
href="https://redirect.github.com/serde-rs/serde/issues/2845">#2845</a>)</li>
</ul>
<h2>v1.0.211</h2>
<ul>
<li>Improve error reporting about mismatched signature in
<code>with</code> and <code>default</code> attributes (<a
href="https://redirect.github.com/serde-rs/serde/issues/2558">#2558</a>,
thanks <a
href="https://github.com/Mingun"><code>@Mingun</code></a>)</li>
<li>Show variant aliases in error message when variant deserialization
fails (<a
href="https://redirect.github.com/serde-rs/serde/issues/2566">#2566</a>,
thanks <a
href="https://github.com/Mingun"><code>@Mingun</code></a>)</li>
<li>Improve binary size of untagged enum and internally tagged enum
deserialization by about 12% (<a
href="https://redirect.github.com/serde-rs/serde/issues/2821">#2821</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="58a8d22931"><code>58a8d22</code></a>
Release 1.0.213</li>
<li><a
href="ef0ed22593"><code>ef0ed22</code></a>
Merge pull request <a
href="https://redirect.github.com/serde-rs/serde/issues/2847">#2847</a>
from dtolnay/newtypewith</li>
<li><a
href="79925ac394"><code>79925ac</code></a>
Ignore dead_code warning in regression test</li>
<li><a
href="b60e4092ec"><code>b60e409</code></a>
Hygiene for macro-generated newtype struct deserialization with 'with'
attr</li>
<li><a
href="fdc36e5c06"><code>fdc36e5</code></a>
Add regression test for issue 2846</li>
<li><a
href="49e11ce1ba"><code>49e11ce</code></a>
Ignore trivially_copy_pass_by_ref pedantic clippy lint in test</li>
<li><a
href="7ae1b5f8f3"><code>7ae1b5f</code></a>
Release 1.0.212</li>
<li><a
href="1ac054b34a"><code>1ac054b</code></a>
Merge pull request <a
href="https://redirect.github.com/serde-rs/serde/issues/2845">#2845</a>
from dtolnay/withlocal</li>
<li><a
href="1e36ef551d"><code>1e36ef5</code></a>
Fix hygiene of macro-generated local variable accesses in serde(with)
wrappers</li>
<li><a
href="0058c7226e"><code>0058c72</code></a>
Add regression test for issue 2844</li>
<li>Additional commits viewable in <a
href="https://github.com/serde-rs/serde/compare/v1.0.210...v1.0.213">compare
view</a></li>
</ul>
</details>
<br />
[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=serde&package-manager=cargo&previous-version=1.0.210&new-version=1.0.213)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
</details>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- distingiush between empty bars and bars with a value of 0
- provide custom styling for empty bars
- provide custom styling for individual bars
- inverts the rendering algorithm to be item first
Closes: #1325
BREAKING CHANGE: `Sparkline::data` takes `IntoIterator<Item = SparklineBar>`
instead of `&[u64]` and is no longer const
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
This is a follow-up PR to https://github.com/ratatui/ratatui/pull/987,
which implemented alignment-aware truncation for the `Line` widget.
However, the truncation only checked the `Line::alignment` field, and
any alignment inherited from a parent's `Text::alignment` field would
not be used.
This commit updates the truncation of `Line` to depend both on the
individual `Line::alignment`, and on any alignment inherited from the
parent's `Text::alignment`.
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
Motivation for this is that there's a bunch of stuff at the bottom of the Readme that we don't really keep up to date. Instead it's better to link to the places that we do keep this info.
This PR adds a new feature for the existing `Layout::spacing` method,
and introducing a `Spacing` enum.
Now `Layout::spacing` is generic and can take
- zero or positive numbers, e.g. `Layout::spacing(1)` (current
functionality)
- negative number, e.g. `Layout::spacing(-1)` (new)
- variant of the `Spacing` (new)
This allows creating layouts with a shared pixel for segments. When
`spacing(negative_value)` is used, spacing is ignored and all segments
will be adjacent and have pixels overlapping.
`spacing(zero_or_positive_value)` behaves the same as before. These are
internally converted to `Spacing::Overlap` or `Spacing::Space`.
Here's an example output to illustrate the layout solve from this PR:
```rust
#[test]
fn test_layout() {
use crate::layout::Constraint::*;
let mut terminal = crate::Terminal::new(crate::backend::TestBackend::new(50, 4)).unwrap();
terminal
.draw(|frame| {
let [upper, lower] = Layout::vertical([Fill(1), Fill(1)]).areas(frame.area());
let (segments, spacers) = Layout::horizontal([Length(10), Length(10), Length(10)])
.flex(Flex::Center)
.split_with_spacers(upper);
for segment in segments.iter() {
frame.render_widget(
crate::widgets::Block::bordered()
.border_set(crate:🔣:border::DOUBLE),
*segment,
);
}
for spacer in spacers.iter() {
frame.render_widget(crate::widgets::Block::bordered(), *spacer);
}
let (segments, spacers) = Layout::horizontal([Length(10), Length(10), Length(10)])
.flex(Flex::Center)
.spacing(-1) // new feature
.split_with_spacers(lower);
for segment in segments.iter() {
frame.render_widget(
crate::widgets::Block::bordered()
.border_set(crate:🔣:border::DOUBLE),
*segment,
);
}
for spacer in spacers.iter() {
frame.render_widget(crate::widgets::Block::bordered(), *spacer);
}
})
.unwrap();
dbg!(terminal.backend());
}
```
```plain
┌────────┐╔════════╗╔════════╗╔════════╗┌────────┐
└────────┘╚════════╝╚════════╝╚════════╝└────────┘
┌─────────┐╔════════╔════════╔════════╗┌─────────┐
└─────────┘╚════════╚════════╚════════╝└─────────┘
```
Currently drawing a border on top of an existing border overwrites it.
Future PRs will allow for making the border drawing handle overlaps
better.
---------
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
BREAKING CHANGE: The Rect Positions iterator no longer has public
fields. The `rect` and `current_position` fields have been made private
as they were not intended to be accessed directly.
BREAKING-CHANGE: Previously `Color::from_hsl` accepted components
as individual f64 parameters. It now accepts a single `palette::Hsl`
value
and is gated behind a `palette` feature flag.
```diff
- Color::from_hsl(360.0, 100.0, 100.0)
+ Color::from_hsl(Hsl::new(360.0, 100.0, 100.0))
```
Fixes: <https://github.com/ratatui/ratatui/issues/1414>
---------
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
We pin unicode-width to avoid breaking applications when there are breaking changes in the library.
Discussion in #1271Fixes: #1385
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
The current implementation of Terminal::insert_before causes the
viewport to flicker. This is described in #584 .
This PR removes that flickering by using terminal scrolling regions
(sometimes called "scroll regions"). A terminal can have its scrolling
region set to something other than the whole screen. When a scroll ANSI
sequence is sent to the terminal and it has a non-default scrolling
region, the terminal will scroll just inside of that region.
We use scrolling regions to implement insert_before. We create a region
on the screen above the viewport, scroll that up to make room for the
newly inserted lines, and then draw the new lines. We may need to repeat
this process depending on how much space there is and how many lines we
need to draw.
When the viewport takes up the entire screen, we take a modified
approach. We create a scrolling region of just the top line (could be
more) of the viewport, then use that to draw the lines we want to
output. When we're done, we scroll it up by one line, into the
scrollback history, and then redraw the top line from the viewport.
A final edge case is when the viewport hasn't yet reached the bottom of
the screen. This case, we set up a different scrolling region, where the
top is the top of the viewport, and the bottom is the viewport's bottom
plus the number of lines we want to scroll by. We then scroll this
region down to open up space above the viewport for drawing the inserted
lines.
Regardless of what we do, we need to reset the scrolling region. This PR
takes the approach of always resetting the scrolling region after every
operation. So the Backend gets new scroll_region_up and
scroll_region_down methods instead of set_scrolling_region, scroll_up,
scroll_down, and reset_scrolling_region methods. We chose that approach
for two reasons. First, we don't want Ratatui to have to remember that
state and then reset the scrolling region when tearing down. Second, the
pre-Windows-10 console code doesn't support scrolling regio
This PR:
- Adds a new scrolling-regions feature.
- Adds two new Backend methods: scroll_region_up and scroll_region_down.
- Implements those Backend methods on all backends in the codebase.
- The crossterm and termion implementations use raw ANSI escape
sequences. I'm trying to merge changes into those two projects
separately to support these functions.
- Adds code to Terminal::insert_before to choose between
insert_before_scrolling_regions and insert_before_no_scrolling_regions.
The latter is the old implementation.
- Adds lots of tests to the TestBackend to for the
scrolling-region-related Backend methods.
- Adds versions of terminal tests that show that insert_before doesn't
clobber the viewport. This is a change in behavior from before.
BREAKING-CHANGE: The `pub` modifier has been removed from fields on the
`layout::rect::Columns` and `layout::rect::Rows` iterators. These fields
were not intended to be public and should not have been accessed
directly.
Fixes: #1357
This change fixes the unexpected behavior of the Rect::new() function to
be more intuitive. The Rect::new() function now clamps the width and
height of the rectangle to keep each bound within u16::MAX. The
Rect::area() function now returns a u32 instead of a u16 to allow for
larger areas to be calculated.
Previously, the Rect::new() function would clamp the total area of the
rectangle to u16::MAX, by preserving the aspect ratio of the rectangle.
BREAKING CHANGE: Rect::area() now returns a u32 instead of a u16.
Fixes: <https://github.com/ratatui/ratatui/issues/1375>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
BREAKING-CHANGES: `Line` now implements `From<Cow<str>`
As this adds an extra conversion, ambiguous infered values may no longer
compile.
```rust
// given:
struct Foo { ... }
impl From<Foo> for String { ... }
impl From<Foo> for Cow<str> { ... }
let foo = Foo { ... };
let line = Line::from(foo); // now fails due to ambiguous type inference
// replace with
let line = Line::from(String::from(foo));
```
Fixes: https://github.com/ratatui/ratatui/issues/1367
---------
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
`Tabs::select()` now accepts `Into<Option<usize>>` instead of `usize`.
This allows tabs to be deselected by passing `None`.
`Tabs::default()` is now also implemented manually instead of deriving
`Default`, and a new method `Tabs::titles()` is added to set the titles
of the tabs.
Fixes: <https://github.com/ratatui/ratatui/pull/1412>
BREAKING CHANGE: `Tabs::select()` now accepts `Into<Option<usize>>`
which breaks any code already using parameter type inference:
```diff
let selected = 1u8;
- let tabs = Tabs::new(["A", "B"]).select(selected.into())
+ let tabs = Tabs::new(["A", "B"]).select(selected as usize)
```
Fixes https://github.com/ratatui-org/ratatui/issues/1250
Adds support for selecting a column and cell in `TableState`. The
selected column, and cells style can be set by
`Table::column_highlight_style` and `Table::cell_highlight_style`
respectively.
The table example has also been updated to display the new
functionality:
https://github.com/user-attachments/assets/e5fd2858-4931-4ce1-a2f6-a5ea1eacbecc
BREAKING CHANGE: The Serialized output of the state will now include the
"selected_column" field. Software that manually parse the serialized the
output (with anything other than the `Serialize` implementation on
`TableState`) may have to be refactored if the "selected_column" field
is not accounted for. This does not affect users who rely on the
`Deserialize`, or `Serialize` implementation on the state.
BREAKING CHANGE: The `Table::highlight_style` is now deprecated in favor
of `Table::row_highlight_style`.
---------
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>