Commit Graph

31 Commits (master)

Author SHA1 Message Date
Florian Dehau 6069d89dee chore: fix all clippy warnings 2 years ago
Florian Dehau 9806217a6a feat!: use crossterm as default backend 3 years ago
Florian Dehau 23d5fbde56 refactor(examples): remove exit key from Events handler
The thread spawned by `Events` to listen for keyboard inputs had knowlegde of
the exit key to exit on its own when it was pressed. It is however a source of
confusion (#491) because the exit behavior is wired in both the event handler
and the input handling performed by the app. In addition, this is not needed as
the thread will exit anyway when the main thread finishes as it is already the
case for the "tick" thread. Therefore, this commit removes both the option to
configure the exit key in the `Events` handler and the option to temporarily
ignore it.
3 years ago
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.
4 years ago
Florian Dehau 88c4b191fb feat(text): add new text primitives 4 years ago
Alexander Batischev 8c2ee0ed85
feat(terminal): Add after-draw() cursor control to Frame (#91) (#309) 4 years ago
Florian Dehau 5a590bca74 chore: enable clippy on all targets and all features
- Remove deny warnings in lib.rs. This allows easier iteration when developing
new features. The warnings will make the CI fails anyway on the clippy CI
stage.
- Run clippy on all targets (including tests and examples) and all features.
- Fail CI on clippy warnings.
4 years ago
Florian Dehau 3f62ce9c19 chore: remove unecessary dependencies
* Remove log, stderrlog, structopt
* Add argh
4 years ago
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.
4 years ago
Florian Dehau e6ce0ab9a7 refactor(examples): add input modes to user input examples 4 years ago
Sebastian Thiel 2dfe9c1663 [example: user_input] Assure the cursor responds immediatel when hitting backspace
This was discovered with the termion backend in alacritty on OSX.
5 years ago
Sven-Hendrik Haase 144bfb71cf Upgrade to 2018 edition 5 years ago
Karoline Pauls 228816f5f8 Frame: provide consistent size for rendering 6 years ago
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).
6 years ago
Florian Dehau 37aa06f508 style(examples): rustfmt 6 years ago
Florian Dehau 32947669d5 feat(examples): show how to move the cursor 6 years ago
Florian Dehau 7b4d35d224 feat: restore the cursor state on terminal drop 6 years ago
Florian Dehau 08ab92da80 refactor: clean examples
* Introduce a common event handler in order to focus on the drawing part
* Remove deprecated custom termion backends
6 years ago
Antoine Büsch f795173886 Unify Item and Text 6 years ago
Antoine Büsch 0544c023f5 Rename Text::{Data -> Raw, StyledData -> Styled} 6 years ago
Antoine Büsch ff47f9480b Introduce builder methods for Text to make it more ergonomic 6 years ago
Antoine Büsch 70561b7c54 Fix examples and doctests 6 years ago
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
6 years ago
Florian Dehau d6016788ef refactor: clippy + rustfmt 6 years ago
Florian Dehau ad602a54bf refactor(widgets): replace text rendering in Paragraph
* remove custom markup language
* add Text container for both raw and styled strings
6 years ago
Florian Dehau 7181970a32 feat: split layout from rendering
* remove layout logic from Terminal
* replace Group with Layout
* add Frame intermediate object
6 years ago
Florian Dehau df7493fd33 style: Run rustfmt 6 years ago
Florian Dehau 36146d970a [style] rustfmt 6 years ago
Florian Dehau 36a5eb2110 Format code 6 years ago
Florian Dehau d53ecaeade [examples] Clean user input example 6 years ago
Florian Dehau 299279dc2d [examples] Add user input example 6 years ago