* feat(barchart): Add direction attribute
Enable rendring the bars horizontally. In some cases this allow us to
make more efficient use of the available space.
Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
* feat(barchart)!: render the group labels depending on the alignment
This is a breaking change, since the alignment by default is set to
Left and the group labels are always rendered in the center.
Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
---------
Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Previously the layout used the floor of the calculated start and width
as the value to use for the split Rects. This resulted in gaps between
the split rects.
This change modifies the layout to round to the nearest column instead
of taking the floor of the start and width. This results in the start
and end of each rect being rounded the same way and being strictly
adjacent without gaps.
Because there is a required constraint that ensures that the last end is
equal to the area end, there is no longer the need to fixup the last
item width when the fill (as e.g. width = x.99 now rounds to x+1 not x).
The colors example has been updated to use Ratio(1, 8) instead of
Percentage(13), as this now renders without gaps for all possible sizes,
whereas previously it would have left odd gaps between columns.
The track symbol is now optional, simplifying composition with other
widgets.
BREAKING_CHANGE: The `track_symbol` needs to be set in the following way
now:
```
let scrollbar = Scrollbar::default().track_symbol(Some("-"));
```
The symbols and sets are moved from `widgets::scrollbar` to
`symbols::scrollbar`. This makes it consistent with the other symbol
sets and allows us to make the scrollbar module private rather than
re-exporting it.
BREAKING CHANGE: The symbols are now in the `symbols` module. To update
your code, add an import for `ratatui:🔣:scrollbar::*` (or the
specific symbols you need). The scrollbar module is no longer public. To
update your code, remove any `widgets::scrollbar` imports and replace it
with `ratatui::widgets::Scrollbar`.
This commit adds a readme to the examples directory with gifs of each
example. This should make it easier to see what each example does
without having to run it.
I modified the examples to fit better in the gifs. Mostly this was just
removing the margins, but for the block example I cleaned up the code a
bit to make it more readable and changed it so the background bug is not
triggered.
For the table example, the combination of Min, Length, and Percent
constraints was causing the table to panic when the terminal was too
small. I changed the example to use the Max constraint instead of the
Length constraint.
The layout example now shows information about how the layout is
constrained on each block (which is now a paragraph with a block).
This helps to keep the prelude small and less likely to conflict with
other crates.
- remove widgets module from prelude as the entire module can be just as
easily imported with `use ratatui::widgets::*;`
- move prelude module into its own file
- update examples to import widgets module instead of just prelude
- added several modules to prelude to make it possible to qualify
imports that collide with other types that have similar names
for now the value is converted to a string and then printed. in many
cases the values are too wide or double values. so it make sense
to set a custom value text instead of the default behavior.
this patch suggests to add a method
"fn text_value(mut self, text_value: String)"
to the Bar, which allows to override the value printed in the bar
Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
The user_input example now responds to left/right and allows the
character at the cursor position to be deleted / inserted.
Co-authored-by: Leon Sautour <leon1.sautour@epitech.eu>
* feat(barchart): allow to add a group of bars
Example: to show the revenue of different companies:
┌────────────────────────┐
│ ████ │
│ ████ │
│ ████ ████ │
│ ▄▄▄▄ ████ ████ ████ │
│ ████ ████ ████ ████ │
│ ████ ████ ████ ████ │
│ █50█ █60█ █90█ █55█ │
│ Mars April │
└────────────────────────┘
new structs are introduced: Group and Bar.
the data function is modified to accept "impl Into<Group<'a>>".
a new function "group_gap" is introduced to set the gap between each group
unit test changed to allow the label to be in the center
Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
* feat(barchart)!: center labels by default
The bar labels are currently printed string from the left side of
bar. This commit centers the labels under the bar.
Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
---------
Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Before this change, it wasn't possible to build all features and all
targets at the same time, which prevents rust-analyzer from working
for the whole project.
Adds a bacon.toml file to the project, which is used by bacon
https://dystroy.org/bacon/
Configures docs.rs to show the feature flags that are necessary to
make modules / types / functions available.
Represents a scrollbar widget that renders a track, thumb and arrows
either horizontally or vertically. State is kept in ScrollbarState, and
passed as a parameter to the render function.
* fix(gauge): render gauge with unicode correctly
Gauge now correctly renders a block rather than a space when in unicode mode.
* docs: update demo.gif
- remove existing gif
- upload using VHS (https://github.com/charmbracelet/vhs)
- add instructions to RELEASE.md
- link new gif in README
This is an opinionated default that helps avoid horizontal scrolling.
100 is the most common width on github rust projects and works well for
displaying code on a 16in macbook pro.
- Reformat summary info
- Add badges for dependencies, discord, license
- point existing badges to shields.io
- add Table of Contents
- tweaked installation instructions to show instructions for new and
existing crates
- moved fork status lower
- chop lines generally to 100 limit
- add a quickstart based on a simplified hello_world example
- added / updated some internal links to point locally
- removed some details to simplify the readme (e.g. tick-rate)
- reordered widgets and pointed these at the widget docs
- adds a hello_world example that has just the absolute basic code
necessary to run a ratatui app. This includes some comments that help
guide the user towards other approaches and considerations for a real
world app.
* refactor: add Line type to replace Spans
`Line` is a significantly better name over `Spans` as the plural causes
confusion and the type really is a representation of a line of text made
up of spans.
This is a backwards compatible version of the approach from
https://github.com/tui-rs-revival/ratatui/pull/175
There is a significant amount of code that uses the Spans type and
methods, so instead of just renaming it, we add a new type and replace
parameters that accepts a `Spans` with a parameter that accepts
`Into<Line>`.
Note that the examples have been intentionally left using `Spans` in
this commit to demonstrate the compiler warnings that will be emitted in
existing code.
Implementation notes:
- moves the Spans code to text::spans and publicly reexports on the text
module. This makes the test in that module only relevant to the Spans
type.
- adds a line module with a copy of the code and tests from Spans with a
single addition: `impl<'a> From<Spans<'a>> for Line<'a>`
- adds tests for `Spans` (created and checked before refactoring)
- adds the same tests for `Line`
- updates all widget methods that accept and store Spans to instead
store `Line` and accept `Into<Line>`
* refactor: move text::Masked to text::masked::Masked
Re-exports the Masked type at text::Masked
* refactor: replace Spans with Line in tests/examples/docs
* build: bump MSRV to 1.65
The latest version of the time crate requires Rust 1.65.0
```
cargo +1.64.0-x86_64-apple-darwin test --no-default-features \
--features serde,crossterm,all-widgets --lib --tests --examples
error: package `time v0.3.21` cannot be built because it requires rustc
1.65.0 or newer, while the currently active rustc version is 1.64.0
```
* feat(backend): add termwiz backend and demo
* ci(termwiz): add termwiz to makefile.toml
---------
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
Co-authored-by: Prabir Shrestha <mail@prabir.me>
Adds a new type Masked that can mask data with a mask character, and can
be used anywhere we expect Cow<'a, str> or Text<'a>. E.g. Paragraph,
ListItem, Table Cells etc.
BREAKING CHANGE:
Because Masked implements From for Text<'a>, code that binds
Into<Text<'a>> without type annotations may no longer compile
(e.g. `Paragraph::new("".as_ref())`)
To fix this, annotate or call to_string() / to_owned() / as_str()
Without a terminal-resetting panic hook there are two main problems when
an application panics:
1. The report of the panic is distorted because the terminal has not
properly left the alternate screen and is still in raw mode.
2. The terminal needs to be manually reset with the `reset` command.
To avoid this, the standard panic hook can be extended to first reset
the terminal.
Third column in table example was using the `Max` constraint.
But since version 0.16, the layout system does not add a hidden constraint on the last column which would ensure that it fills the remaining available space (a change that was already mentioned in #525). In addition, `tui` does not support sizing based on content because of its immediate mode nature. Therefore, `Max` is now resolved to `0`. Replacing with `Min` fixes the issue.
A new way of specifying constraints is being worked on at #519 which should for more deterministic and advanced layout.