@@ -28,7 +28,7 @@ import type { PluginConfig } from "../types.js";
2828import { ANSI } from "../ui/ansi.js" ;
2929import { UI_COPY } from "../ui/copy.js" ;
3030import { getUiRuntimeOptions , setUiRuntimeOptions } from "../ui/runtime.js" ;
31- import { type MenuItem , select } from "../ui/select.js" ;
31+ import { type MenuItem , select , type SelectOptions } from "../ui/select.js" ;
3232import { getUnifiedSettingsPath } from "../unified-settings.js" ;
3333import { sleep } from "../utils.js" ;
3434
@@ -281,6 +281,42 @@ type ExperimentalSettingsAction =
281281 | { type : "save" }
282282 | { type : "back" } ;
283283
284+ function getExperimentalSelectOptions (
285+ ui : ReturnType < typeof getUiRuntimeOptions > ,
286+ help : string ,
287+ onInput ?: SelectOptions < ExperimentalSettingsAction > [ "onInput" ] ,
288+ ) : SelectOptions < ExperimentalSettingsAction > {
289+ return {
290+ message : UI_COPY . settings . experimentalTitle ,
291+ subtitle : UI_COPY . settings . experimentalSubtitle ,
292+ help,
293+ clearScreen : true ,
294+ theme : ui . theme ,
295+ selectedEmphasis : "minimal" ,
296+ onInput,
297+ } ;
298+ }
299+
300+ function mapExperimentalMenuHotkey (
301+ raw : string ,
302+ ) : ExperimentalSettingsAction | undefined {
303+ const lower = raw . toLowerCase ( ) ;
304+ if ( lower === "q" ) return { type : "back" } ;
305+ if ( lower === "s" ) return { type : "save" } ;
306+ if ( raw === "1" ) return { type : "sync" } ;
307+ if ( raw === "2" ) return { type : "backup" } ;
308+ if ( raw === "3" ) return { type : "toggle-refresh-guardian" } ;
309+ if ( raw === "[" || raw === "-" ) return { type : "decrease-refresh-interval" } ;
310+ if ( raw === "]" || raw === "+" ) return { type : "increase-refresh-interval" } ;
311+ return undefined ;
312+ }
313+
314+ function mapExperimentalStatusHotkey (
315+ raw : string ,
316+ ) : ExperimentalSettingsAction | undefined {
317+ return raw . toLowerCase ( ) === "q" ? { type : "back" } : undefined ;
318+ }
319+
284320const BACKEND_TOGGLE_OPTIONS : BackendToggleSettingOption [ ] = [
285321 {
286322 key : "liveAccountSync" ,
@@ -2573,16 +2609,11 @@ async function promptExperimentalSettings(
25732609 color : "red" ,
25742610 } ,
25752611 ] ,
2576- {
2577- message : UI_COPY . settings . experimentalTitle ,
2578- subtitle : UI_COPY . settings . experimentalSubtitle ,
2579- help : UI_COPY . settings . experimentalHelpMenu ,
2580- clearScreen : true ,
2581- theme : ui . theme ,
2582- selectedEmphasis : "minimal" ,
2583- onInput : ( raw ) =>
2584- raw . toLowerCase ( ) === "q" ? { type : "back" } : undefined ,
2585- } ,
2612+ getExperimentalSelectOptions (
2613+ ui ,
2614+ UI_COPY . settings . experimentalHelpMenu ,
2615+ mapExperimentalMenuHotkey ,
2616+ ) ,
25862617 ) ;
25872618 if ( ! action || action . type === "back" ) return null ;
25882619 if ( action . type === "save" ) return draft ;
@@ -2647,14 +2678,11 @@ async function promptExperimentalSettings(
26472678 color : "red" ,
26482679 } ,
26492680 ] ,
2650- {
2651- message : UI_COPY . settings . experimentalTitle ,
2652- subtitle : UI_COPY . settings . experimentalSubtitle ,
2653- help : UI_COPY . settings . experimentalHelpStatus ,
2654- clearScreen : true ,
2655- theme : ui . theme ,
2656- selectedEmphasis : "minimal" ,
2657- } ,
2681+ getExperimentalSelectOptions (
2682+ ui ,
2683+ UI_COPY . settings . experimentalHelpStatus ,
2684+ mapExperimentalStatusHotkey ,
2685+ ) ,
26582686 ) ;
26592687 } catch ( error ) {
26602688 const message =
@@ -2674,14 +2702,11 @@ async function promptExperimentalSettings(
26742702 color : "red" ,
26752703 } ,
26762704 ] ,
2677- {
2678- message : UI_COPY . settings . experimentalTitle ,
2679- subtitle : UI_COPY . settings . experimentalSubtitle ,
2680- help : UI_COPY . settings . experimentalHelpStatus ,
2681- clearScreen : true ,
2682- theme : ui . theme ,
2683- selectedEmphasis : "minimal" ,
2684- } ,
2705+ getExperimentalSelectOptions (
2706+ ui ,
2707+ UI_COPY . settings . experimentalHelpStatus ,
2708+ mapExperimentalStatusHotkey ,
2709+ ) ,
26852710 ) ;
26862711 }
26872712 } finally {
@@ -2708,14 +2733,11 @@ async function promptExperimentalSettings(
27082733 color : "red" ,
27092734 } ,
27102735 ] ,
2711- {
2712- message : UI_COPY . settings . experimentalTitle ,
2713- subtitle : UI_COPY . settings . experimentalSubtitle ,
2714- help : UI_COPY . settings . experimentalHelpStatus ,
2715- clearScreen : true ,
2716- theme : ui . theme ,
2717- selectedEmphasis : "minimal" ,
2718- } ,
2736+ getExperimentalSelectOptions (
2737+ ui ,
2738+ UI_COPY . settings . experimentalHelpStatus ,
2739+ mapExperimentalStatusHotkey ,
2740+ ) ,
27192741 ) ;
27202742 continue ;
27212743 }
@@ -2747,14 +2769,11 @@ async function promptExperimentalSettings(
27472769 color : "red" ,
27482770 } ,
27492771 ] ,
2750- {
2751- message : UI_COPY . settings . experimentalTitle ,
2752- subtitle : UI_COPY . settings . experimentalSubtitle ,
2753- help : UI_COPY . settings . experimentalHelpStatus ,
2754- clearScreen : true ,
2755- theme : ui . theme ,
2756- selectedEmphasis : "minimal" ,
2757- } ,
2772+ getExperimentalSelectOptions (
2773+ ui ,
2774+ UI_COPY . settings . experimentalHelpStatus ,
2775+ mapExperimentalStatusHotkey ,
2776+ ) ,
27582777 ) ;
27592778 continue ;
27602779 }
@@ -2793,20 +2812,16 @@ async function promptExperimentalSettings(
27932812 color : "red" ,
27942813 } ,
27952814 ] ,
2796- {
2797- message : UI_COPY . settings . experimentalTitle ,
2798- subtitle : UI_COPY . settings . experimentalSubtitle ,
2799- help : UI_COPY . settings . experimentalHelpStatus ,
2800- clearScreen : true ,
2801- theme : ui . theme ,
2802- selectedEmphasis : "minimal" ,
2803- onInput : ( raw ) => {
2815+ getExperimentalSelectOptions (
2816+ ui ,
2817+ UI_COPY . settings . experimentalHelpPreview ,
2818+ ( raw ) => {
28042819 const lower = raw . toLowerCase ( ) ;
28052820 if ( lower === "q" ) return { type : "back" } ;
28062821 if ( lower === "a" ) return { type : "apply" } ;
28072822 return undefined ;
28082823 } ,
2809- } ,
2824+ ) ,
28102825 ) ;
28112826 if ( ! review || review . type === "back" ) continue ;
28122827
@@ -2837,14 +2852,11 @@ async function promptExperimentalSettings(
28372852 } ,
28382853 { label : UI_COPY . settings . back , value : { type : "back" } , color : "red" } ,
28392854 ] ,
2840- {
2841- message : UI_COPY . settings . experimentalTitle ,
2842- subtitle : UI_COPY . settings . experimentalSubtitle ,
2843- help : UI_COPY . settings . experimentalHelpStatus ,
2844- clearScreen : true ,
2845- theme : ui . theme ,
2846- selectedEmphasis : "minimal" ,
2847- } ,
2855+ getExperimentalSelectOptions (
2856+ ui ,
2857+ UI_COPY . settings . experimentalHelpStatus ,
2858+ mapExperimentalStatusHotkey ,
2859+ ) ,
28482860 ) ;
28492861 }
28502862}
0 commit comments