Commit Graph

313 Commits (master)

Author SHA1 Message Date
Kemyt 62495c3bd1
fix(widgets/barchart): fix chart filled more than actual (#383)
* Fix barchart incorrectly showing chart filled more than actual

Determination of how filled the bar should be was incorrectly taking the
entire chart height into account, when in fact it should take height-1, because
of extra line with label. Because of that the chart appeared fuller than it
should and was full before reaching maximum value.

* Add a test case for checking if barchart fills correctly up to max value

Co-authored-by: Kemyt <kemyt4@gmail.com>
4 years ago
Brooks Rady d00184a7c3
feat(text): extend `Text` to be stylable and extendable (#361)
* Extend `Text` to be extendable
* Add some documentation
4 years ago
Brooks Rady ce32d5537d
chore: clippy fixes (#386) 4 years ago
Florian Dehau 57862eeda6 Release v0.11.0 4 years ago
Brooks Rady 0abaa20de9
refactor: clean up some folds (#362) 4 years ago
Amjad Alsharafi c35a1dd79f
feat(widgets/canvas): added type Block in canvas markers (#350)
This allows for clearer colors than using Dot, especially when
decreasing the size of the terminal font in order to increase the
resolution of the canvas
4 years ago
alvinhochun e0b2572eba
refactor(backend/crossterm): support more style modifiers on Windows and fix build with Crossterm 0.17.8 (#368)
* Support more style modifiers on Windows
* Change Crossterm backend to write directly to buffer instead of String

Crossterm might actually do WinAPI calls instead of writing ANSI excape
codes so writing to an intermediate String may cause issues on older
versions of Windows. It also fails to compile with Crossterm 0.17.8 due
to Crossterm now expecting the writer to support `flush`, which String
doesn't.

Fixes #373
4 years ago
Florian Dehau 90f3858eff feat(backend): keep the internal buffers in sync when the terminal is cleared. 4 years ago
Florian Dehau ecb482f297 fix(backend): move the cursor when first diff is on second cell
Both termion and crossterm backends were not moving the cursor if the first diff to draw was on the
second cell. The condition triggering the cursor move has been updated to fix this. In addition, two
tests have been added to avoid future regressions.
4 years ago
Florian Dehau 641f391137 feat(terminal): add unstable api to use a fixed viewport
There was now way to avoid the autoresize behavior of `Terminal`. While it was fine for most users,
it made the testing experience painful as it was impossible to avoid the calls to `Backend::size()`.
Indeed they trigger the following error: "Inappropriate ioctl for device" since we are not running
the tests in a real terminal (at least in the CI).

This commit introduces a new api to create a `Terminal` with a fixed viewport.
4 years ago
Florian Dehau 6504930888 Release v0.10.0 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 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
Mikko Rantanen 3aa8b9a259 Implement `patch` between two `StyleDiff` 4 years ago
Florian Dehau fdbea9e2ee fix(widgets/canvas): avoid panic on zero-width bounds 4 years ago
Alexander Batischev 8c2ee0ed85
feat(terminal): Add after-draw() cursor control to Frame (#91) (#309) 4 years ago
Florian Dehau 7251186762 feat(style): add StyleDiff 4 years ago
Florian Dehau 82fda4ac0e doc(style): improve documentation of Style 4 years ago
Kenta Iwasaki 1d12ddbdfc layout: add vertical split constraint test on height 4 years ago
Kenta Iwasaki f474c76e19 layout: force constraint that width and height are non-negative 4 years ago
Florian Dehau ac99104114 feat(style): add support to serialize and deserialize Style using serde
* Add serde as an optional dependency.
* Add feature-gated derives to Color, Modifier and Style.
4 years ago
Paul Horn 0bb9b388f7 Borrow layout for splitting instead of moving it
This allows for layouts to be saved and reused and does not require an additional clone
4 years ago
Florian Dehau 96c6b4efcb refactor(tests): move test utilities to TestBackend
* Remove custom Debug implementation of Buffer
* Add `TestBackend::assert_buffer` to compare buffers in integration tests. When
the assertion fails, the output now show the list of differences in addition
of the views of the computed and expected buffers. This effectively replaces
the table of debug code for colors and modifiers as it is easier to read.
4 years ago
Stephan Dilly 7110fe0159 fix panic on narrow buffers (fixes #293) 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 a7761fe55d fix(buffer): ignore zero-width graphemes 4 years ago
Clement Tsang b72ced4511
fix(widgets/chart): remove overflow when dataset if empty (#274)
* docs: Fix missing code block fence
* use slice::windows to deal with underflow issue
* add test for empty dataset and lines
4 years ago
Darrien Glasser 359b7feb8c
fix(widgets/canvas): Add bounds check when drawing line high/low (#283)
* Add bounds check when drawing line high/low
* Add test to ensure codepath doesn't break
4 years ago
Florian Dehau 5d99b4af00 docs: improve widgets documentation 4 years ago
Björn Steinbrink 8f9aa276e8 fix(widgets/list): fix line length calculation for selectable lists
The code that outputs the list elements uses the full inner width of its
block, without taking the width of the highlight symbol into
consideration. This allows the elements to overflow the box and draw
over the block's border. To fix that, we need to reduce the target width
for the list elements.
4 years ago
Florian Dehau bc2a512101 feat: add missing `Clone` and `Copy` on types 4 years ago
Florian Dehau 4f728d363f fix(widgets/list): stop highlighting blank placeholders 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
Florian Dehau cee65ed283 feat: allow BarChart and Sparkline to use a more portable set of symbols
Add `BarChart::bar_set` and `Sparkline::bar_set` methods to customize
the set of symbols used to display the data. The new set should give
a better looking output on terminal that do not support a wide range
of unicode symbols.
4 years ago
Stephan Dilly 7676d3c7df add clear widget and popup example utilizing it 4 years ago
Stephan Dilly fd48719040 fix some typos 4 years ago
Loïc Girault d987225ac8 Add thick lines and line::Set struct
Add a new style of line and use a struct to avoid duplication of
matching
4 years ago
Florian Dehau 3f62ce9c19 chore: remove unecessary dependencies
* Remove log, stderrlog, structopt
* Add argh
4 years ago
Florian Dehau 278c153d31 style: remove clippy warnings 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
Vadim Chekan 1683e8d609
Clean redundant generics params in Table (#234)
* Clean redundant generics params in Table

It is possible to use associated types the same way as generics parameters. In fact associated types are nothing more than better organized generics params. For example, there is no need to introduce another param to constraint iterator item to be Display, you can just say `where I::Iterator, I::Item: Display`. This allows to drop type params for Table from 5 to 2.
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
Malte Tammena 808a5c9ffd Mark Style::* functions `const` 4 years ago
Florian Dehau d16db5ed90 style: fix clippy warnings 4 years ago
Florian Dehau 28017f97ea feat(widgets/chart): add more control on the visibility of the legend 4 years ago
Florian Dehau ea43413507 fix: remove clippy warnings 4 years ago
Caleb Bassi 829b7b6b70 Change linechart to draw the points also 4 years ago
Caleb Bassi 262bf441ce Add linechart support
Closes #73

This commit only adds support for linecharts for the braille marker.
4 years ago
Caleb Bassi 7aae9b380e Add header_gap field to Table 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 a72389b28c revert to single Block struct; add set_border_type method and BorderType enum 4 years ago
Matthew Stevenson 06d159fb7b add RoundedBlock and DoubleBlock structs that impl From Block; add Block::rounded() and Block::double_border() 4 years ago
Matthew Stevenson 578560766d add round corners and double lines to symbols 4 years ago
Florian Dehau 8293cef703 Release v0.8.0 4 years ago
Timon 60b99cfc66 feat: bump crossterm to 0.14 4 years ago
Kyle Ruzic b8d0f947e8 Added a verticle 'cross' to the symbols as it was missing for no real reason 4 years ago
Sebastian Woetzel bbd4363fa9 Bugfix: title_style was not used to style the axis title 4 years ago
Florian Dehau e0083fb8de chore: make the onboarding easier for Windows users. 4 years ago
Florian Dehau 3abafc307c Release v0.7.0 5 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
Florian Dehau 2233cdc9cc chore: add CI based on github actions 5 years ago
Florian Dehau 816bc9b5c8 style: fix formatting and clippy issues 5 years ago
Florian Dehau a82c82fcd7 fix(widgets): remove compilation warning in table widget 5 years ago
TheZoq2 bb28d02277 Update docs to point encourage installing 0.6 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
Florian Dehau 42731da546 Enable build failure on compilation warnings 5 years ago
Joseph Knight e183d63a5e typo in barcharg.rs 5 years ago
Joseph Knight e5fdd442c3 typo in sparkline.rs 5 years ago
Joseph Knight 97357c0e08 typo in curses.rs 5 years ago
Joseph Knight 8649ce4c78 fixed typo in symbols.rs 5 years ago
Timon_Post a0f6605f59 Implemented command api crossterm, for better perfomance. 5 years ago
Jeffas db9b1dd689 Make margins be vertical or horizontal
This adds support for margins to be either vertical or horizontal, or
both.
5 years ago
Joe Ardent 86f681a007 Silence check warnings about [lack of] use of 'dyn' for boxed trait objects. 5 years ago
Florian Dehau a3827aaeae Remove try call in termion backend 5 years ago
Jeremy Day 47c68e40a2 fix for canvas rendering edge cases causing overflow errors 5 years ago
Florian Dehau 2a7eec816a Add PartialEq to Text 5 years ago
Florian Dehau 8fbb764c9e Move Borders documentation 5 years ago
Florian Dehau 4756801fd9 Format 5 years ago
Russ f0e0b515ad avoid divide by zero 5 years ago
defiori 25a0825ae4 fix: curses backend cursor positions 5 years ago
scauligi b1ac297d71 fix crossterm terminal size and dark gray color 5 years ago
nytopop 8a9c76b003 Don't highlight Tabs separator behind selection 5 years ago
DarrienG 41cdd3e261 Provide clone and debug for Text type 5 years ago
Timon_Post f6a0a91a23 fmt 5 years ago
timonpost@hotmail.nl ffaaf5e39c review update 5 years ago
timonpost@hotmail.nl 567cf7b8e5 update 0.9.2 5 years ago
Florian Dehau a74d335cb4 Fix clippy warnings 5 years ago
Florian Dehau 7a5ad3fbdb Fix sparkline panic when max is zero 5 years ago
Florian Dehau 4436110c44 Improve onboarding in documentation 5 years ago
Florian Dehau f8b3526426 Add code example for `Constraint::Ratio` 5 years ago
Florian Dehau 43e38ac483 Fix Buffer::merge
Coordinates returned by Buffer::pos_of were interpreted as local coordinates
while they were global. This was resulting in panics due to out of bounds
accesses. Interpreting the coordinates as global and using correct offsets
when computing the new index within the buffer for each cell fix the issue.
5 years ago
David Flemström 21e79ca078 Rebase and include necessary curses changes 5 years ago
David Flemström a25bbea555 Add workarounds for weird termion escape code handling 5 years ago
David Flemström b7664a4108 Support several modifiers and indexed colors at once 5 years ago
David Flemström d360cd3434 Support exact ratios for layout constraints 5 years ago