termiraly 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 40

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

0.1.0 #

  • First version.

example/main.dart

import "package:termiraly/termiraly.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 Terminal terminal = Terminal(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:
  termiraly: ^0.1.0

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:termiraly/termiraly.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
93
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
40
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: web

Primary library: package:termiraly/termiraly.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.99 points)

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

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

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

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

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

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

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

line 15 col 22: Don't type annotate initializing formals.

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

Fix lib/src/key_input.dart. (-0.50 points)

Analysis of lib/src/key_input.dart reported 1 hint:

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

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/umr1352/termiraly was unreachable.

Issue tracker URL doesn't exist. (-10 points)

At the time of the analysis the issue_tracker field https://github.com/umr1352/termiraly was unreachable.

Repository URL doesn't exist. (-10 points)

At the time of the analysis the repository field https://github.com/umr1352/termiraly was unreachable.

Dependencies

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