8 releases

0.3.1 May 22, 2023
0.3.0 May 22, 2023
0.2.0 May 19, 2023
0.1.1 May 19, 2023
0.1.0-dev-r2 Apr 14, 2023

#1077 in GUI

Download history 2/week @ 2024-09-20 3/week @ 2024-09-27 1/week @ 2024-10-04

88 downloads per month

MIT license

95KB
2.5K SLoC

sanguine

Create dynamic, performant TUI applications in Rust.

Sanguine was created from the need for a library tailored for complex TUI applications such as text editors and terminal multiplexers. The Rust ecosystem contains many great crates for building TUI apps, but many are geared towards small dashboard-like apps and implement immediate-mode rendering or struggle with mouse events.

Sanguine implements a tree-based layout API that can be updated at runtime, with a custom constraint algorithm geared towards rendering to the terminal. Layout results are cached between renders for performance, and are only recomputed when the layout is changed. Widgets can be nested and mouse events are handled properly for widgets at any depth - widgets only need to handle mouse events based on local position. Widgets can optionally specify a cursor location to allow for implementations of text editor windows and more.

It is built on top of Termwiz' BufferedTerminal, which optimizes terminal writes to maximize performance.

Features:

  • Dynamic, Tree-based layout API
  • Extensible widget trait
  • First-class mouse events support
    • Automatic propagation
    • Hover and click support
  • Global and widget-local event handlers
  • Generic API
    • Custom user event type for message passing
    • Custom state type for core app state
  • Focus
    • Switch focus by direction or directly

Demo

demo

Demo Usage

$ git clone git@github.com:willothy/sanguine.git

$ cd sanguine

$ cargo run --example demo

Keymaps:

  • Control + q: Quit
  • Shift + Tab: Cycle focus
  • Shift + Up/Down/Left/Right: Switch focus by direction
  • Up/Down/Left/Right: Switch menu item
  • Enter: Select menu item

Dependencies

~16–30MB
~466K SLoC