feat: add config-backed ask keymaps

This commit is contained in:
Erik Kotsiuba
2026-04-28 22:35:43 +02:00
parent 5c0d8964fb
commit e8a36b72ef
31 changed files with 2192 additions and 422 deletions
+46
View File
@@ -0,0 +1,46 @@
import { DEFAULT_ASK_KEYMAPS } from "../constants/keymaps.ts";
import type { AskConfig, AskConfigFileV1 } from "./schema.ts";
export const DEFAULT_ASK_CONFIG: AskConfig = {
behaviour: {
autoSubmitWhenAnsweredWithoutNotes: false,
},
keymaps: {
...DEFAULT_ASK_KEYMAPS,
},
};
export function normalizeAskConfig(
config?: Partial<AskConfigFileV1> | AskConfig
): AskConfig {
return {
behaviour: {
autoSubmitWhenAnsweredWithoutNotes:
config?.behaviour?.autoSubmitWhenAnsweredWithoutNotes ??
DEFAULT_ASK_CONFIG.behaviour.autoSubmitWhenAnsweredWithoutNotes,
},
keymaps: {
...DEFAULT_ASK_CONFIG.keymaps,
...(config?.keymaps ?? {}),
},
};
}
export function toAskConfigFileV1(config: AskConfig): AskConfigFileV1 {
const normalized = normalizeAskConfig(config);
return {
schemaVersion: 1,
behaviour: {
autoSubmitWhenAnsweredWithoutNotes:
normalized.behaviour.autoSubmitWhenAnsweredWithoutNotes,
},
keymaps: {
cancel: normalized.keymaps.cancel,
dismiss: normalized.keymaps.dismiss,
toggle: normalized.keymaps.toggle,
confirm: normalized.keymaps.confirm,
optionNote: normalized.keymaps.optionNote,
questionNote: normalized.keymaps.questionNote,
},
};
}