mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
43 lines
820 B
TypeScript
43 lines
820 B
TypeScript
import type ConsoleApp from "./ConsoleApp.ts";
|
|
|
|
type View = {
|
|
offset: number;
|
|
};
|
|
|
|
export default class ConsoleAppDemo
|
|
implements ConsoleApp<ConsoleAppDemo, View> {
|
|
value = 0;
|
|
|
|
createView(): View {
|
|
return { offset: 0 };
|
|
}
|
|
|
|
render = function (this: { db: ConsoleAppDemo; view: View }) {
|
|
return `${" ".repeat(this.view.offset)}${this.db.value}`;
|
|
};
|
|
|
|
onKeyDown = function (this: { db: ConsoleAppDemo; view: View }, key: string) {
|
|
switch (key) {
|
|
case "ArrowLeft": {
|
|
this.view.offset = Math.max(0, this.view.offset - 1);
|
|
break;
|
|
}
|
|
|
|
case "ArrowRight": {
|
|
this.view.offset++;
|
|
break;
|
|
}
|
|
|
|
case "ArrowUp": {
|
|
this.db.value++;
|
|
break;
|
|
}
|
|
|
|
case "ArrowDown": {
|
|
this.db.value--;
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
}
|