Add refresh loop
This commit is contained in:
parent
55238b5065
commit
c9292c0199
11
mod.ts
Normal file
11
mod.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { AnsiTerminalDisplay } from "./ansi.ts";
|
||||||
|
import { TextUI } from "./ui.ts";
|
||||||
|
export { TextUI } from "./ui.ts";
|
||||||
|
|
||||||
|
export async function createTextUI(): Promise<TextUI> {
|
||||||
|
// TODO detect platform
|
||||||
|
var display = new AnsiTerminalDisplay();
|
||||||
|
var ui = new TextUI(display);
|
||||||
|
await ui.init();
|
||||||
|
return ui;
|
||||||
|
}
|
19
ui.ts
19
ui.ts
|
@ -1,4 +1,4 @@
|
||||||
import { BufferDrawing, CharBuffer } from "./base.ts";
|
import { BufferDrawing, BufferSize, CharBuffer } from "./base.ts";
|
||||||
import { Display } from "./display.ts";
|
import { Display } from "./display.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,13 @@ export class TextUI {
|
||||||
await this.display.clear();
|
await this.display.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current display size
|
||||||
|
*/
|
||||||
|
getSize(): BufferSize {
|
||||||
|
return this.screen.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush the internal buffer to the display
|
* Flush the internal buffer to the display
|
||||||
*/
|
*/
|
||||||
|
@ -35,4 +42,14 @@ export class TextUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the event loop, waiting for input
|
||||||
|
*/
|
||||||
|
async loop(refresh = 1000): Promise<void> {
|
||||||
|
while (true) {
|
||||||
|
await this.flush();
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, refresh));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue