11 releases

Uses old Rust 2015

0.3.0 Jun 3, 2021
0.2.5 Nov 14, 2020
0.2.4 Jul 15, 2020
0.2.3 Jan 2, 2020
0.1.1 Mar 23, 2019

#1062 in Command-line interface

Download history 16/week @ 2024-07-22 23/week @ 2024-07-29 17/week @ 2024-08-05 24/week @ 2024-08-12 8/week @ 2024-08-19 38/week @ 2024-08-26 21/week @ 2024-09-02 16/week @ 2024-09-09 25/week @ 2024-09-16 83/week @ 2024-09-23 41/week @ 2024-09-30 9/week @ 2024-10-07 11/week @ 2024-10-14 17/week @ 2024-10-21 16/week @ 2024-10-28 13/week @ 2024-11-04

58 downloads per month
Used in 5 crates

MIT license

285KB
6K SLoC

unsegen

unsegen is a library facilitating the creation of text user interface (TUI) applications akin to ncurses. Currently, unsegen only provides a Rust interface.

Overview

The library consists of four modules:

  • base: Basic terminal rendering including Terminal setup, "slicing" using Windows, and formatted writing to Windows using Cursors.
  • widget: Widget abstraction and some basic Widgets useful for creating basic building blocks of text user interfaces.
  • input: Raw terminal input events, common abstractions for application (component) Behavior and means to easily distribute events.
  • container: Higher level window manager like functionality using Containers as the combination of widget and input concepts.

The following libraries are built on top of unsegen and provide higher level functionality:

  • unsegen_jsonviewer provides an interactive widget that can be used to display json values.
  • unsegen_pager provides a memory or file backed line buffer viewer with syntax highlighting and line decorations.
  • unsegen_signals uses unsegen's input module to raise signals on the usual key combinations (e.g., SIGINT on CTRL-C).
  • unsegen_terminal provides a pseudoterminal that can be easily integrated into applications using unsegen.

Getting Started

unsegen is available on crates.io. You can install it by adding this line to your Cargo.toml:

unsegen = "0.3.0"

Screenshots

Here is a screenshot of ugdb, which is built on top of unsegen.

Examples

There are examples at the top of each main modules' documentation (i.e., base, input, widget, and container) which should be sufficient to get you going.

For a fully fledged application using unsegen, you can have a look at ugdb, which was developed alongside unsegen and the primary motivation for it.

Some notes on implementation details

For simplicity, layouting is done in every draw call. This, in conjunction with recursive calls to calculate space demand of widgets, leads to not-so-great asymptotic runtime. However, I found this not to be a problem in practice so far. If this is problematic for, please file an issue. There are workarounds (caching the draw-result of widgets) for which convenient wrappers can be implemented in the library, but have not so far.

Licensing

unsegen is released under the MIT license.

Dependencies

~7.5MB
~147K SLoC