Commit graph

49 commits

Author SHA1 Message Date
EdJoPaTo
c12bcfefa2
refactor(non-src): apply pedantic lints (#976)
Fixes many not yet enabled lints (mostly pedantic) on everything that is
not the lib (examples, benchs, tests). Therefore, this is not containing
anything that can be a breaking change.

Lints are not enabled as that should be the job of #974. I created this
as a separate PR as its mostly independent and would only clutter up the
diff of #974 even more.

Also see
https://github.com/ratatui-org/ratatui/pull/974#discussion_r1506458743

---------

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2024-03-02 01:06:53 -08:00
Josh McKinney
87bf1dd9df
feat: replace Rect::split with Layout::areas and spacers (#904)
In a recent commit we added Rec::split, but this feels more ergonomic as
Layout::areas. This also adds Layout::spacers to get the spacers between
the areas.
2024-02-01 20:26:35 -08:00
Emirhan TALA
5b7ad2ad82
docs(examples): update gauge example (#863)
- colored gauges
- removed box borders
- show the difference between ratio / percentage and unicode / no unicode better
- better application approach (consistent with newer examples)
- various changes for 0.26 featuers
- impl `Widget` for `&App`
- use color_eyre

for gauge.tape

- change to get better output from the new code

---------
Fixes: https://github.com/ratatui-org/ratatui/issues/846
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2024-01-27 01:47:17 -08:00
Josh McKinney
f383625f0e
docs(examples): add note about example versions to all examples (#871) 2024-01-24 11:50:18 -08:00
Josh McKinney
fb93db0730
docs(examples): simplify docs using new layout methods (#731)
Use the new `Layout::horizontal` and `vertical` constructors and
`Rect::split_array` through all the examples.
2024-01-05 07:45:14 -08:00
Josh McKinney
0c52ff431a
fix(gauge): fix gauge widget colors (#572)
The background colors of the gauge had a workaround for the issue we had
with VHS / TTYD rendering the background color of the gauge. This
workaround is no longer necessary in the updated versions of VHS / TTYD.

Fixes https://github.com/ratatui-org/ratatui/issues/501
2023-10-19 04:29:53 -07:00
Josh McKinney
fbf1a451c8
chore: simplify constraints (#556)
Use bare arrays rather than array refs / Vecs for all constraint
examples.

Ref: https://github.com/ratatui-org/ratatui-book/issues/94
2023-10-03 16:50:14 -07:00
Josh McKinney
082cbcbc50
feat(frame)!: Remove generic Backend parameter (#530)
This change simplifys UI code that uses the Frame type. E.g.:

```rust
fn draw<B: Backend>(frame: &mut Frame<B>) {
    // ...
}
```

Frame was generic over Backend because it stored a reference to the
terminal in the field. Instead it now directly stores the viewport area
and current buffer. These are provided at creation time and are valid
for the duration of the frame.

BREAKING CHANGE: Frame is no longer generic over Backend. Code that
accepted `Frame<Backend>` will now need to accept `Frame`. To migrate
existing code, remove any generic parameters from code that uses an
instance of a Frame. E.g. the above code becomes:

```rust
fn draw(frame: &mut Frame) {
    // ...
}
```
2023-09-25 22:30:36 -07:00
Josh McKinney
add578a7d6
docs(examples): Add examples readme with gifs (#303)
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).
2023-07-24 19:05:37 +00:00
Josh McKinney
446efae185
fix(prelude): remove widgets module from prelude (#317)
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
2023-07-16 09:11:59 +00:00
Josh McKinney
804115ac6f
feat(prelude): add a prelude (#304)
This allows users of the library to easily use ratatui without a huge amount of imports
2023-07-10 22:59:01 +00:00
Chris Morris
43bac80e4d
fix(examples): Correct progress label in gague example (#263) 2023-06-16 09:17:04 +00:00
Josh McKinney
f7af8a3863
style: reformat imports (#219)
Order imports by std, external, crate and group them by crate
2023-06-12 05:07:15 +00:00
Yuri Astrakhan
e08b466166
chore: inline format args (#190) 2023-05-21 20:46:02 -07:00
Orhun Parmaksız
ed12ab16e0
chore(cargo): update project metadata (#94) 2023-03-17 17:03:49 +01:00
Florian Dehau
6069d89dee chore: fix all clippy warnings 2021-12-23 18:55:43 +01:00
Florian Dehau
9806217a6a feat!: use crossterm as default backend 2021-11-01 23:21:55 +01:00
Florian Dehau
8da5f740af refactor(examples): show more use case in gauge example 2021-06-16 20:24:14 +02:00
Florian Dehau
79e27b1778 refactor(widgets/gauge): stop using unicode blocks by default 2020-11-29 19:27:34 +01:00
DashEightMate
0a05579a1c
feat(widgets/gauge): allow gauge to use unicode block for more descriptive progress (#377)
* gauge now uses unicode blocks for more descriptive progress

* removed unnecessary if

* changed function name to better reflect unicode

* standardized block symbols, added no unicode option, added tests

* formatting

* improved readability

* gauge tests now check color

* formatted
2020-11-29 19:20:08 +01:00
Florian Dehau
0ffea495b1 refactor: implement cascading styles
- merge `Style` and `StyleDiff` together. `Style` now is used to activate or deactivate certain
style rules not to overidden all of them.
- update all impacted widgets, examples and tests.
2020-07-17 20:58:20 +02:00
Florian Dehau
72ba4ff2d4 refactor(examples): remove unecessary terminal.hide_cursor calls 2020-07-10 23:56:46 +02:00
Florian Dehau
88c4b191fb feat(text): add new text primitives 2020-07-10 22:59:24 +02:00
Alexander Batischev
8c2ee0ed85
feat(terminal): Add after-draw() cursor control to Frame (#91) (#309) 2020-06-15 22:57:23 +02:00
Florian Dehau
3f62ce9c19 chore: remove unecessary dependencies
* Remove log, stderrlog, structopt
* Add argh
2020-03-13 02:07:13 +01:00
Florian Dehau
6cb57f5d2a feat: add stateful widgets
Most widgets can be drawn directly based on the input parameters. However, some
features may require some kind of associated state to be implemented.

For example, the `List` widget can highlight the item currently selected. This
can be translated in an offset, which is the number of elements to skip in
order to have the selected item within the viewport currently allocated to this
widget. The widget can therefore only provide the following behavior: whenever
the selected item is out of the viewport scroll to a predefined position (make
the selected item the last viewable item or the one in the middle).
Nonetheless, if the widget has access to the last computed offset then it can
implement a natural scrolling experience where the last offset is reused until
the selected item is out of the viewport.

To allow such behavior within the widgets, this commit introduces the following
changes:
- Add a `StatefulWidget` trait with an associated `State` type. Widgets that
can take advantage of having a "memory" between two draw calls needs to
implement this trait.
- Add a `render_stateful_widget` method on `Frame` where the associated
state is given as a parameter.

The chosen approach is thus to let the developers manage their widgets' states
themselves as they are already responsible for the lifecycle of the wigets
(given that the crate exposes an immediate mode api).

The following changes were also introduced:

- `Widget::render` has been deleted. Developers should use `Frame::render_widget`
instead.
- `Widget::background` has been deleted. Developers should use `Buffer::set_background`
instead.
- `SelectableList` has been deleted. Developers can directly use `List` where
`SelectableList` features have been back-ported.
2020-02-23 19:23:37 +01:00
David Flemström
b7664a4108 Support several modifiers and indexed colors at once 2019-03-10 15:56:56 +01:00
Sven-Hendrik Haase
144bfb71cf Upgrade to 2018 edition 2019-01-13 14:35:51 +00:00
Karoline Pauls
228816f5f8 Frame: provide consistent size for rendering 2018-12-07 21:32:00 +01:00
Karoline Pauls
8522e028f1 Run cargo fmt with the new Rust stable toolchain (1.31.0) 2018-12-07 19:54:13 +01:00
Karoline Pauls
cc95c8cfb0 Gauge: use f64 internally and allow to set any f64 between 0 and 1 2018-12-05 21:20:12 +01:00
Karoline Pauls
8cdfc883b9 Feature: Autoresize
It basically never makes sense to render without syncing the size.

Without resizing, if shrinking, we get artefacts. If growing, we may get
panics (before this change the Rustbox sample (the only one which didn't
handle resizing on its own) panicked because the widget would get an
updated size, while the terminal would not).
2018-12-04 08:39:32 +01:00
Florian Dehau
7b4d35d224 feat: restore the cursor state on terminal drop 2018-09-24 08:03:52 +02:00
Florian Dehau
08ab92da80 refactor: clean examples
* Introduce a common event handler in order to focus on the drawing part
* Remove deprecated custom termion backends
2018-09-23 20:59:51 +02:00
Florian Dehau
13e194cd26 refactor: update widgets
* all widgets use the consumable builder pattern
* `draw` on terminal expect a closure that take a frame as only arg
2018-09-04 22:23:44 +02:00
Florian Dehau
d6016788ef refactor: clippy + rustfmt 2018-09-04 22:23:44 +02:00
Florian Dehau
7181970a32 feat: split layout from rendering
* remove layout logic from Terminal
* replace Group with Layout
* add Frame intermediate object
2018-09-04 22:23:44 +02:00
Florian Dehau
df7493fd33 style: Run rustfmt 2018-06-09 11:26:59 +02:00
Florian Dehau
36146d970a [style] rustfmt 2018-05-25 07:57:00 +02:00
Florian Dehau
36a5eb2110 Format code 2018-05-06 15:54:47 +02:00
Florian Dehau
c3c5109c5a [src] Fix build and tests 2017-12-26 21:45:46 +01:00
Florian Dehau
151d7e8a1c [src] Update dependencies
* Update all dependencies to their latest versions
* Change border to Borders to match v1.0 of bitflags
2017-12-26 21:45:46 +01:00
Florian Dehau
f24517bc5a [examples] Run cargo fmt 2017-10-30 23:14:57 +01:00
Florian Dehau
71545a0aa8 Run cargo fmt 2017-09-11 08:15:39 +02:00
Florian Dehau
bb61028e0c Fix examples 2017-09-07 08:32:08 +02:00
Florian Dehau
b2bb24b9d2 Fix rustfmt and clippy errors 2017-05-21 12:49:12 +02:00
Sebastian Woetzel
7652cc440d
fixes panic when terminal was resized 2017-05-08 21:34:41 +02:00
Florian Dehau
feefa5d54f Convert backends to conditionnal features for compilation 2016-11-28 09:52:51 +01:00
Florian Dehau
42fb0803af Add examples and demo 2016-11-08 00:35:46 +01:00