Skip to main content

twk_term 0.3.0 copy "twk_term: ^0.3.0" to clipboard
twk_term: ^0.3.0 copied to clipboard

An embedded terminal for twk: a permissive VT emulator drawn by the core's Canvas, a pseudo-terminal through dart:ffi, and TerminalView, a widget that runs a program in one.

twk_term #

A terminal inside a twk app. Run a shell, an editor or any program in a widget, next to the rest of your interface.

The TerminalView page of the twk gallery, dark theme

Features #

  • TerminalView: shows a running program and gives it the keys, the mouse, pasted text, the focus and its size.
  • Real programs: shells, less, nano and htop run in it, with colors, the alternate screen, bracketed paste and the kitty keyboard protocol.
  • Pseudo-terminals: Pty starts a program in one, through dart:ffi alone. It runs on Linux and macOS.
  • Your own link: a TerminalSession can run over any byte stream, such as a scripted program or a remote shell.
  • An emulator of its own: TerminalEmulator turns a program's output into cells and its keys into bytes, for a host that is not a twk app.

Getting started #

dart pub add twk twk_term

A shell in the whole terminal. The app quits when the shell ends, so type exit to leave:

import 'package:twk/twk.dart';
import 'package:twk_term/twk_term.dart';

Future<void> main() => runApp(const Shell());

final class Shell extends StatefulWidget {
  const Shell({super.key});

  @override
  State<Shell> createState() => _ShellState();
}

final class _ShellState extends State<Shell> {
  // started at the view's size, at its first layout
  final _session = TerminalSession.start('bash', const []);

  @override
  void initState() {
    super.initState();
    _session.addListener(() {
      if (_session.ended) {
        AppBinding.of(context).quit();
      }
    });
  }

  @override
  void dispose() {
    _session.dispose(); // hangs up: SIGHUP for bash
    super.dispose();
  }

  @override
  Widget build(BuildContext context) =>
      TerminalView(session: _session, autofocus: true);
}

Learn more #

License #

MIT, copyright 2026 Andrii Ivanov: LICENSE.

1
likes
160
points
1.15k
downloads

Documentation

API reference

Publisher

verified publisherpro100.dev

Weekly Downloads

An embedded terminal for twk: a permissive VT emulator drawn by the core's Canvas, a pseudo-terminal through dart:ffi, and TerminalView, a widget that runs a program in one.

Repository (GitHub)
View/report issues
Contributing

Topics

#terminal #tui #emulator #pty #widget

License

MIT (license)

Dependencies

meta, twk, twk_core

More

Packages that depend on twk_term