53 Commits

Author SHA1 Message Date
Jagoda Estera Ślązak
daeba85f14
build(deps): bump kasuari and line-clipping (#1844) 2025-05-12 01:55:49 -07:00
Josh McKinney
93143126b3
fix(layout): feature flag cache related types (#1842) 2025-05-11 01:55:12 -07:00
Jagoda Estera Ślązak
2dd1977c59
fix(layout-cache): import NonZeroUsize only when layout-cache is enabled (#1839)
This silences unused import warning, when `layout-cache` is disabled.
2025-05-10 08:09:47 -07:00
Jagoda Estera Ślązak
3e1c72fb27
feat(no_std)!: make ratatui compatible with #![no_std] (#1794)
Resolves #1781

This PR makes it possible to compile ratatui with `#![no_std]`.
Also makes me answer "We Are So Embedded" to "Are We Embedded Yet?"
2025-05-07 13:42:03 -07:00
Jagoda Estera Ślązak
ab48c06171
feat(no_std)!: option to disable layout cache for no_std compatibility (#1795)
Resolves #1780 

BREAKING CHANGE: Disabling `default-features` will now disable layout
cache, which can have a negative impact on performance.
`Layout::init_cache` and `Layout::DEFAULT_CACHE_SIZE` are now only
available if `layout-cache` feature is enabled.
2025-05-07 13:00:22 -07:00
Jagoda Estera Ślązak
09173d1829
feat(no_std)!: make TestBackend::Error Infallible (#1823)
BREAKING CHANGE: `TestBackend` now uses `core::convert::Infallible` for
error handling instead of `std::io::Error`
2025-05-07 00:33:26 -07:00
Tatesa Uradnik
08b08cc45b
feat(rect): centering (#1814)
Resolves #617
2025-04-28 11:16:58 -07:00
Jagoda Estera Ślązak
007713e50a
feat(no_std)!: replace Backend's io::Error usages with associated Error type (#1778)
Resolves #1775 

BREAKING CHANGE: Custom backends now have to implement `Backend::Error`
and `Backend::clear_region`. Additionally some generic `Backend` usage
will have to explicitly set trait bounds for `Backend::Error`.
2025-04-23 15:05:59 -07:00
Tyler Breisacher
d88cd29079
chore: Add 'const' to functions where possible. (#1802)
The Clippy check for this (missing_const_for_fn) is already enabled, but
catches more cases in upcoming toolchain versions.

This is part of the work to unblock #1727
2025-04-20 18:48:49 -07:00
Josh McKinney
bb068892c9
chore: fix io_other_error clippy lints (#1756)
Pre-emptive fix for new lint to be added in 1.87 (currently in beta).

https://rust-lang.github.io/rust-clippy/master/index.html\#io_other_error
2025-04-15 11:09:05 -07:00
cgzones
deb1b8ec43
test: ensure Style::new() and Style::default() are equivalent (#1789) 2025-04-15 10:21:19 -07:00
cgzones
0f80c5e87e
chore!: use expect() instead of allow() for lint overrides (#1786)
BREAKING CHANGE: MSRV is now 1.81
2025-04-15 10:20:22 -07:00
Edwin Burwell
07bec55b7d
refactor(no_std): Make usages of std explicit in ratatui-core. (#1782)
### This commit does the following:

- Adds `#[no_std]` to `lib.rs`.
- Adds `extern crate std;` to `lib.rs`.
- Updates `ratatui-core` to explicitly `use` items from std and alloc.
- Prefers `use`-ing alloc over std when possible.

### Explanation:

This allows usages of `std` in `ratatui-core` to be clearly pointed out
and dealt with individually.

Eventually, when `std` is to be feature gated, the associated commit
will be much cleaner.
2025-04-15 09:14:25 -07:00
cgzones
02e53de0f8
refactor: make use of iter::repeat_n() (#1788)
Applied via clippy --fix.
Available since 1.82.0.
2025-04-14 21:43:38 +03:00
cgzones
c90ba9781e
fix: avoid unnecessary imports in minimal build (#1787)
core::ops::Range is only used with the feature `scrolling-regions`.
Ensure a minimal `cargo check` reports no warnings.
2025-04-14 21:38:47 +03:00
Ben Beasley
fc4b996c59
build(deps): update compact_str requirement from 0.8.1 to 0.9.0 (#1783)
Looking at
https://github.com/ParkMyCar/compact_str/blob/v0.9.0/CHANGELOG.md#090,
there are a few API changes, but it doesn’t seem like anything there
should be a problem given that `cargo test` still passes in
`ratatui-core/`.
2025-04-13 10:51:21 +03:00
Austin Schey
6836a6903e
feat: implement styled for other primitives (#1684) 2025-04-11 07:52:33 -07:00
Josh McKinney
fcb47d60f3
feat!: rename Alignment to HorizontalAlignment and add VerticalAlignment (#1735)
We don't anticipate removing or deprecating the type alias in the near
future, but it is recommended to update your imports to use the new
name.

Added a VerticalAlignment enum to make the API more consistent. We don't
have a specific use case for it yet, but it's better to add it now and
be able to use it in the future.

BREAKING-CHANGE: The `Alignment` enum has been renamed to
`HorizontalAlignment` to better reflect its purpose. A type alias has
been added to maintain backwards compatibility, however there are some
cases where type aliases are not enough to maintain backwards
compatibility. E.g. when using glob imports to import all the enum
variants. This should not affect most users, but it is recommended to
update your imports to use the new name.

```diff
- use ratatui::layout::Alignment;
+ use ratatui::layout::HorizontalAlignment;

- use Alignment::*;
+ use HorizontalAlignment::*;
```
2025-04-06 20:00:59 +03:00
Jagoda Estera Ślązak
2be9ccb120
docs(layout): remove unnecessary path prefix (#1766) 2025-04-06 18:19:36 +03:00
Jagoda Estera Ślązak
b669cebcaf
docs(layout): change cassowary to kasuari crate reference (#1765) 2025-04-06 18:19:19 +03:00
Jagoda Estera Ślązak
cef617cc35
chore(lint): add std instead of core/alloc lints to ratatui-core (#1759)
Resolves #1752
2025-04-04 03:59:22 -07:00
Josh McKinney
3d5b250e74
build(deps): use kasuari instead of cassowary (#1758)
[Kasuari](https://github.com/ratatui/kasuari) is a maintained fork of Cassowary.
2025-04-04 00:03:39 -07:00
Jagoda Estera Ślązak
ebe10cd81f
feat(no_std): remove redundant std usages in ratatui-core (#1753)
Resolves https://github.com/ratatui/ratatui/issues/1751
2025-04-03 20:02:54 -07:00
Jagoda Estera Ślązak
416ebdf8c8
fix: correct clippy errors introduced by rust 1.86.0 update (#1755)
New version of rust (1.86.0) caused CI to fail.
2025-04-03 16:43:12 -07:00
Josh McKinney
2739391950
style: use Module imports_granularity (#1728)
I was swayed by the arguments about this made by the compiler team In
<https://github.com/rust-lang/compiler-team/issues/750> and decided to
look at how this organization affects ratatui. I found this reduces the
number of lines across the codebase by about 350 and makes the imports
more readable and definitely more greppable as you usually only have
to read a single line. I've found in the past that maintaining imports
regularly leads to merge conflicts which have to be resolved by hand
and this change should reduce the likelihood of that happening.

Main change is in rustfmt.toml, and the rest is just the result of
running `cargo xtask format`.

While implementing this, cargo machete brings up that the various
backend crates are unused by the example crates.

The re-export of each backend crate under ratatui is to make it possible
for libs that rely on a specific version of ratatui to use the same
version of the backend crate. Apps in general should use the backend
crate directly rather than through ratatui as this is less confusing.

- Removes all usages of `ratatui::{crossterm, termion, termwiz}`` in the
  examples.
- Adds the backend crate to the dependencies of the examples that use
  the backend crate directly.
2025-03-19 16:48:02 -07:00
Josh McKinney
fe8577c070
chore: remove paste dependency (#1713)
The paste crate is no longer maintained. Replaces the usages of this in
the Stylize declarative macros with hard coded values. These macros are
internal implementation deatil to ratatui and so the changes should have
no impact on users.

Fixes: https://github.com/ratatui/ratatui/issues/1712
2025-03-09 08:56:06 -07:00
Josh McKinney
4eac5b2849
fix: make deprecation notes more helpful (#1702)
AI coding assistants use the deprecation notes to automatically suggest
fixes. This commit updates the deprecation notes to push those tools to
suggest the correct replacement methods and types.

Specifically, AI tools often suggest using `Buffer::get(x, y)`, because
of their training data where this was prevalent. When fixing these
deprecations, they often incorrectly suggest using `Buffer::get(x, y)`
instead of `Buffer[(x, y)]`.
2025-03-04 11:56:44 -08:00
Josh McKinney
2714d6b9c3
feat: add array and tuple RGB color conversion methods (#1703)
Other crates (e.g. colorgrad) that deal with colors can convert colors
to a tuple of 3 or 4 u8 values. This commit adds conversion methods from
these types to a `Color::Rgb` instance. Any alpha value is ignored.

```rust
Color::from([255, 0, 0]);
Color::from((255, 0, 0));
Color::from([255, 0, 0, 255]);
Color::from((255, 0, 0, 255));
```
2025-03-04 11:52:54 -08:00
github-actions[bot]
c10d0f12e8
chore: release (#1671)
## 🤖 New release

* `ratatui-core`: 0.1.0-alpha.2 -> 0.1.0-alpha.3
* `ratatui-crossterm`: 0.1.0-alpha.1 -> 0.1.0-alpha.2
* `ratatui-widgets`: 0.3.0-alpha.1 -> 0.3.0-alpha.2
* `ratatui-macros`: 0.7.0-alpha.0 -> 0.7.0-alpha.1
* `ratatui-termwiz`: 0.1.0-alpha.1 -> 0.1.0-alpha.2
* `ratatui-termion`: 0.1.0-alpha.1 -> 0.1.0-alpha.2
* `ratatui`: 0.30.0-alpha.1 -> 0.30.0-alpha.2
2025-03-01 15:34:53 -08:00
Orhun Parmaksız
22e3e84de8
docs(core): remove link to Paragraph widget (#1683) 2025-02-21 12:12:16 -08:00
John T. Wodder II
35a86427ab
fix: Rect::positions() should be empty when width is 0 and height is nonzero (#1669)
Fixes #1666.
2025-02-11 13:51:48 -08:00
Théo Tchilinguirian
985cd05573
feat(symbols): add dashed borders (#1573)
Adds several new border sets:
- ratatui:🔣:border::LIGHT_DOUBLE_DASHED
- ratatui:🔣:border::HEAVY_DOUBLE_DASHED
- ratatui:🔣:border::LIGHT_TRIPLE_DASHED
- ratatui:🔣:border::HEAVY_TRIPLE_DASHED
- ratatui:🔣:border::LIGHT_QUADRUPLE_DASHED
- ratatui:🔣:border::HEAVY_QUADRUPLE_DASHED

And corresponding variants to the ratatui::widgets::BorderType enum

Fixes: https://github.com/ratatui/ratatui/issues/1355
Signed-off-by: Théo Tchilinguirian <theo.tchlx@gmail.com>
2025-01-20 00:36:19 -08:00
Josh McKinney
e7831aedd4
chore: release 0.30.0-alpha.1 (#1618)
Versions:

```
ratatui = { path = "ratatui", version = "0.30.0-alpha.1" }
ratatui-core = { path = "ratatui-core", version = "0.1.0-alpha.2" }
ratatui-crossterm = { path = "ratatui-crossterm", version = "0.1.0-alpha.1" }
ratatui-termion = { path = "ratatui-termion", version = "0.1.0-alpha.1" }
ratatui-termwiz = { path = "ratatui-termwiz", version = "0.1.0-alpha.1" }
ratatui-widgets = { path = "ratatui-widgets", version = "0.3.0-alpha.1" }
```
2025-01-15 15:31:38 -08:00
Josh McKinney
904b0aa723
refactor: move symbols to modules (#1594) 2024-12-26 04:05:05 -08:00
Josh McKinney
1d28c89fe5
feat: add conversions for anstyle (#1581)
https://crates.io/crates/anstyle makes it possible to define colors in
an interoperable way. This makes it possible for applications to easily
load colors from a variety of formats.

This is gated by the anstyle feature flag which is disabled by default.

---------

Co-authored-by: Orhun Parmaksız <orhun@archlinux.org>
2024-12-24 12:03:14 -08:00
Orhun Parmaksız
9a541981b8
chore: make source files non-executable (#1577)
```bash
find . -type f -not -path './.git/*' -not -name '*.bash' -exec chmod 644 {} +
```

fixes #1576
2024-12-17 17:33:06 +03:00
EdJoPaTo
f57b696fdc
fix(span): dont render control characters (#1312) 2024-12-08 02:10:58 -08:00
Josh McKinney
9275d3421c
feat(layout): add Offset::new() constructor (#1547) 2024-12-04 12:57:38 -08:00
raylu
7c8573f575
refactor: rearrange selection_spacing code (#1540) 2024-12-03 00:11:47 -08:00
Josh McKinney
357ae7e251
chore: move terminal types to ratatui-core (#1530)
- Move Terminal, TerminalOptions, ViewPort, CompletedFrame, Frame to
  ratatui-core crate
- Move render_widget_ref() and render_stateful_widget_ref() to extension
  trait (FrameExt) due as the Ref types are unstable and kept in the
  main lib instead of -core
- Fix rustdoc errors / feature config issues

BREAKING CHANGE: to call `Frame::render_widget_ref()` or
`Frame::render_stateful_widget_ref()` you now need to import the
FrameExt trait from `ratatui::widgets` and enable the
`unstable-widget-ref` feature.

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2024-11-30 17:11:17 -08:00
Josh McKinney
d3f01ebf6e
chore(lint): ensure lint config is correct (#1528)
- Move lints to workspace manifest
- Add lint config to backend crates
- Fix one small lint error
2024-11-30 11:13:50 +03:00
Josh McKinney
2892bddce6
fix: rust 1.83 clippy lints (#1527)
https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
2024-11-29 10:49:12 +03:00
Josh McKinney
fbf6050c86
chore: prepare alpha modularization release (#1525)
This is the first modularization -alpha release. It captures the changes
necessary to manual publish. And ensures all the crates are properly
setup and to set a baseline for comparison in future release checks etc.

This does not update / check the git-cliff setup / changelog

Part of: #1388
2024-11-28 16:47:43 -08:00
Orhun Parmaksız
217c57cd60
refactor: modularize backends (#1508)
Backend code is now moved to `ratatui-crossterm`, `ratatui-termion` and
`ratatui-termwiz`. This should be backwards compatible with existing code.

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2024-11-23 15:23:40 -08:00
Josh McKinney
36e2d1bda1
fix: add feature(doc_cfg) when generating docs (#1506) 2024-11-20 04:17:13 -08:00
thscharler
4d7704fba5
fix: Make StatefulWidget and Ref work with unsized State (#1505)
StatefulWidget::State and StatefulWidgetRef::State are now ?Sized.

This allows implementations of the traits to use unsized types for the
State associated type. This is turn is useful when doing things like
boxing different stateful widget types with State which implements
`Any`, are slices or any other dynamically sized type.

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2024-11-19 17:56:26 -08:00
Josh McKinney
a41c97b413
chore: move unstable widget refs to ratatui (#1491)
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>
2024-11-18 14:19:21 -08:00
Orhun Parmaksız
46902f5587
docs: improve docs for workspace crates (#1490)
Overall makes improvements in the documentation of the workspace crates and checking them.
2024-11-18 02:03:44 +03:00
Josh McKinney
e7085e3a3e
chore: move widgets into ratatui-widgets crate (#1474)
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>
2024-11-15 19:42:07 -08:00
Josh McKinney
e461b724a6
refactor: move {Stateful,}Widget{,Ref} types into individual files (#1479)
This is a preparatory refactoring for modularization. No user visible
changes.
2024-11-12 15:34:48 +03:00