import { decodeInputrcKeySequence } from "./key-sequence.js"; import { InputrcKeyTrie, type TrieResolution } from "./key-trie.js"; import type { ReadlineKeymap, ReadlineKeymapName } from "./keymap.js"; import type { ResolvedReadlineProfile } from "./profile-loader.js"; import type { ReadlineVariables } from "./variables.js"; function buildTrie(keymap: ReadlineKeymap): InputrcKeyTrie { return InputrcKeyTrie.fromEntries( keymap .entries() .map(([sequence, binding]) => [ decodeInputrcKeySequence(sequence), binding, ]), ); } /** Immutable decoded dispatcher for one resolved inputrc profile. */ export class ReadlineProfileResolver { readonly variables: ReadlineVariables; readonly #tries: Readonly>; constructor(profile: ResolvedReadlineProfile) { this.variables = new Map(profile.variables); this.#tries = { "vi-command": buildTrie(profile.viCommand), "vi-insert": buildTrie(profile.viInsert), }; } resolve(keymap: ReadlineKeymapName, input: string): TrieResolution { return this.#tries[keymap].resolve(input); } }