Commit Graph

164 Commits (master)

Author SHA1 Message Date
♫ Christian Krause ♫ a6b25a4877
chore: add panic hook example (#593)
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.
2 years ago
Florian Dehau 6069d89dee chore: fix all clippy warnings 2 years ago
Petr Portnov ef583cead9 chore(examples): remove unused `demo/util.rs`
This module is unused and is not imported by any other module.
2 years ago
Florian Dehau 8032191366 chore: fix table example
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.
2 years ago
Florian Dehau c8c03294e1 chore: self contained examples 3 years ago
Florian Dehau 9806217a6a feat!: use crossterm as default backend 3 years ago
Florian Dehau ca68bae4ed feat!(widgets/canvas): use spans for text of labels 3 years ago
Florian Dehau 8da5f740af refactor(examples): show more use case in gauge example 3 years ago
Moritz e05b80cec1
doc: fix typos in comments. (#486) 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
Oleks (オレクス) a346704cdc
feat(block): add option to center and right align the title (#462)
* Added ability to set title alignment, added tests, modified blocks example to show the feature

* Added test for inner with title in block

* Updated block example to show center alignment

* Formatting fixed

* Updated tests to use lamdas and be more concise. Updated title alignmnet code to be more straightforward and have correct behavior when placing title in the center without left border
3 years ago
Simas Toleikis 8832281dcf Update crossterm to 0.19. 3 years ago
Florian Dehau 67e996c5f4 feat(examples): add third tab to demo to show colors 3 years ago
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
3 years ago
Florian Dehau 117098d2d2 refactor(examples): add missing margin at the bottom of the header of table in the demo 3 years ago
Florian Dehau 5ea54792c0 refactor(widgets/table): more flexible table
- control over the style of each cell and its content using the styling capabilities of Text.
- rows with multiple lines.
- fix panics on small areas.
- less generic type parameters.
3 years ago
Florian Dehau 79e27b1778 refactor(widgets/gauge): stop using unicode blocks by default 3 years ago
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
3 years ago
Florian Dehau 5050f1ce1c feat(widgets/gauge): add `LineGauge` variant of `Gauge` 4 years ago
Florian Dehau 11df94d601
fix(examples): avoid panic when computing event poll timeout in crossterm demo (#380) 4 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 72ba4ff2d4 refactor(examples): remove unecessary `terminal.hide_cursor` calls 4 years ago
Florian Dehau 88c4b191fb feat(text): add new text primitives 4 years ago
Brooks Rady 112d2a65f6
feat(widgets/paragraph): add option to preserve indentation when the text is wrapped (#327) 4 years ago
Xiaopeng Li d999c1b434
feat(widgets/paragraph): Add horizontal scroll (#329)
* `Paragraph:scroll` takes a tuple of offsets instead of a single vertical offset.
* `LineTruncator` takes this new horizontal offset into account to let the paragraph scroll horizontally.
4 years ago
Alexander Batischev 8c2ee0ed85
feat(terminal): Add after-draw() cursor control to Frame (#91) (#309) 4 years ago
Cokemonkey11 2b48409cfd
fix(examples): remove typo in demo text 4 years ago
Florian Dehau b59e4bb808 feat(examples): enable mouse capture to make crossterm demo on par with termion 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 4f728d363f fix(widgets/list): stop highlighting blank placeholders 4 years ago
Florian Dehau e81af75427 fix(examples): improve input handling in crossterm demo
* avoid stacking events
* ensure tick events are sent at the given tick rate (and not everytime a key is pressed).
4 years ago
Florian Dehau c98002eb76 feat: add an option to run the examples without all unicode symbols 4 years ago
Florian Dehau 584e1b0500 refactor(widgets/canvas): allow canvas to render with a simple dot character instead of braille patterns
This change allows developers to gracefully degrade the output if the targeted
terminal does not support the full range of unicode symbols.
4 years ago
Stephan Dilly 7676d3c7df add clear widget and popup example utilizing it 4 years ago
Florian Dehau 3f62ce9c19 chore: remove unecessary dependencies
* Remove log, stderrlog, structopt
* Add argh
4 years ago
Florian Dehau ae677099d6 feat(widgets/table): allow one row to be selected 4 years ago
Florian Dehau 140db9b2e2 refactor(canvas): update shape drawing strategy
* Update the `Shape` trait. Instead of returning an iterator of point, all
shapes are now aware of the surface they will be drawn to through a `Painter`.
In order to draw themselves, they paint points of the "braille grid".
* Rewrite how lines are drawn using a common line drawing algorithm (Bresenham).
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 67dd1ac608 fix: remove array_into_iter warnings 4 years ago
Florian Dehau d50327548b style: run rustfmt 4 years ago
Florian Dehau e6ce0ab9a7 refactor(examples): add input modes to user input examples 4 years ago
Florian Dehau 9085c81e76 refactor: clean up border type for blocks
* Merge line symbols in a single module.
* Replace set_border_type with border_type to match other builder methods.
* Remove unecessary branching.
4 years ago
Matthew Stevenson 682349c03e update block example; add BorderType to exposed widgets API 4 years ago
Matthew Stevenson f1bc00b67f add rounded corners and double borders to block example 4 years ago
Timon 60b99cfc66 feat: bump crossterm to 0.14 4 years ago
Timon e4873e4da9 feat(backend): bump crossterm to 0.13
* removed flush calls because execute already calls flush under the hood.
* moved some static functions into From traits
* removed useless clone in demo
* upgrade to crossterm 0.13
* map all errors
5 years ago
Jeffas 94877f4e7e Use constraints for table column widths
This allows table column widths to be adapted more and scale with the
UI.

The constraints are solved using the Cassowary solver. An added
constraint for fitting them all in the width is added.
5 years ago
Florian Dehau 3747ddbefb feat(backend): Refactor crossterm backend
* Remove compilation warnings
* Fix rendering artifacts in the crossterm demo. In particular, the bold modifier
was leaking on most of the terminal screen because the old logic was not
properly unsetting the bold modifier after use (took inspiration of the termion
backend implementation)
5 years ago
Timon_Post a0f6605f59 Implemented command api crossterm, for better perfomance. 5 years ago
Joe Ardent 85f74dd802 Fix typo in table example. 5 years ago