termilary 0.1.2

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

##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;

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);

final UserInterface<String> ui = UserInterface(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;

  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;

      default:
        return false;
    }

    _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);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  termilary: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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]
0
Health:
Code health derived from static analysis. [more]
92
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: web

Primary library: package:termilary/termilary.dart with components: html.

Health suggestions

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

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

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

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

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

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

line 106 col 47: 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 50 col 7: DO use curly braces for all flow control structures.

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

Fix additional 3 files with analysis or formatting issues. (-2 points)

Additional issues in the following files:

  • lib/src/glyph.dart (2 hints)
  • 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.5