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.
Features
TerminalView: shows a running program and gives it the keys, the mouse, pasted text, the focus and its size.- Real programs: shells,
less,nanoandhtoprun in it, with colors, the alternate screen, bracketed paste and the kitty keyboard protocol. - Pseudo-terminals:
Ptystarts a program in one, throughdart:ffialone. It runs on Linux and macOS. - Your own link: a
TerminalSessioncan run over any byte stream, such as a scripted program or a remote shell. - An emulator of its own:
TerminalEmulatorturns 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
- Examples:
two shells side by side in a
SplitView. - Widget catalog:
TerminalViewwith a picture and its code. - The view:
TerminalSessionandTerminalView, in full. - The pseudo-terminal:
Pty, signals and the environment. - What it emulates: the sequences, modes and keys the emulator speaks.
- The host interface: the emulator alone, for a host of its own.
- How it is tested: and how fast it is, for those who work on the package.
License
MIT, copyright 2026 Andrii Ivanov: LICENSE.
Libraries
- twk_term
- An embedded terminal: a permissive VT emulator whose screen the core's Canvas draws, the pseudo-terminal a program runs in, the widget that shows it, and the terminal on stdin in raw mode, for a program that passes the keys typed on.