Skip to content

Commit 4c93b44

Browse files
committed
refactor: extract experimental settings schema
1 parent f186246 commit 4c93b44

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { UI_COPY } from "../ui/copy.js";
2+
import type { getUiRuntimeOptions } from "../ui/runtime.js";
3+
import type { SelectOptions } from "../ui/select.js";
4+
5+
export type ExperimentalSettingsAction =
6+
| { type: "sync" }
7+
| { type: "backup" }
8+
| { type: "toggle-refresh-guardian" }
9+
| { type: "decrease-refresh-interval" }
10+
| { type: "increase-refresh-interval" }
11+
| { type: "apply" }
12+
| { type: "save" }
13+
| { type: "back" };
14+
15+
export function getExperimentalSelectOptions(
16+
ui: ReturnType<typeof getUiRuntimeOptions>,
17+
help: string,
18+
onInput?: SelectOptions<ExperimentalSettingsAction>["onInput"],
19+
): SelectOptions<ExperimentalSettingsAction> {
20+
return {
21+
message: UI_COPY.settings.experimentalTitle,
22+
subtitle: UI_COPY.settings.experimentalSubtitle,
23+
help,
24+
clearScreen: true,
25+
theme: ui.theme,
26+
selectedEmphasis: "minimal",
27+
onInput,
28+
};
29+
}
30+
31+
export function mapExperimentalMenuHotkey(
32+
raw: string,
33+
): ExperimentalSettingsAction | undefined {
34+
if (raw === "1") return { type: "sync" };
35+
if (raw === "2") return { type: "backup" };
36+
if (raw === "3") return { type: "toggle-refresh-guardian" };
37+
if (raw === "[" || raw === "-") return { type: "decrease-refresh-interval" };
38+
if (raw === "]" || raw === "+") return { type: "increase-refresh-interval" };
39+
const lower = raw.toLowerCase();
40+
if (lower === "q") return { type: "back" };
41+
if (lower === "s") return { type: "save" };
42+
return undefined;
43+
}
44+
45+
export function mapExperimentalStatusHotkey(
46+
raw: string,
47+
): ExperimentalSettingsAction | undefined {
48+
return raw.toLowerCase() === "q" ? { type: "back" } : undefined;
49+
}

0 commit comments

Comments
 (0)