d_zero_terminal 0.1.7
d_zero_terminal: ^0.1.7 copied to clipboard
Ultra-lightweight zero-allocation FFI PTY terminal emulator with C++17 VT100/TrueColor parser and single-pass Impeller drawRawAtlas rendering.
⚡️ d_zero_terminal #
Ultra-lightweight, zero-allocation FFI PTY terminal emulator for Flutter & Impeller with C++17 VT100/ANSI/TrueColor parsing, POSIX forkpty execution, and single-pass Canvas.drawRawAtlas rendering.
🚀 Key Architecture #
- 128-Byte (2 Cache Lines) C++17 FFI Shared Memory (
ZeroTerminalState):- Cache Line 0 (
0..63): Grid geometry (cols,rows), cursor position & style (block,beam,underline), scrollback offset, POSIXforkptychild PID, and Seqlock counter (seq). - Cache Line 1 (
64..127): Live telemetry (bytesProcessed,escapeSeqsParsed,throughputMbPerSec,parseLatencyNs, 128-bitdirtyRowMask). - Protected by
ZERO_TERM_MAGIC_ALIVE(0x5A54524D) canary validation and registry checks for 100% Double-Free and Use-After-Free immunity.
- Cache Line 0 (
- Zero-Copy SoA Viewport Buffers (
Uint32List/Uint8List):- Fixed-address Structure-of-Arrays (
viewportCodepoints,viewportFgArgb,viewportBgArgb,viewportAttrs) mapped directly into Dart viaPointer.asTypedListwith 0 FFI calls per cell and 0 heap allocations.
- Fixed-address Structure-of-Arrays (
- Zero-Channel POSIX
forkpty+ C++17 VT100/TrueColor Parser:- Dedicated C++ PTY reader thread parses 16-color, 256-color, and 24-bit TrueColor (
\x1b[38;2;r;g;bm) sequences, UTF-8 codepoints, cursor motions, and Alternate Screen (?1049h/l) off the UI thread. - Dart UI thread coalesces updates at VSync (120Hz/240Hz) and flushes the visible grid in a single
Canvas.drawRawAtlasdraw call.
- Dedicated C++ PTY reader thread parses 16-color, 256-color, and 24-bit TrueColor (
📦 Exported Z Widgets & Controllers #
| Widget / Class | Alias / Legacy | Description |
|---|---|---|
ZPtyTerminal |
ZTerminalEmulator (ZeroPtyTerminal) |
Zero-rebuild, single-pass drawRawAtlas terminal viewport with hardware keyboard input, mouse selection, and scrollback wheel support. |
ZTerminalHud |
ZTerminalTelemetryBar (ZeroTerminalHud) |
Zero-allocation telemetry HUD painting live C++ parser throughput (MB/s), latency (ns/byte), bytes parsed, and grid/cursor state via ZeroNumberPainter. |
ZTerminalMinimap |
ZScrollbackRadar (ZeroTerminalMinimap) |
Zero-allocation 256-bin scrollback density & color radar strip with interactive drag-to-scrub lens. |
ZeroPtyController |
- | 128-byte FFI shared-memory & POSIX forkpty controller (spawnShell, feedAnsiBytes, writeInputText, sendKey, resize, runStressBurst). |
💻 Usage Example #
import 'package:flutter/material.dart';
import 'package:d_zero_terminal/d_zero_terminal.dart';
class TerminalScreen extends StatefulWidget {
const TerminalScreen({super.key});
@override
State<TerminalScreen> createState() => _TerminalScreenState();
}
class _TerminalScreenState extends State<TerminalScreen> {
late final ZeroPtyController _controller;
@override
void initState() {
super.initState();
_controller = ZeroPtyController(cols: 96, rows: 28, scrollbackCapacity: 2048);
// Spawn a real POSIX shell (/bin/zsh) or feed ANSI sequences directly:
_controller.spawnShell();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: ZPtyTerminal(
controller: _controller,
autoResize: true,
),
),
ZTerminalMinimap(controller: _controller),
],
);
}
}