termui_flutter library

A Flutter GUI embedder and renderer for termui applications.

This library provides the integration between termui and Flutter, allowing TUI applications to be rendered inside a Flutter application.

It translates terminal draw commands and cell updates into Flutter text textures, rendering the final output using custom painters. It also routes keyboard and mouse interactions from the Flutter UI back to the terminal.

Example Usage

The following example demonstrates how to host a TUI application inside a standard MaterialApp.

import 'package:flutter/material.dart' hide Color;
import 'package:termui/termui.dart' as termui;
import 'package:termui_flutter/termui_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: SizedBox(
            width: 640,
            height: 480,
            child: Terminal(
              onRun: (terminal, drawFrame) async {
                final termSize = await terminal.size;
                final buffer = termui.Buffer.blank(termSize.x, termSize.y);

                void render() {
                  buffer.clear();
                  buffer.write(
                    0,
                    0,
                    'Hello from Flutter TUI!',
                    style: const termui.Style(foreground: termui.Colors.white),
                  );
                  drawFrame(buffer);
                }

                render();

                await for (final event in terminal.events) {
                  if (event is termui.KeyEvent && event.key == 'q') {
                    break;
                  }
                  render();
                }
              },
            ),
          ),
        ),
      ),
    );
  }
}

Classes

FlutterTerminal
A custom terminal implementation managed by the Flutter frontend.
GlyphAtlas
A cached texture atlas containing rasterized glyphs for terminal rendering.
GlyphAtlasGenerator
A generator that asynchronously produces a new GlyphAtlas.
Terminal
A widget that embeds a termui TUI application within Flutter.

Functions

saveFile(String basename, List<int> bytes) → Future<String?>
Saves the given bytes to a file with the specified basename.
waitForFontsToLoad() → Future<void>
Waits for web fonts to load (no-op on this platform).