vtparse 1.0.1 copy "vtparse: ^1.0.1" to clipboard
vtparse: ^1.0.1 copied to clipboard

A pure dart library for generating virtual terminal events from a stream of bytes

A library for generating a stream of virtual terminal events from a byte stream.

Usage #

A simple usage example reading bytes from stdin:

import 'dart:async';
import 'dart:io';

import 'package:vtparse/vtparse.dart';

final q = 'q'.codeUnitAt(0);

void main() async {
  // Don't echo the things typed
  stdin.echoMode = false;
  // Accept char by char instead of line by line
  stdin.lineMode = false;

  // This could use stdin.expand(...) instead, but since you can't close stdin,
  // manually listening to it and passing events to a StreamController allows
  // us to close the StreamController when we're done with it.
  final _stdioByteController = StreamController<int>();
  final _stdioSubscription = stdin.listen((event) {
    for (final byte in event) {
      _stdioByteController.sink.add(byte);
    }
  });

  final parser = VTParse(_stdioByteController.stream);
  parser.events.listen((event) {
    print(event);
    // For example, this closes the stream if 'q' is typed. We wouldn't be able
    // to close the stream if we used stdin.expand above. Using our own stream
    // gives us the ability to close things properly if we're done taking user
    // input.
    if (event.action == VTAction.print && event.ch == q) {
      _stdioSubscription.cancel();
      _stdioByteController.close();
    }
  });
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1
likes
140
pub points
0%
popularity

Publisher

unverified uploader

A pure dart library for generating virtual terminal events from a stream of bytes

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

statemachine

More

Packages that depend on vtparse