termio 0.5.1 copy "termio: ^0.5.1" to clipboard
termio: ^0.5.1 copied to clipboard

A minimal library for building interactive terminal applications with VT100 escape codes support.

termio #

A minimal library for building interactive terminal applications in Dart.

No dependencies. Just pure Dart.

Installation #

dart pub add termio

Usage #

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(.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.inputEvents.listen((event) {
    switch (event) {
      case KeyInputEvent(key: 'q'):
        terminal.write(Ansi.cursorVisible(true));
        terminal.write(Ansi.reset());
        terminal.write(Ansi.clearScreen());
        terminal.rawMode = false;
        exit(0);
      case KeyInputEvent(key: 'up'):
        terminal.write('\nUp arrow pressed!');
      default:
        break;
    }
  });

  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
  • InputParser - Parse raw terminal input into structured KeyInputEvent and MouseInputEvent
  • Keys - Constants for keyboard input (arrows, function keys, ctrl combinations)
  • MouseEvent - Parse mouse clicks, drags, and scroll wheel events
  • 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:

  • example - Simple demo with title and key input
  • ansi_demo - Comprehensive demo of all ANSI features (colors, styles, cursor, etc.)
  • mouse_demo - Mouse tracking: click to position cursor, scroll wheel
  • sweep - Minesweeper game
  • snake - Classic snake game
  • life - Conway's Game of Life
1
likes
150
points
244
downloads

Publisher

unverified uploader

Weekly Downloads

A minimal library for building interactive terminal applications with VT100 escape codes support.

Repository (GitHub)
View/report issues

Topics

#terminal #console #cli #vt100 #ansi

Documentation

API reference

License

MIT (license)

More

Packages that depend on termio