Awesome
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:
- Rust and
cargo
dfx
via the DFINITY SDKvessel
package manager for Motoko examples.
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
- IC-Logo: A toy Logo-like language for the Internet Computer.
- Simple interactive graphics demos and games of Elm lang.
- Fantasy console PICO-8 (PICO-8 Manual).
- Languages of Play: Towards semantic foundations for game interfaces (Chris Martens and Matthew Hammer, March 2017).
- Lock-Step Simulation Is Child’s Play (Experience Report) (Joachim Breitner and Chris Smith)