termui_pty 0.3.7 copy "termui_pty: ^0.3.7" to clipboard
termui_pty: ^0.3.7 copied to clipboard

A custom ANSI terminal emulator and PTY view for termui.

example/termui_pty.dart

import 'dart:io';
import 'package:termui/terminal/terminal.dart' as term;
import 'package:termui/termui.dart';
import 'package:pty2/pty2.dart';
import 'package:termui_pty/termui_pty.dart';

void main() async {
  // Start a bash shell that launches top, with a valid TERM environment
  final pty = PseudoTerminal.start(
    'bash',
    ['-c', 'top'],
    environment: {'TERM': 'xterm-256color'},
  );

  await term.Terminal.runGuarded((terminal) async {
    terminal.enterAlternateScreen();
    terminal.hideCursor();

    try {
      final runner = PromptRunner(
        terminal: terminal,
        alternateScreen: true,
        widget: SizedBox.expand(child: PseudoTerminalView(pty: pty)),
      );

      // Run until the user types 'q' in top, which exits top and closes the pty?
      // Wait, top exits when you type 'q'. If the pty process exits, we should exit.
      // But PromptRunner runs until `abort` is called or focus is lost.
      // Let's just run it.
      await runner.run();
    } finally {
      terminal.showCursor();
      terminal.exitAlternateScreen();
    }
  });

  print('Exited cleanly.');
  exit(0);
}
0
likes
0
points
307
downloads

Publisher

verified publishermcdole.org

Weekly Downloads

A custom ANSI terminal emulator and PTY view for termui.

Repository (GitHub)
View/report issues

Topics

#cli #tui #terminal #console #pty

License

unknown (license)

Dependencies

characters, pty2, termui

More

Packages that depend on termui_pty