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
59 lines
1.9 KiB
TypeScript
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~");
|
|
});
|
|
});
|