-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdashboard.ts
More file actions
293 lines (281 loc) · 7.92 KB
/
Copy pathdashboard.ts
File metadata and controls
293 lines (281 loc) · 7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import {
type DashboardAccentColor,
type DashboardDisplaySettings,
type DashboardStatuslineField,
type DashboardThemePreset,
DEFAULT_DASHBOARD_DISPLAY_SETTINGS,
getDashboardSettingsPath,
loadDashboardDisplaySettings,
} from "../../dashboard-settings.js";
import { UI_COPY } from "../../ui/ui-copy.js";
import { getUiRuntimeOptions, setUiRuntimeOptions } from "../../ui/runtime.js";
import { promptBehaviorSettingsPanel } from "../behavior-settings-panel.js";
import {
promptDashboardDisplayPanel,
type DashboardDisplaySettingOption,
} from "../dashboard-display-panel.js";
import {
formatDashboardSettingState,
formatMenuLayoutMode,
formatMenuQuotaTtl,
formatMenuSortMode,
} from "../dashboard-formatters.js";
import { configureDashboardSettingsController } from "../dashboard-settings-controller.js";
import { configureDashboardSettingsEntry } from "../dashboard-settings-entry.js";
import {
promptBehaviorSettingsPanelEntry,
promptDashboardDisplaySettingsPanelEntry,
promptStatuslineSettingsPanelEntry,
promptThemeSettingsPanelEntry,
} from "../settings-panels.js";
import { normalizeStatuslineFields } from "../settings-preview.js";
import { promptStatuslineSettingsPanel } from "../statusline-settings-panel.js";
import { promptThemeSettingsPanel } from "../theme-settings-panel.js";
import {
applyDashboardDefaultsForKeys,
buildAccountListPreview,
cloneDashboardSettings,
type DashboardSettingKey,
dashboardSettingsEqual,
isTtyInteractive,
persistDashboardSettingsSelection,
resolveMenuLayoutMode,
} from "./shared.js";
const DASHBOARD_DISPLAY_OPTIONS: DashboardDisplaySettingOption[] = [
{
key: "menuShowStatusBadge",
label: "Show Status Badges",
description: "Show [ok], [active], and similar badges.",
},
{
key: "menuShowCurrentBadge",
label: "Show [current]",
description: "Mark the account active in Codex.",
},
{
key: "menuShowLastUsed",
label: "Show Last Used",
description: "Show relative usage like 'today'.",
},
{
key: "menuShowQuotaSummary",
label: "Show Limits (5h / 7d)",
description: "Show limit bars in each row.",
},
{
key: "menuShowQuotaCooldown",
label: "Show Limit Cooldowns",
description: "Show reset timers next to 5h/7d bars.",
},
{
key: "menuShowFetchStatus",
label: "Show Fetch Status",
description: "Show background limit refresh status in the menu subtitle.",
},
{
key: "menuHighlightCurrentRow",
label: "Highlight Current Row",
description: "Use stronger color on the current row.",
},
{
key: "menuSortEnabled",
label: "Enable Smart Sort",
description: "Sort accounts by readiness (view only).",
},
{
key: "menuSortPinCurrent",
label: "Pin [current] when tied",
description: "Keep current at top only when it is equally ready.",
},
{
key: "menuSortQuickSwitchVisibleRow",
label: "Quick Switch Uses Visible Rows",
description: "Number keys (1-9) follow what you see in the list.",
},
];
const STATUSLINE_FIELD_OPTIONS: Array<{
key: DashboardStatuslineField;
label: string;
description: string;
}> = [
{
key: "last-used",
label: "Show Last Used",
description: "Example: 'today' or '2d ago'.",
},
{
key: "limits",
label: "Show Limits (5h / 7d)",
description: "Uses cached limit data from checks.",
},
{
key: "status",
label: "Show Status Text",
description: "Visible when badges are hidden.",
},
];
const AUTO_RETURN_OPTIONS_MS = [1_000, 2_000, 4_000] as const;
const MENU_QUOTA_TTL_OPTIONS_MS = [
60_000,
5 * 60_000,
10 * 60_000,
] as const;
const THEME_PRESET_OPTIONS: DashboardThemePreset[] = ["green", "blue"];
const ACCENT_COLOR_OPTIONS: DashboardAccentColor[] = [
"green",
"cyan",
"blue",
"yellow",
];
const ACCOUNT_LIST_PANEL_KEYS = [
"menuShowStatusBadge",
"menuShowCurrentBadge",
"menuShowLastUsed",
"menuShowQuotaSummary",
"menuShowQuotaCooldown",
"menuShowFetchStatus",
"menuShowDetailsForUnselectedRows",
"menuHighlightCurrentRow",
"menuSortEnabled",
"menuSortMode",
"menuSortPinCurrent",
"menuSortQuickSwitchVisibleRow",
"menuLayoutMode",
] as const satisfies readonly DashboardSettingKey[];
const STATUSLINE_PANEL_KEYS = [
"menuStatuslineFields",
] as const satisfies readonly DashboardSettingKey[];
export const BEHAVIOR_PANEL_KEYS = [
"actionAutoReturnMs",
"actionPauseOnKey",
"menuAutoFetchLimits",
"menuShowFetchStatus",
"menuQuotaTtlMs",
] as const satisfies readonly DashboardSettingKey[];
export const THEME_PANEL_KEYS = [
"uiThemePreset",
"uiAccentColor",
] as const satisfies readonly DashboardSettingKey[];
export function applyUiThemeFromDashboardSettings(
settings: DashboardDisplaySettings,
): void {
const current = getUiRuntimeOptions();
setUiRuntimeOptions({
v2Enabled: current.v2Enabled,
colorProfile: current.colorProfile,
glyphMode: current.glyphMode,
palette: settings.uiThemePreset ?? "green",
accent: settings.uiAccentColor ?? "green",
});
}
/* c8 ignore start - interactive prompt flows are covered by integration tests */
export async function promptDashboardDisplaySettings(
initial: DashboardDisplaySettings,
): Promise<DashboardDisplaySettings | null> {
return promptDashboardDisplaySettingsPanelEntry({
initial,
promptDashboardDisplayPanel,
cloneDashboardSettings,
buildAccountListPreview,
formatDashboardSettingState,
formatMenuSortMode,
resolveMenuLayoutMode: (settings = DEFAULT_DASHBOARD_DISPLAY_SETTINGS) =>
resolveMenuLayoutMode(settings),
formatMenuLayoutMode,
applyDashboardDefaultsForKeys,
DASHBOARD_DISPLAY_OPTIONS,
ACCOUNT_LIST_PANEL_KEYS,
UI_COPY,
});
}
export async function configureDashboardDisplaySettings(
currentSettings?: DashboardDisplaySettings,
): Promise<DashboardDisplaySettings> {
return configureDashboardSettingsEntry(currentSettings, {
configureDashboardSettingsController,
loadDashboardDisplaySettings,
promptSettings: promptDashboardDisplaySettings,
settingsEqual: dashboardSettingsEqual,
persistSelection: (selected) =>
persistDashboardSettingsSelection(
selected,
ACCOUNT_LIST_PANEL_KEYS,
"account-list",
),
applyUiThemeFromDashboardSettings,
isInteractive: isTtyInteractive,
getDashboardSettingsPath,
writeLine: (message) => {
console.log(message);
},
});
}
export async function promptStatuslineSettings(
initial: DashboardDisplaySettings,
): Promise<DashboardDisplaySettings | null> {
return promptStatuslineSettingsPanelEntry({
initial,
promptStatuslineSettingsPanel,
cloneDashboardSettings,
buildAccountListPreview,
normalizeStatuslineFields,
formatDashboardSettingState,
applyDashboardDefaultsForKeys,
STATUSLINE_FIELD_OPTIONS,
STATUSLINE_PANEL_KEYS,
UI_COPY,
});
}
export async function configureStatuslineSettings(
currentSettings?: DashboardDisplaySettings,
): Promise<DashboardDisplaySettings> {
return configureDashboardSettingsEntry(currentSettings, {
configureDashboardSettingsController,
loadDashboardDisplaySettings,
promptSettings: promptStatuslineSettings,
settingsEqual: dashboardSettingsEqual,
persistSelection: (selected) =>
persistDashboardSettingsSelection(
selected,
STATUSLINE_PANEL_KEYS,
"summary-fields",
),
applyUiThemeFromDashboardSettings,
isInteractive: isTtyInteractive,
getDashboardSettingsPath,
writeLine: (message) => {
console.log(message);
},
});
}
export async function promptBehaviorSettings(
initial: DashboardDisplaySettings,
): Promise<DashboardDisplaySettings | null> {
return promptBehaviorSettingsPanelEntry({
initial,
promptBehaviorSettingsPanel,
cloneDashboardSettings,
applyDashboardDefaultsForKeys,
formatMenuQuotaTtl,
AUTO_RETURN_OPTIONS_MS,
MENU_QUOTA_TTL_OPTIONS_MS,
BEHAVIOR_PANEL_KEYS,
UI_COPY,
});
}
export async function promptThemeSettings(
initial: DashboardDisplaySettings,
): Promise<DashboardDisplaySettings | null> {
return promptThemeSettingsPanelEntry({
initial,
promptThemeSettingsPanel,
cloneDashboardSettings,
applyDashboardDefaultsForKeys,
applyUiThemeFromDashboardSettings,
THEME_PRESET_OPTIONS,
ACCENT_COLOR_OPTIONS,
THEME_PANEL_KEYS,
UI_COPY,
});
}
/* c8 ignore stop */