https://github.com/erf/termio
A minimal lib for console apps in Dart.
https://github.com/erf/termio
cli console dart terminal vt100
Last synced: 4 months ago
JSON representation
A minimal lib for console apps in Dart.
- Host: GitHub
- URL: https://github.com/erf/termio
- Owner: erf
- License: mit
- Created: 2020-04-05T17:38:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-12-22T20:24:58.000Z (6 months ago)
- Last Synced: 2025-12-24T09:50:01.891Z (6 months ago)
- Topics: cli, console, dart, terminal, vt100
- Language: Dart
- Homepage:
- Size: 104 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# termio
A minimal library for building interactive terminal applications in Dart.
No dependencies. Just pure Dart.
## Installation
```sh
dart pub add termio
```
## Usage
```dart
import 'dart:io';
import 'package:termio/termio.dart';
void main() {
final terminal = Terminal();
terminal.rawMode = true;
terminal.write(Ansi.cursorVisible(false));
terminal.write(Ansi.clearScreen());
// Colors: enum, 256-palette index, or RGB
terminal.write(Ansi.fg(Color.cyan));
terminal.write(Ansi.fgIndex(208));
terminal.write(Ansi.fgRgb(255, 128, 0));
terminal.write(Ansi.bold());
terminal.write('Hello, Terminal! Press q to quit.');
terminal.write(Ansi.reset());
terminal.input.listen((codes) {
final str = String.fromCharCodes(codes);
if (str == 'q') {
terminal.write(Ansi.cursorVisible(true));
terminal.write(Ansi.reset());
terminal.write(Ansi.clearScreen());
terminal.rawMode = false;
exit(0);
} else if (str == Keys.arrowUp) {
terminal.write('\nUp arrow pressed!');
}
});
terminal.resize.listen((_) {
terminal.write('Resized: ${terminal.width}x${terminal.height}');
});
}
```
## Features
- **Ansi** - Escape codes for cursor, colors, text styles, and terminal modes
- **Terminal** - Raw mode, terminal size, input stream, resize events
- **Keys** - Constants for keyboard input (arrows, function keys, ctrl combinations)
- **Color** - 16 standard colors, 256-color palette, and 24-bit RGB
- **ThemeDetector** - Detect terminal background color for automatic light/dark theme selection
## Examples
See the `example/` folder for complete examples:
- **sweep** - Minesweeper game
- **snake** - Classic snake game
- **life** - Conway's Game of Life
- **simple** - Minimal centered text example
- **colors** - 256-color palette display