export type ParsedViInput = | { kind: "pending"; count: number } | { kind: "command"; command: string; count: number }; /** Parses the Readline vi count prefix independently from command behavior. */ export class ViCommandParser { #countText = ""; push(input: string): ParsedViInput { if (input.length === 1 && /[1-9]/.test(input)) { this.#countText += input; return { kind: "pending", count: Number(this.#countText) }; } if (input === "0" && this.#countText.length > 0) { this.#countText += input; return { kind: "pending", count: Number(this.#countText) }; } const count = this.#countText.length === 0 ? 1 : Number(this.#countText); this.#countText = ""; return { kind: "command", command: input, count }; } reset(): void { this.#countText = ""; } }