33 lines
854 B
TypeScript
33 lines
854 B
TypeScript
import { AnsiTerminalDisplay } from "./ansi.ts";
|
|
import { UIConfig } from "./config.ts";
|
|
import { Display } from "./display.ts";
|
|
import { TextUI } from "./ui.ts";
|
|
import { PreTerminalDisplay } from "./web.ts";
|
|
export { TextUI } from "./ui.ts";
|
|
|
|
export const UI_DISPLAY_TYPES = {
|
|
autodetect: undefined,
|
|
ansi: AnsiTerminalDisplay,
|
|
web_pre: PreTerminalDisplay,
|
|
dummy: Display,
|
|
} as const;
|
|
|
|
export async function createTextUI(
|
|
config: Partial<UIConfig>,
|
|
display_type: keyof typeof UI_DISPLAY_TYPES = "autodetect",
|
|
): Promise<TextUI> {
|
|
if (display_type == "autodetect") {
|
|
if (typeof (window as any).document != "undefined") {
|
|
display_type = "web_pre";
|
|
} else {
|
|
display_type = "ansi";
|
|
}
|
|
}
|
|
|
|
var display = new UI_DISPLAY_TYPES[display_type]();
|
|
|
|
var ui = new TextUI(display, config);
|
|
await ui.init();
|
|
|
|
return ui;
|
|
}
|