Dart Terminal
A fun and minimalist experiment in crafting terminal UIs with Dart.
Key Concepts
Note
This project is a work-in-progress and everything is subject to change.
This project aims to provide an intuitive and ergonomic API for building, emulating, and interacting with terminal applications in Dart. It's designed to be a low-level building block for more complex terminal applications, such as text editors, games, and interactive command-line interfaces.
Buffer
A Buffer
is a two-dimensional grid of characters with an associated style. It
is the primary building block for rendering text-based content to the terminal,
and it can be used to build more complex UI components. For example, a Buffer
can be used to render text, boxes, and sprites:
import 'package:dt/rendering.dart';
void main() {
final buffer = Buffer(10, 3, '#');
buffer.print(0, 1, 'Hello, World!');
// ##########
// Hello, Wor
// ##########
buffer.rows.forEach((row) => print(row.map((cell) => cell.symbol).join()));
}
Surface
A Surface
is a high-level abstraction for writing Buffer
s to the terminal:
import 'package:dt/terminal.dart';
void main() {
final surface = Surface.fromStdout();
surface.draw((frame) {
frame.draw((buffer) {
buffer.print(0, 1, 'Hello, World!');
});
});
}
Contributing
CI/CD
This package is:
- Formatted with
dart format
. - Checked with
dart analyze
. - Tested with
dart test
, including with code coverage (seetool/coverage.dart
).
Inspiration
This package is inspired by a number of libraries, including but not limited to:
- crossterm: A Rust library for cross-platform terminal manipulation.
- dart_console: A Dart library for terminal manipulation.
- fortress: A Dart library for building retro-style games.
- hex_toolkit: A Dart library for hexagonal grids.
- mini_sprite: A Dart library for sprite-based rendering.
- pathxp and pathfinding: Dart libraries for pathfinding algorithms.
- ratatui: A Rust library for building terminal UIs.
- taffy: UI layout library for Rust.
- termenv: A Go library for terminal feature detection and styling.
- termion: A Rust library for low-level bindless terminal manipulation.
- termwiz: Another Rust library for building a terminal emulator.
- vaxis: A Rust library for building terminal UIs.
Libraries
- backend
- Provides backend implementations for interacting with terminal APIs.
- foundation
- Building blocks and framework primitives for the rest of the library.
- layout
- Layout definitions, computations, and utilities.
- rendering
- Provides utilities for rendering text to a terminal-like UI.
- terminal
- Provides the main interface of this package, Surface, and related types.
- widgets
- A collection of built-in types that implement Widget.