Commit graph

47 commits

Author SHA1 Message Date
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
Samy Rahmani
2f4413be6e
feat: stylization shorthands (#283) 2023-07-01 09:14:16 +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
Josh McKinney
40b3543c3f
style(comments): set comment length to wrap at 100 chars (#218)
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.
2023-06-04 12:34:05 +02:00
Yuri Astrakhan
e08b466166
chore: inline format args (#190) 2023-05-21 20:46:02 -07:00
Josh McKinney
728f82c084
refactor(text): replace Spans with Line (#178)
* 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
2023-05-18 20:21:43 +02:00
lesleyrs
4842885aa6
fix(examples): update input in examples to only use press events (#129) 2023-04-13 22:21:35 +02:00
Orhun Parmaksız
ed12ab16e0
chore(cargo): update project metadata (#94) 2023-03-17 17:03:49 +01:00
Florian Dehau
c8c03294e1 chore: self contained examples 2021-11-11 16:18:49 +01:00
Florian Dehau
9806217a6a feat!: use crossterm as default backend 2021-11-01 23:21:55 +01:00
Moritz
e05b80cec1
doc: fix typos in comments. (#486) 2021-06-16 17:14:16 +02:00
Arne Beer
77c6e106e4
doc(examples): Add comments to "list" example and fix list direction (#425)
* Add docs to list example and fix list direction

* List example: review adjustments and typo fixes
2020-12-06 16:33:31 +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
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
Antoine Büsch
f795173886 Unify Item and Text 2018-09-08 08:41:57 +02:00
Florian Dehau
6c69160d6b feat: remove unecessary borrows of Style 2018-09-07 22:24:52 +02:00
Florian Dehau
bcd1e30376 refactor: update List select behavior
* allow a selectable list to have no selected item
* show highlight_symbol only when something is selected
2018-09-04 22:23:44 +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
5de571fb03 feat(widgets): Add start_corner option to List 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
f620af1455 [examples][list] Change style of first list 2018-04-01 12:36:11 +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
af16518650 [src] Run rustfmt 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
d6a91d1865 Fix List lifetime issues
Add a new lifetime for the items inside the list
2017-09-10 21:38:17 +02:00
Florian Dehau
b8fd4a8685 Fix List example 2017-09-10 21:38:17 +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