@@ -33,6 +33,7 @@ import { getUnifiedSettingsPath } from "../unified-settings.js";
3333import { sleep } from "../utils.js" ;
3434import { promptBehaviorSettingsPanel } from "./behavior-settings-panel.js" ;
3535import { promptDashboardDisplayPanel } from "./dashboard-display-panel.js" ;
36+ import { promptStatuslineSettingsPanel } from "./statusline-settings-panel.js" ;
3637import { promptThemeSettingsPanel } from "./theme-settings-panel.js" ;
3738
3839type DashboardDisplaySettingKey =
@@ -154,14 +155,6 @@ type PreviewFocusKey =
154155 | "menuLayoutMode"
155156 | null ;
156157
157- type StatuslineConfigAction =
158- | { type : "toggle" ; key : DashboardStatuslineField }
159- | { type : "move-up" ; key : DashboardStatuslineField }
160- | { type : "move-down" ; key : DashboardStatuslineField }
161- | { type : "reset" }
162- | { type : "save" }
163- | { type : "cancel" } ;
164-
165158type BackendToggleSettingKey =
166159 | "liveAccountSync"
167160 | "sessionAffinity"
@@ -1372,193 +1365,17 @@ function reorderField(
13721365async function promptStatuslineSettings (
13731366 initial : DashboardDisplaySettings ,
13741367) : Promise < DashboardDisplaySettings | null > {
1375- if ( ! input . isTTY || ! output . isTTY ) {
1376- return null ;
1377- }
1378-
1379- const ui = getUiRuntimeOptions ( ) ;
1380- let draft = cloneDashboardSettings ( initial ) ;
1381- let focusKey : DashboardStatuslineField =
1382- draft . menuStatuslineFields ?. [ 0 ] ?? "last-used" ;
1383- while ( true ) {
1384- const preview = buildAccountListPreview ( draft , ui , focusKey ) ;
1385- const selectedSet = new Set (
1386- normalizeStatuslineFields ( draft . menuStatuslineFields ) ,
1387- ) ;
1388- const ordered = normalizeStatuslineFields ( draft . menuStatuslineFields ) ;
1389- const orderMap = new Map < DashboardStatuslineField , number > ( ) ;
1390- for ( let index = 0 ; index < ordered . length ; index += 1 ) {
1391- const key = ordered [ index ] ;
1392- if ( key ) orderMap . set ( key , index + 1 ) ;
1393- }
1394-
1395- const optionItems : MenuItem < StatuslineConfigAction > [ ] =
1396- STATUSLINE_FIELD_OPTIONS . map ( ( option , index ) => {
1397- const enabled = selectedSet . has ( option . key ) ;
1398- const rank = orderMap . get ( option . key ) ;
1399- const label = `${ formatDashboardSettingState ( enabled ) } ${ index + 1 } . ${ option . label } ${ rank ? ` (order ${ rank } )` : "" } ` ;
1400- return {
1401- label,
1402- hint : option . description ,
1403- value : { type : "toggle" , key : option . key } ,
1404- color : enabled ? "green" : "yellow" ,
1405- } ;
1406- } ) ;
1407-
1408- const items : MenuItem < StatuslineConfigAction > [ ] = [
1409- {
1410- label : UI_COPY . settings . previewHeading ,
1411- value : { type : "cancel" } ,
1412- kind : "heading" ,
1413- } ,
1414- {
1415- label : preview . label ,
1416- hint : preview . hint ,
1417- value : { type : "cancel" } ,
1418- color : "green" ,
1419- disabled : true ,
1420- hideUnavailableSuffix : true ,
1421- } ,
1422- { label : "" , value : { type : "cancel" } , separator : true } ,
1423- {
1424- label : UI_COPY . settings . displayHeading ,
1425- value : { type : "cancel" } ,
1426- kind : "heading" ,
1427- } ,
1428- ...optionItems ,
1429- { label : "" , value : { type : "cancel" } , separator : true } ,
1430- {
1431- label : UI_COPY . settings . moveUp ,
1432- value : { type : "move-up" , key : focusKey } ,
1433- color : "green" ,
1434- } ,
1435- {
1436- label : UI_COPY . settings . moveDown ,
1437- value : { type : "move-down" , key : focusKey } ,
1438- color : "green" ,
1439- } ,
1440- { label : "" , value : { type : "cancel" } , separator : true } ,
1441- {
1442- label : UI_COPY . settings . resetDefault ,
1443- value : { type : "reset" } ,
1444- color : "yellow" ,
1445- } ,
1446- {
1447- label : UI_COPY . settings . saveAndBack ,
1448- value : { type : "save" } ,
1449- color : "green" ,
1450- } ,
1451- {
1452- label : UI_COPY . settings . backNoSave ,
1453- value : { type : "cancel" } ,
1454- color : "red" ,
1455- } ,
1456- ] ;
1457-
1458- const initialCursor = items . findIndex (
1459- ( item ) => item . value . type === "toggle" && item . value . key === focusKey ,
1460- ) ;
1461-
1462- const updateFocusedPreview = ( cursor : number ) => {
1463- const focusedItem = items [ cursor ] ;
1464- const focusedKey =
1465- focusedItem ?. value . type === "toggle" ? focusedItem . value . key : focusKey ;
1466- const nextPreview = buildAccountListPreview ( draft , ui , focusedKey ) ;
1467- const previewItem = items [ 1 ] ;
1468- if ( ! previewItem ) return ;
1469- previewItem . label = nextPreview . label ;
1470- previewItem . hint = nextPreview . hint ;
1471- } ;
1472-
1473- const result = await select < StatuslineConfigAction > ( items , {
1474- message : UI_COPY . settings . summaryTitle ,
1475- subtitle : UI_COPY . settings . summarySubtitle ,
1476- help : UI_COPY . settings . summaryHelp ,
1477- clearScreen : true ,
1478- theme : ui . theme ,
1479- selectedEmphasis : "minimal" ,
1480- initialCursor : initialCursor >= 0 ? initialCursor : undefined ,
1481- onCursorChange : ( { cursor } ) => {
1482- const focusedItem = items [ cursor ] ;
1483- if ( focusedItem ?. value . type === "toggle" ) {
1484- focusKey = focusedItem . value . key ;
1485- }
1486- updateFocusedPreview ( cursor ) ;
1487- } ,
1488- onInput : ( raw ) => {
1489- const lower = raw . toLowerCase ( ) ;
1490- if ( lower === "q" ) return { type : "cancel" } ;
1491- if ( lower === "s" ) return { type : "save" } ;
1492- if ( lower === "r" ) return { type : "reset" } ;
1493- if ( lower === "[" ) return { type : "move-up" , key : focusKey } ;
1494- if ( lower === "]" ) return { type : "move-down" , key : focusKey } ;
1495- const parsed = Number . parseInt ( raw , 10 ) ;
1496- if (
1497- Number . isFinite ( parsed ) &&
1498- parsed >= 1 &&
1499- parsed <= STATUSLINE_FIELD_OPTIONS . length
1500- ) {
1501- const target = STATUSLINE_FIELD_OPTIONS [ parsed - 1 ] ;
1502- if ( target ) {
1503- return { type : "toggle" , key : target . key } ;
1504- }
1505- }
1506- return undefined ;
1507- } ,
1508- } ) ;
1509-
1510- if ( ! result || result . type === "cancel" ) {
1511- return null ;
1512- }
1513- if ( result . type === "save" ) {
1514- return draft ;
1515- }
1516- if ( result . type === "reset" ) {
1517- draft = applyDashboardDefaultsForKeys ( draft , STATUSLINE_PANEL_KEYS ) ;
1518- focusKey = draft . menuStatuslineFields ?. [ 0 ] ?? "last-used" ;
1519- continue ;
1520- }
1521- if ( result . type === "move-up" ) {
1522- draft = {
1523- ...draft ,
1524- menuStatuslineFields : reorderField (
1525- normalizeStatuslineFields ( draft . menuStatuslineFields ) ,
1526- result . key ,
1527- - 1 ,
1528- ) ,
1529- } ;
1530- focusKey = result . key ;
1531- continue ;
1532- }
1533- if ( result . type === "move-down" ) {
1534- draft = {
1535- ...draft ,
1536- menuStatuslineFields : reorderField (
1537- normalizeStatuslineFields ( draft . menuStatuslineFields ) ,
1538- result . key ,
1539- 1 ,
1540- ) ,
1541- } ;
1542- focusKey = result . key ;
1543- continue ;
1544- }
1545-
1546- focusKey = result . key ;
1547- const fields = normalizeStatuslineFields ( draft . menuStatuslineFields ) ;
1548- const isEnabled = fields . includes ( result . key ) ;
1549- if ( isEnabled ) {
1550- const next = fields . filter ( ( field ) => field !== result . key ) ;
1551- draft = {
1552- ...draft ,
1553- menuStatuslineFields : next . length > 0 ? next : [ result . key ] ,
1554- } ;
1555- } else {
1556- draft = {
1557- ...draft ,
1558- menuStatuslineFields : [ ...fields , result . key ] ,
1559- } ;
1560- }
1561- }
1368+ return promptStatuslineSettingsPanel ( initial , {
1369+ cloneDashboardSettings,
1370+ buildAccountListPreview,
1371+ normalizeStatuslineFields,
1372+ formatDashboardSettingState,
1373+ reorderField,
1374+ applyDashboardDefaultsForKeys,
1375+ STATUSLINE_FIELD_OPTIONS ,
1376+ STATUSLINE_PANEL_KEYS ,
1377+ UI_COPY ,
1378+ } ) ;
15621379}
15631380
15641381async function configureStatuslineSettings (
0 commit comments