diff --git a/client/main.ts b/client/main.ts index 44c5720..999bcc1 100755 --- a/client/main.ts +++ b/client/main.ts @@ -80,15 +80,17 @@ class DisplayHandler { async spin() { while (true) { await wait(100); - const [width, height] = await this.get_res(); + const [width, height] = await DisplayHandler.get_res(); this.outputs.send({ kind: "request_display", content: { width, height } }); } } - async get_res() { - const width = parseInt(await run("tput", "cols")) / 2 - 2; // note : tiles are 2 char wide - const height = parseInt(await run("tput", "lines")) - 2; - return [width, height]; + static async get_res() { + const output = await run("stty", "size"); + const [raw_height, raw_width] = output.split(" "); + const width = Math.floor(parseInt(raw_width) / 2) - 2; // note : tiles are 2 char wide + const height = parseInt(raw_height) - 2; + return [width, height] as const; } refresh(raw: string) { @@ -123,3 +125,13 @@ class ServerInterface { } if (import.meta.main) await main(); + +Deno.test("res_check", async () => { + const ENABLED = false; // note : toggle before running test to know current resolution. + while (ENABLED) { + await wait(100); + const res = await DisplayHandler.get_res(); + console.clear(); + console.log("res", res); + } +});