Skip to content

danielhatoshi/ic-mini-terminal

 
 

Repository files navigation

IC Mini Terminal (ic-mt)

Minimal keyboard input (⌨) and graphical output (📺) for programs on the Internet Computer.

Example

The Motoko package icmt (in this repo, under src) provides a simple framework for building services that interact with an icmt instance.

Below, we show an interactive Counter example.

class Counter(initCount : Nat) {
  public var count = initCount;

  public func clone () : Counter {
    Counter(count)
  };

  public func draw (d: Dim) : Types.Graphics.Elm {
    let r = Render.Render();
    let atts = Style.txtAtts(d.width / 256 + 1);
    let cr = Render.CharRender(r, Mono5x5.bitmapOfChar, atts);
    let tr = Render.TextRender(cr);
    tr.textAtts("count = " # Nat.toText(count), atts);
    r.getElm()
  };

  public func update (e : EventInfo) {
    switch (e.event) {
      case (#keyDown(keys)) {
        for (k in keys.vals()) {
          switch (k.key) {
            case ("=" or "+" or "ArrowUp" or "ArrowRight") {
              count += 1;
            };
            case ("-" or "_" or "ArrowDown" or "ArrowLeft") {
              if (count > 0) { count -= 1 };
            };
            case _ { /* ignore key */ };
          }
        }
      };
      case _ { /* ignore event */ };
    }
  };
};

The full example uses this class to instantiate the terminal/Terminal.Basic class, which adapts the simple (single-event) draw-update protocol shown below to that of the "full" icmt service protocol.

Technical spec

The ic-mt tool talks to any service on the Internet Computer that uses the mini-terminal update-view service protocol, given below in Candid syntax (eliding message-type details):

service : {
  view: (Dim, vec EventInfo) -> (Graphics) query;
  update: (vec EventInfo, GraphicsRequest) -> (vec Graphics);
}

See the full Candid spec, and general docs for Candid for further details.

Building and testing

Dependencies:

The mini terminal is a Rust project.

We typically use dfx to run the Internet Computer services (e.g., within a local replica) to run applications for the terminal.

We often write these applications in Motoko.

Inspired by

About

Internet Computer Mini Terminal

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 61.3%
  • Modelica 36.5%
  • Dhall 1.3%
  • Shell 0.9%