@@ -20,7 +20,7 @@ import { loadAccounts, normalizeAccountStorage } from "../storage.js";
2020import type { PluginConfig } from "../types.js" ;
2121import { UI_COPY } from "../ui/copy.js" ;
2222import { getUiRuntimeOptions , setUiRuntimeOptions } from "../ui/runtime.js" ;
23- import { type MenuItem , select } from "../ui/select.js" ;
23+ import { select } from "../ui/select.js" ;
2424import { sleep } from "../utils.js" ;
2525import {
2626 applyBackendCategoryDefaults ,
@@ -39,16 +39,15 @@ import {
3939 cloneBackendPluginConfig ,
4040 formatBackendNumberValue ,
4141} from "./backend-settings-helpers.js" ;
42+ import { promptBackendSettingsMenu } from "./backend-settings-prompt.js" ;
4243import {
4344 BACKEND_CATEGORY_OPTIONS ,
4445 BACKEND_DEFAULTS ,
4546 BACKEND_NUMBER_OPTION_BY_KEY ,
4647 BACKEND_TOGGLE_OPTION_BY_KEY ,
47- type BackendCategoryKey ,
4848 type BackendCategoryOption ,
4949 type BackendNumberSettingOption ,
5050 type BackendSettingFocusKey ,
51- type BackendSettingsHubAction ,
5251} from "./backend-settings-schema.js" ;
5352import { promptBehaviorSettingsPanel } from "./behavior-settings-panel.js" ;
5453import { promptDashboardDisplayPanel } from "./dashboard-display-panel.js" ;
@@ -622,135 +621,21 @@ async function promptBackendCategorySettings(
622621async function promptBackendSettings (
623622 initial : PluginConfig ,
624623) : Promise < PluginConfig | null > {
625- if ( ! input . isTTY || ! output . isTTY ) return null ;
626-
627- const ui = getUiRuntimeOptions ( ) ;
628- let draft = cloneBackendPluginConfig ( initial ) ;
629- let activeCategory = BACKEND_CATEGORY_OPTIONS [ 0 ] ?. key ?? "session-sync" ;
630- const focusByCategory : Partial <
631- Record < BackendCategoryKey , BackendSettingFocusKey >
632- > = { } ;
633- for ( const category of BACKEND_CATEGORY_OPTIONS ) {
634- focusByCategory [ category . key ] = getBackendCategoryInitialFocus ( category ) ;
635- }
636-
637- while ( true ) {
638- const previewFocus = focusByCategory [ activeCategory ] ?? null ;
639- const preview = buildBackendSettingsPreview ( draft , ui , previewFocus , {
640- highlightPreviewToken,
641- } ) ;
642- const categoryItems : MenuItem < BackendSettingsHubAction > [ ] =
643- BACKEND_CATEGORY_OPTIONS . map ( ( category , index ) => {
644- return {
645- label : `${ index + 1 } . ${ category . label } ` ,
646- hint : category . description ,
647- value : { type : "open-category" , key : category . key } ,
648- color : "green" ,
649- } ;
650- } ) ;
651-
652- const items : MenuItem < BackendSettingsHubAction > [ ] = [
653- {
654- label : UI_COPY . settings . previewHeading ,
655- value : { type : "cancel" } ,
656- kind : "heading" ,
657- } ,
658- {
659- label : preview . label ,
660- hint : preview . hint ,
661- value : { type : "cancel" } ,
662- disabled : true ,
663- color : "green" ,
664- hideUnavailableSuffix : true ,
665- } ,
666- { label : "" , value : { type : "cancel" } , separator : true } ,
667- {
668- label : UI_COPY . settings . backendCategoriesHeading ,
669- value : { type : "cancel" } ,
670- kind : "heading" ,
671- } ,
672- ...categoryItems ,
673- { label : "" , value : { type : "cancel" } , separator : true } ,
674- {
675- label : UI_COPY . settings . resetDefault ,
676- value : { type : "reset" } ,
677- color : "yellow" ,
678- } ,
679- {
680- label : UI_COPY . settings . saveAndBack ,
681- value : { type : "save" } ,
682- color : "green" ,
683- } ,
684- {
685- label : UI_COPY . settings . backNoSave ,
686- value : { type : "cancel" } ,
687- color : "red" ,
688- } ,
689- ] ;
690-
691- const initialCursor = items . findIndex ( ( item ) => {
692- if ( item . separator || item . disabled || item . kind === "heading" )
693- return false ;
694- return (
695- item . value . type === "open-category" && item . value . key === activeCategory
696- ) ;
697- } ) ;
698-
699- const result = await select < BackendSettingsHubAction > ( items , {
700- message : UI_COPY . settings . backendTitle ,
701- subtitle : UI_COPY . settings . backendSubtitle ,
702- help : UI_COPY . settings . backendHelp ,
703- clearScreen : true ,
704- theme : ui . theme ,
705- selectedEmphasis : "minimal" ,
706- initialCursor : initialCursor >= 0 ? initialCursor : undefined ,
707- onCursorChange : ( { cursor } ) => {
708- const focusedItem = items [ cursor ] ;
709- if ( focusedItem ?. value . type === "open-category" ) {
710- activeCategory = focusedItem . value . key ;
711- }
712- } ,
713- onInput : ( raw ) => {
714- const lower = raw . toLowerCase ( ) ;
715- if ( lower === "q" ) return { type : "cancel" } ;
716- if ( lower === "s" ) return { type : "save" } ;
717- if ( lower === "r" ) return { type : "reset" } ;
718- const parsed = Number . parseInt ( raw , 10 ) ;
719- if (
720- Number . isFinite ( parsed ) &&
721- parsed >= 1 &&
722- parsed <= BACKEND_CATEGORY_OPTIONS . length
723- ) {
724- const target = BACKEND_CATEGORY_OPTIONS [ parsed - 1 ] ;
725- if ( target ) return { type : "open-category" , key : target . key } ;
726- }
727- return undefined ;
728- } ,
729- } ) ;
730-
731- if ( ! result || result . type === "cancel" ) return null ;
732- if ( result . type === "save" ) return draft ;
733- if ( result . type === "reset" ) {
734- draft = cloneBackendPluginConfig ( BACKEND_DEFAULTS ) ;
735- for ( const category of BACKEND_CATEGORY_OPTIONS ) {
736- focusByCategory [ category . key ] =
737- getBackendCategoryInitialFocus ( category ) ;
738- }
739- activeCategory = BACKEND_CATEGORY_OPTIONS [ 0 ] ?. key ?? activeCategory ;
740- continue ;
741- }
742-
743- const category = getBackendCategory ( result . key , BACKEND_CATEGORY_OPTIONS ) ;
744- if ( ! category ) continue ;
745- activeCategory = category . key ;
746- const categoryResult = await promptBackendCategorySettings (
747- draft ,
748- category ,
749- focusByCategory [ category . key ] ?? getBackendCategoryInitialFocus ( category ) ,
750- ) ;
751- draft = categoryResult . draft ;
752- focusByCategory [ category . key ] = categoryResult . focusKey ;
753- }
624+ return promptBackendSettingsMenu ( {
625+ initial,
626+ isInteractive : ( ) => input . isTTY && output . isTTY ,
627+ ui : getUiRuntimeOptions ( ) ,
628+ cloneBackendPluginConfig,
629+ backendCategoryOptions : BACKEND_CATEGORY_OPTIONS ,
630+ getBackendCategoryInitialFocus,
631+ buildBackendSettingsPreview,
632+ highlightPreviewToken,
633+ select,
634+ getBackendCategory,
635+ promptBackendCategorySettings,
636+ backendDefaults : BACKEND_DEFAULTS ,
637+ copy : UI_COPY . settings ,
638+ } ) ;
754639}
755640
756641async function loadExperimentalSyncTarget ( ) : Promise <
0 commit comments