termilary 0.2.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

A ncurses-like terminal emulator running on a web canvas.

0.2.2 #

  • Fix error with canvasTerminal's getter bounds.

0.2.1 #

  • Add getter bounds for canvasTerminal and ui.
  • Add getter pixelToPosition for ui.

0.2.0 #

  • Add support for handling mouse and touch inputs

0.1.2 #

  • Decouple Terminal into Terminal and CanvasTerminal. Terminal is abstract and provide basic logic and operations.
  • Add class SubTerminal: a Terminal inside a Terminal.

0.1.1 #

  • Fix broken repository/homepage link.

0.1.0 #

  • First version.

example/main.dart

import "package:termilary/termilary.dart";
import "package:utilary/utilary.dart" show rng, Vector;

const rows = 25;
const cols = 40;

final Font font = Font("Consolas", size: 14, w: 16, h: 16, x: 1, y: 13);

//Create a new 40 x 25 characters terminal using a Consolas font.
//Optional argument [canvas] isn't provided (will create a new canvas)
final CanvasTerminal terminal = CanvasTerminal(cols, rows, font);

String inputMapper(PointInput i) => i.toString();

final UserInterface<String> ui = UserInterface(inputMapper, terminal);

void main() {
  ui.keyPress.bind("up", KeyInput(KeyCodes.up));
  ui.keyPress.bind("right", KeyInput(KeyCodes.right));
  ui.keyPress.bind("down", KeyInput(KeyCodes.down));
  ui.keyPress.bind("left", KeyInput(KeyCodes.left));

  ui.push(ExampleScreen("HELLO, move me with the arrow keys"));

  //Start the UI
  ui.handlingInput = true;
  ui.running = true;
}

class ExampleScreen extends Screen<String> {
  int _x;
  int _y;

  int _ticks;

  Set<Vector> _points = Set();

  Color _textColor;
  final String _text;

  ExampleScreen(this._text, [this._textColor]) {
    _x = _y = 0;
    _ticks = 10;
    _textColor ??= Color.white;
  }

  @override
  bool handleInput(String input) {
    int xDir = 0, yDir = 0;

    switch (input) {
      case "up":
        yDir = -1;
        break;

      case "right":
        xDir = 1;
        break;

      case "down":
        yDir = 1;
        break;

      case "left":
        xDir = -1;
        break;
    }

    List<String> fields = input.split(",");
    if (fields.length > 2) {
      fields = fields.take(2).toList();
      fields = fields.map((String str) => str.split(":")[1]).toList();

      int x = int.parse(fields[0]);
      int y = int.parse(fields[1]);

      _points.add(Vector(x, y));
    }

    _move(xDir, yDir);
    dirty();

    return true;
  }

  void _move(int x, int y) {
    _x += x;
    _y += y;
  }

  @override
  void update() {
    _ticks--;

    if (_ticks <= 0) {
      _ticks = 10;
      _textColor = Color(rng.range(256), rng.range(256), rng.range(256));
      dirty();
    }
  }

  @override
  void render(Terminal t) {
    t.drawString(_x, _y, _text, _textColor);

    _points.forEach((Vector v) => t.setGlyph(v.x, v.y, Glyph('#', Color.white)));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  termilary: ^0.2.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:termilary/termilary.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
90
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jan 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/src/user_interface.dart. (-4.89 points)

Analysis of lib/src/user_interface.dart reported 10 hints, including:

line 34 col 7: DO use curly braces for all flow control structures.

line 40 col 9: DO use curly braces for all flow control structures.

line 42 col 9: DO use curly braces for all flow control structures.

line 49 col 9: DO use curly braces for all flow control structures.

line 51 col 9: DO use curly braces for all flow control structures.

Fix lib/src/terminal.dart. (-1.49 points)

Analysis of lib/src/terminal.dart reported 3 hints:

line 42 col 7: DO use curly braces for all flow control structures.

line 42 col 40: DO use curly braces for all flow control structures.

line 50 col 7: DO use curly braces for all flow control structures.

Fix lib/src/canvas_terminal.dart. (-1 points)

Analysis of lib/src/canvas_terminal.dart reported 2 hints:

line 52 col 7: DO use curly braces for all flow control structures.

line 54 col 7: DO use curly braces for all flow control structures.

Fix additional 4 files with analysis or formatting issues. (-2.50 points)

Additional issues in the following files:

  • lib/src/glyph.dart (2 hints)
  • lib/src/input.dart (1 hint)
  • lib/src/key_input.dart (1 hint)
  • lib/src/sub_terminal.dart (1 hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >= 2.0.0 < 3.0.0
utilary ^1.0.0 1.0.9