This repository has been archived on 2026-10-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
maestro/web/src/keys.test.ts
T
Miguel Palhas 3ce1a6f331
ci / web (push) Successful in 1m22s
ci / rust (push) Successful in 7m24s
ci / flake (push) Successful in 8m50s
feat(maestro): add paging and symbol keys to the mobile key bar
PgUp/PgDn and the `- / | ~` symbols the soft keyboard buries behind a page
switch join the bar, in an 8-column grid that keeps the cursor inverted-T.
Columns hold a thumb's width, so a narrow phone scrolls the bar sideways
instead of shrinking the caps.

Closes #7
2026-09-02 16:01:08 +01:00

59 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { applyModsToChar, cursorSeq, tildeSeq, toCtrl } from "./keys.js";
describe("toCtrl", () => {
it("maps letters to their control code, case-insensitively", () => {
expect(toCtrl("a")).toBe("\x01");
expect(toCtrl("A")).toBe("\x01");
expect(toCtrl("c")).toBe("\x03");
expect(toCtrl("[")).toBe("\x1b");
});
it("handles the two specials outside the @-_ range", () => {
expect(toCtrl(" ")).toBe("\x00");
expect(toCtrl("?")).toBe("\x7f");
});
it("passes through anything it has no mapping for", () => {
expect(toCtrl("1")).toBe("1");
expect(toCtrl("é")).toBe("é");
expect(toCtrl("abc")).toBe("abc");
expect(toCtrl("")).toBe("");
});
});
describe("applyModsToChar", () => {
it("composes ctrl and alt, with ESC outermost", () => {
expect(applyModsToChar("a", false, false)).toBe("a");
expect(applyModsToChar("a", true, false)).toBe("\x01");
expect(applyModsToChar("a", false, true)).toBe("\x1ba");
expect(applyModsToChar("a", true, true)).toBe("\x1b\x01");
});
});
describe("cursorSeq", () => {
it("uses the bare CSI form when unmodified", () => {
expect(cursorSeq("A", false, false)).toBe("\x1b[A");
});
it("uses the xterm modifier encoding n = 1 + alt(2) + ctrl(4)", () => {
expect(cursorSeq("A", false, true)).toBe("\x1b[1;3A");
expect(cursorSeq("A", true, false)).toBe("\x1b[1;5A");
expect(cursorSeq("A", true, true)).toBe("\x1b[1;7A");
});
});
describe("tildeSeq", () => {
it("uses the bare CSI form when unmodified", () => {
expect(tildeSeq(5, false, false)).toBe("\x1b[5~");
expect(tildeSeq(6, false, false)).toBe("\x1b[6~");
});
it("keeps the parameter in place when modified, unlike the cursor keys", () => {
expect(tildeSeq(5, true, false)).toBe("\x1b[5;5~");
expect(tildeSeq(6, false, true)).toBe("\x1b[6;3~");
expect(tildeSeq(6, true, true)).toBe("\x1b[6;7~");
});
});