
* feat(canvas): implement half block marker A useful technique for the terminal is to use half blocks to draw a grid of "pixels" on the screen. Because we can set two colors per cell, and because terminal cells are about twice as tall as they are wide, we can draw a grid of half blocks that looks like a grid of square pixels. This commit adds a new `HalfBlock` marker that can be used in the Canvas widget and the associated HalfBlockGrid. Also updated demo2 to use the new marker as it looks much nicer. Adds docs for many of the methods and structs on canvas. Changes the grid resolution method to return the pixel count rather than the index of the last pixel. This is an internal detail with no user impact.
Examples
These gifs were created using Charm VHS.
VHS has a problem rendering some background color transitions, which shows up in several examples below. See https://github.com/charmbracelet/vhs/issues/344 for more info. These problems don't occur in a terminal.
Demo
This is the previous demo example from the main README. It is available for each of the backends. Source: demo.rs.
cargo run --example=demo --features=crossterm
cargo run --example=demo --no-default-features --features=termion
cargo run --example=demo --no-default-features --features=termwiz
Hello World
This is a pretty boring example, but it contains some good documentation on writing tui apps. Source: hello_world.rs.
cargo run --example=hello_world --features=crossterm
Barchart
Demonstrates the BarChart
widget. Source: barchart.rs.
cargo run --example=barchart --features=crossterm
Block
Demonstrates the Block
widget. Source: block.rs.
cargo run --example=block --features=crossterm
Calendar
Demonstrates the Calendar
widget. Source: calendar.rs.
cargo run --example=calendar --features=crossterm widget-calendar
Canvas
Demonstrates the Canvas
widget
and related shapes in the
canvas
module. Source:
canvas.rs.
cargo run --example=canvas --features=crossterm
Chart
Demonstrates the Chart
widget.
Source: chart.rs.
cargo run --example=chart --features=crossterm
Colors
Demonstrates the available Color
options. These can be used in any style field. Source: colors.rs.
cargo run --example=colors --features=crossterm
Colors (RGB)
Demonstrates the available RGB
Color
options. These can be used
in any style field. Source: colors_rgb.rs.
cargo run --example=colors_rgb --features=crossterm
Custom Widget
Demonstrates how to implement the
Widget
trait. Source:
custom_widget.rs.
cargo run --example=custom_widget --features=crossterm
Gauge
Demonstrates the Gauge
widget.
Source: gauge.rs.
[!NOTE] The backgrounds render poorly when we generate this example using VHS. This problem doesn't generally happen during normal rendering in a terminal. See vhs#344 for more details.
cargo run --example=gauge --features=crossterm
Inline
Demonstrates the
Inline
Viewport mode for ratatui apps. Source: inline.rs.
cargo run --example=inline --features=crossterm
Layout
Demonstrates the Layout
and
interaction between each constraint. Source: layout.rs.
cargo run --example=layout --features=crossterm
List
Demonstrates the List
widget.
Source: list.rs.
cargo run --example=list --features=crossterm
Modifiers
Demonstrates the style
Modifiers
. Source:
modifiers.rs.
cargo run --example=modifiers --features=crossterm
Panic
Demonstrates how to handle panics by ensuring that panic messages are written correctly to the screen. Source: panic.rs.
cargo run --example=panic --features=crossterm
Paragraph
Demonstrates the Paragraph
widget. Source: paragraph.rs
cargo run --example=paragraph --features=crossterm
Popup
Demonstrates how to render a widget over the top of previously rendered widgets using the
Clear
widget. Source:
popup.rs.
cargo run --example=popup --features=crossterm
[!NOTE] The background renders poorly after the popup when we generate this example using VHS. This problem doesn't generally happen during normal rendering in a terminal. See vhs#344 for more details.
Scrollbar
Demonstrates the Scrollbar
widget. Source: scrollbar.rs.
cargo run --example=scrollbar --features=crossterm
Sparkline
Demonstrates the Sparkline
widget. Source: sparkline.rs.
[!NOTE] The background renders poorly in the second sparkline when we generate this example using VHS. This problem doesn't generally happen during normal rendering in a terminal. See vhs#344 for more details.
cargo run --example=sparkline --features=crossterm
Table
Demonstrates the Table
widget.
Source: table.rs.
cargo run --example=table --features=crossterm
Tabs
Demonstrates the Tabs
widget.
Source: tabs.rs.
cargo run --example=tabs --features=crossterm
User Input
Demonstrates one approach to accepting user input. Source user_input.rs.
[!NOTE] Consider using
tui-textarea
ortui-input
crates for more functional text entry UIs.
cargo run --example=user_input --features=crossterm