libghostty 0.0.3 copy "libghostty: ^0.0.3" to clipboard
libghostty: ^0.0.3 copied to clipboard

Dart FFI bindings to libghostty-vt, the VT emulator library from Ghostty.

libghostty #

pub package GitHub Actions

Dart FFI bindings to libghostty-vt, the VT emulator library from Ghostty.

Android iOS macOS Linux Windows Web

Caution

This package is under active development. The underlying native library (patch) has not yet landed upstream in Ghostty. Expect breaking changes between releases. Linux and Windows are CI-tested but unverified in a Flutter application.

Getting started #

dependencies:
  libghostty: ^0.0.3
import 'package:libghostty/libghostty.dart';

Future<void> main() async {
  // Required on web only. You can safely call this on other platforms.
  // await initializeForWeb(Uri.parse('assets/libghostty.wasm'));

  final terminal = Terminal(cols: 80, rows: 24);
  terminal.write(Uint8List.fromList('Hello, terminal!\r\n'.codeUnits));

  final cell = terminal.screen.cellAt(0, 0);
  print(cell.content); // H

  terminal.dispose();
}

Usage #

Terminal emulation #

final terminal = Terminal(cols: 80, rows: 24);

terminal.write(Uint8List.fromList('\x1b[1;34mHello\x1b[0m\r\n'.codeUnits));

for (var row = 0; row < terminal.screen.rows; row++) {
  final text = terminal.screen.lineAt(row).text;
  if (text.isNotEmpty) print(text);
}

terminal.dispose();

Key encoding #

final encoder = KeyEncoder();
final event = KeyEvent()
  ..action = KeyAction.press
  ..key = Key.keyC
  ..mods = Mods.ctrl;

print(encoder.encode(event).codeUnits); // [3] (ETX)

event.dispose();
encoder.dispose();

SGR parsing #

final parser = SgrParser();
final attrs = parser.parse([1, 31]);

for (final attr in attrs) {
  switch (attr) {
    case SgrBold():
      print('Bold');
    case SgrForeground8(:final index):
      print('Color: $index');
    default:
      break;
  }
}

parser.dispose();

OSC parsing #

final parser = OscParser();
parser.feedBytes(utf8.encode('0;Window Tile'));
final command = parser.end(0x07);

print(command.type);        // OscCommandType.changeWindowTitle
print(command.windowTitle); // My Title

parser.dispose();

Paste validation #

pasteIsSafe('hello');           // true
pasteIsSafe('rm -rf /\n');      // false
pasteIsSafe('\x1b[201~inject'); // false

Clean up #

All native backed objects require dispose() when no longer needed. Using disposed object throws DisposedException. Double dispose is a no-op.

1
likes
0
points
160
downloads

Publisher

unverified uploader

Weekly Downloads

Dart FFI bindings to libghostty-vt, the VT emulator library from Ghostty.

Repository (GitHub)
View/report issues

Topics

#terminal #emulator #ffi #ghostty #libghostty

License

unknown (license)

Dependencies

code_assets, crypto, ffi, hooks, meta, web

More

Packages that depend on libghostty