|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import React, { useState, useEffect } from 'react'; |
|
|
import { Box, Text } from 'ink'; |
|
|
import { Colors } from '../colors.js'; |
|
|
import type { LoadedSettings, Settings } from '../../config/settings.js'; |
|
|
import { SettingScope } from '../../config/settings.js'; |
|
|
import { |
|
|
getScopeItems, |
|
|
getScopeMessageForSetting, |
|
|
} from '../../utils/dialogScopeUtils.js'; |
|
|
import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; |
|
|
import { |
|
|
getDialogSettingKeys, |
|
|
getSettingValue, |
|
|
setPendingSettingValue, |
|
|
getDisplayValue, |
|
|
hasRestartRequiredSettings, |
|
|
saveModifiedSettings, |
|
|
getSettingDefinition, |
|
|
isDefaultValue, |
|
|
requiresRestart, |
|
|
getRestartRequiredFromModified, |
|
|
getDefaultValue, |
|
|
setPendingSettingValueAny, |
|
|
getNestedValue, |
|
|
} from '../../utils/settingsUtils.js'; |
|
|
import { useVimMode } from '../contexts/VimModeContext.js'; |
|
|
import { useKeypress } from '../hooks/useKeypress.js'; |
|
|
import chalk from 'chalk'; |
|
|
import { cpSlice, cpLen, stripUnsafeCharacters } from '../utils/textUtils.js'; |
|
|
|
|
|
interface SettingsDialogProps { |
|
|
settings: LoadedSettings; |
|
|
onSelect: (settingName: string | undefined, scope: SettingScope) => void; |
|
|
onRestartRequest?: () => void; |
|
|
} |
|
|
|
|
|
const maxItemsToShow = 8; |
|
|
|
|
|
export function SettingsDialog({ |
|
|
settings, |
|
|
onSelect, |
|
|
onRestartRequest, |
|
|
}: SettingsDialogProps): React.JSX.Element { |
|
|
|
|
|
const { vimEnabled, toggleVimEnabled } = useVimMode(); |
|
|
|
|
|
|
|
|
const [focusSection, setFocusSection] = useState<'settings' | 'scope'>( |
|
|
'settings', |
|
|
); |
|
|
|
|
|
const [selectedScope, setSelectedScope] = useState<SettingScope>( |
|
|
SettingScope.User, |
|
|
); |
|
|
|
|
|
const [activeSettingIndex, setActiveSettingIndex] = useState(0); |
|
|
|
|
|
const [scrollOffset, setScrollOffset] = useState(0); |
|
|
const [showRestartPrompt, setShowRestartPrompt] = useState(false); |
|
|
|
|
|
|
|
|
const [pendingSettings, setPendingSettings] = useState<Settings>(() => |
|
|
|
|
|
structuredClone(settings.forScope(selectedScope).settings), |
|
|
); |
|
|
|
|
|
|
|
|
const [modifiedSettings, setModifiedSettings] = useState<Set<string>>( |
|
|
new Set(), |
|
|
); |
|
|
|
|
|
|
|
|
type PendingValue = boolean | number | string; |
|
|
const [globalPendingChanges, setGlobalPendingChanges] = useState< |
|
|
Map<string, PendingValue> |
|
|
>(new Map()); |
|
|
|
|
|
|
|
|
const [_restartRequiredSettings, setRestartRequiredSettings] = useState< |
|
|
Set<string> |
|
|
>(new Set()); |
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
let updated = structuredClone(settings.forScope(selectedScope).settings); |
|
|
|
|
|
const newModified = new Set<string>(); |
|
|
const newRestartRequired = new Set<string>(); |
|
|
for (const [key, value] of globalPendingChanges.entries()) { |
|
|
const def = getSettingDefinition(key); |
|
|
if (def?.type === 'boolean' && typeof value === 'boolean') { |
|
|
updated = setPendingSettingValue(key, value, updated); |
|
|
} else if ( |
|
|
(def?.type === 'number' && typeof value === 'number') || |
|
|
(def?.type === 'string' && typeof value === 'string') |
|
|
) { |
|
|
updated = setPendingSettingValueAny(key, value, updated); |
|
|
} |
|
|
newModified.add(key); |
|
|
if (requiresRestart(key)) newRestartRequired.add(key); |
|
|
} |
|
|
setPendingSettings(updated); |
|
|
setModifiedSettings(newModified); |
|
|
setRestartRequiredSettings(newRestartRequired); |
|
|
setShowRestartPrompt(newRestartRequired.size > 0); |
|
|
}, [selectedScope, settings, globalPendingChanges]); |
|
|
|
|
|
const generateSettingsItems = () => { |
|
|
const settingKeys = getDialogSettingKeys(); |
|
|
|
|
|
return settingKeys.map((key: string) => { |
|
|
const definition = getSettingDefinition(key); |
|
|
|
|
|
return { |
|
|
label: definition?.label || key, |
|
|
value: key, |
|
|
type: definition?.type, |
|
|
toggle: () => { |
|
|
if (definition?.type !== 'boolean') { |
|
|
|
|
|
return; |
|
|
} |
|
|
const currentValue = getSettingValue(key, pendingSettings, {}); |
|
|
const newValue = !currentValue; |
|
|
|
|
|
setPendingSettings((prev) => |
|
|
setPendingSettingValue(key, newValue, prev), |
|
|
); |
|
|
|
|
|
if (!requiresRestart(key)) { |
|
|
const immediateSettings = new Set([key]); |
|
|
const immediateSettingsObject = setPendingSettingValueAny( |
|
|
key, |
|
|
newValue, |
|
|
{} as Settings, |
|
|
); |
|
|
|
|
|
console.log( |
|
|
`[DEBUG SettingsDialog] Saving ${key} immediately with value:`, |
|
|
newValue, |
|
|
); |
|
|
saveModifiedSettings( |
|
|
immediateSettings, |
|
|
immediateSettingsObject, |
|
|
settings, |
|
|
selectedScope, |
|
|
); |
|
|
|
|
|
|
|
|
if (key === 'general.vimMode' && newValue !== vimEnabled) { |
|
|
|
|
|
toggleVimEnabled().catch((error) => { |
|
|
console.error('Failed to toggle vim mode:', error); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
setModifiedSettings((prev) => { |
|
|
const updated = new Set(prev); |
|
|
updated.delete(key); |
|
|
return updated; |
|
|
}); |
|
|
|
|
|
|
|
|
setRestartRequiredSettings((prev) => { |
|
|
const updated = new Set(prev); |
|
|
updated.delete(key); |
|
|
return updated; |
|
|
}); |
|
|
|
|
|
|
|
|
setGlobalPendingChanges((prev) => { |
|
|
if (!prev.has(key)) return prev; |
|
|
const next = new Map(prev); |
|
|
next.delete(key); |
|
|
return next; |
|
|
}); |
|
|
|
|
|
|
|
|
setPendingSettings( |
|
|
structuredClone(settings.forScope(selectedScope).settings), |
|
|
); |
|
|
} else { |
|
|
|
|
|
setModifiedSettings((prev) => { |
|
|
const updated = new Set(prev).add(key); |
|
|
const needsRestart = hasRestartRequiredSettings(updated); |
|
|
console.log( |
|
|
`[DEBUG SettingsDialog] Modified settings:`, |
|
|
Array.from(updated), |
|
|
'Needs restart:', |
|
|
needsRestart, |
|
|
); |
|
|
if (needsRestart) { |
|
|
setShowRestartPrompt(true); |
|
|
setRestartRequiredSettings((prevRestart) => |
|
|
new Set(prevRestart).add(key), |
|
|
); |
|
|
} |
|
|
return updated; |
|
|
}); |
|
|
|
|
|
|
|
|
setGlobalPendingChanges((prev) => { |
|
|
const next = new Map(prev); |
|
|
next.set(key, newValue as PendingValue); |
|
|
return next; |
|
|
}); |
|
|
} |
|
|
}, |
|
|
}; |
|
|
}); |
|
|
}; |
|
|
|
|
|
const items = generateSettingsItems(); |
|
|
|
|
|
|
|
|
const [editingKey, setEditingKey] = useState<string | null>(null); |
|
|
const [editBuffer, setEditBuffer] = useState<string>(''); |
|
|
const [editCursorPos, setEditCursorPos] = useState<number>(0); |
|
|
const [cursorVisible, setCursorVisible] = useState<boolean>(true); |
|
|
|
|
|
useEffect(() => { |
|
|
if (!editingKey) { |
|
|
setCursorVisible(true); |
|
|
return; |
|
|
} |
|
|
const id = setInterval(() => setCursorVisible((v) => !v), 500); |
|
|
return () => clearInterval(id); |
|
|
}, [editingKey]); |
|
|
|
|
|
const startEditing = (key: string, initial?: string) => { |
|
|
setEditingKey(key); |
|
|
const initialValue = initial ?? ''; |
|
|
setEditBuffer(initialValue); |
|
|
setEditCursorPos(cpLen(initialValue)); |
|
|
}; |
|
|
|
|
|
const commitEdit = (key: string) => { |
|
|
const definition = getSettingDefinition(key); |
|
|
const type = definition?.type; |
|
|
|
|
|
if (editBuffer.trim() === '' && type === 'number') { |
|
|
|
|
|
setEditingKey(null); |
|
|
setEditBuffer(''); |
|
|
setEditCursorPos(0); |
|
|
return; |
|
|
} |
|
|
|
|
|
let parsed: string | number; |
|
|
if (type === 'number') { |
|
|
const numParsed = Number(editBuffer.trim()); |
|
|
if (Number.isNaN(numParsed)) { |
|
|
|
|
|
setEditingKey(null); |
|
|
setEditBuffer(''); |
|
|
setEditCursorPos(0); |
|
|
return; |
|
|
} |
|
|
parsed = numParsed; |
|
|
} else { |
|
|
|
|
|
parsed = editBuffer; |
|
|
} |
|
|
|
|
|
|
|
|
setPendingSettings((prev) => setPendingSettingValueAny(key, parsed, prev)); |
|
|
|
|
|
if (!requiresRestart(key)) { |
|
|
const immediateSettings = new Set([key]); |
|
|
const immediateSettingsObject = setPendingSettingValueAny( |
|
|
key, |
|
|
parsed, |
|
|
{} as Settings, |
|
|
); |
|
|
saveModifiedSettings( |
|
|
immediateSettings, |
|
|
immediateSettingsObject, |
|
|
settings, |
|
|
selectedScope, |
|
|
); |
|
|
|
|
|
|
|
|
setModifiedSettings((prev) => { |
|
|
const updated = new Set(prev); |
|
|
updated.delete(key); |
|
|
return updated; |
|
|
}); |
|
|
setRestartRequiredSettings((prev) => { |
|
|
const updated = new Set(prev); |
|
|
updated.delete(key); |
|
|
return updated; |
|
|
}); |
|
|
|
|
|
|
|
|
setGlobalPendingChanges((prev) => { |
|
|
if (!prev.has(key)) return prev; |
|
|
const next = new Map(prev); |
|
|
next.delete(key); |
|
|
return next; |
|
|
}); |
|
|
} else { |
|
|
|
|
|
setModifiedSettings((prev) => { |
|
|
const updated = new Set(prev).add(key); |
|
|
const needsRestart = hasRestartRequiredSettings(updated); |
|
|
if (needsRestart) { |
|
|
setShowRestartPrompt(true); |
|
|
setRestartRequiredSettings((prevRestart) => |
|
|
new Set(prevRestart).add(key), |
|
|
); |
|
|
} |
|
|
return updated; |
|
|
}); |
|
|
|
|
|
|
|
|
setGlobalPendingChanges((prev) => { |
|
|
const next = new Map(prev); |
|
|
next.set(key, parsed as PendingValue); |
|
|
return next; |
|
|
}); |
|
|
} |
|
|
|
|
|
setEditingKey(null); |
|
|
setEditBuffer(''); |
|
|
setEditCursorPos(0); |
|
|
}; |
|
|
|
|
|
|
|
|
const scopeItems = getScopeItems(); |
|
|
|
|
|
const handleScopeHighlight = (scope: SettingScope) => { |
|
|
setSelectedScope(scope); |
|
|
}; |
|
|
|
|
|
const handleScopeSelect = (scope: SettingScope) => { |
|
|
handleScopeHighlight(scope); |
|
|
setFocusSection('settings'); |
|
|
}; |
|
|
|
|
|
|
|
|
const visibleItems = items.slice(scrollOffset, scrollOffset + maxItemsToShow); |
|
|
|
|
|
const showScrollUp = true; |
|
|
const showScrollDown = true; |
|
|
|
|
|
useKeypress( |
|
|
(key) => { |
|
|
const { name, ctrl } = key; |
|
|
if (name === 'tab') { |
|
|
setFocusSection((prev) => (prev === 'settings' ? 'scope' : 'settings')); |
|
|
} |
|
|
if (focusSection === 'settings') { |
|
|
|
|
|
if (editingKey) { |
|
|
const definition = getSettingDefinition(editingKey); |
|
|
const type = definition?.type; |
|
|
|
|
|
if (key.paste && key.sequence) { |
|
|
let pasted = key.sequence; |
|
|
if (type === 'number') { |
|
|
pasted = key.sequence.replace(/[^0-9\-+.]/g, ''); |
|
|
} |
|
|
if (pasted) { |
|
|
setEditBuffer((b) => { |
|
|
const before = cpSlice(b, 0, editCursorPos); |
|
|
const after = cpSlice(b, editCursorPos); |
|
|
return before + pasted + after; |
|
|
}); |
|
|
setEditCursorPos((pos) => pos + cpLen(pasted)); |
|
|
} |
|
|
return; |
|
|
} |
|
|
if (name === 'backspace' || name === 'delete') { |
|
|
if (name === 'backspace' && editCursorPos > 0) { |
|
|
setEditBuffer((b) => { |
|
|
const before = cpSlice(b, 0, editCursorPos - 1); |
|
|
const after = cpSlice(b, editCursorPos); |
|
|
return before + after; |
|
|
}); |
|
|
setEditCursorPos((pos) => pos - 1); |
|
|
} else if (name === 'delete' && editCursorPos < cpLen(editBuffer)) { |
|
|
setEditBuffer((b) => { |
|
|
const before = cpSlice(b, 0, editCursorPos); |
|
|
const after = cpSlice(b, editCursorPos + 1); |
|
|
return before + after; |
|
|
}); |
|
|
|
|
|
} |
|
|
return; |
|
|
} |
|
|
if (name === 'escape') { |
|
|
commitEdit(editingKey); |
|
|
return; |
|
|
} |
|
|
if (name === 'return') { |
|
|
commitEdit(editingKey); |
|
|
return; |
|
|
} |
|
|
|
|
|
let ch = key.sequence; |
|
|
let isValidChar = false; |
|
|
if (type === 'number') { |
|
|
|
|
|
isValidChar = /[0-9\-+.]/.test(ch); |
|
|
} else { |
|
|
ch = stripUnsafeCharacters(ch); |
|
|
|
|
|
|
|
|
isValidChar = ch.length === 1; |
|
|
} |
|
|
|
|
|
if (isValidChar) { |
|
|
setEditBuffer((currentBuffer) => { |
|
|
const beforeCursor = cpSlice(currentBuffer, 0, editCursorPos); |
|
|
const afterCursor = cpSlice(currentBuffer, editCursorPos); |
|
|
return beforeCursor + ch + afterCursor; |
|
|
}); |
|
|
setEditCursorPos((pos) => pos + 1); |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
if (name === 'left') { |
|
|
setEditCursorPos((pos) => Math.max(0, pos - 1)); |
|
|
return; |
|
|
} |
|
|
if (name === 'right') { |
|
|
setEditCursorPos((pos) => Math.min(cpLen(editBuffer), pos + 1)); |
|
|
return; |
|
|
} |
|
|
|
|
|
if (name === 'home') { |
|
|
setEditCursorPos(0); |
|
|
return; |
|
|
} |
|
|
if (name === 'end') { |
|
|
setEditCursorPos(cpLen(editBuffer)); |
|
|
return; |
|
|
} |
|
|
|
|
|
return; |
|
|
} |
|
|
if (name === 'up' || name === 'k') { |
|
|
|
|
|
if (editingKey) { |
|
|
commitEdit(editingKey); |
|
|
} |
|
|
const newIndex = |
|
|
activeSettingIndex > 0 ? activeSettingIndex - 1 : items.length - 1; |
|
|
setActiveSettingIndex(newIndex); |
|
|
|
|
|
if (newIndex === items.length - 1) { |
|
|
setScrollOffset(Math.max(0, items.length - maxItemsToShow)); |
|
|
} else if (newIndex < scrollOffset) { |
|
|
setScrollOffset(newIndex); |
|
|
} |
|
|
} else if (name === 'down' || name === 'j') { |
|
|
|
|
|
if (editingKey) { |
|
|
commitEdit(editingKey); |
|
|
} |
|
|
const newIndex = |
|
|
activeSettingIndex < items.length - 1 ? activeSettingIndex + 1 : 0; |
|
|
setActiveSettingIndex(newIndex); |
|
|
|
|
|
if (newIndex === 0) { |
|
|
setScrollOffset(0); |
|
|
} else if (newIndex >= scrollOffset + maxItemsToShow) { |
|
|
setScrollOffset(newIndex - maxItemsToShow + 1); |
|
|
} |
|
|
} else if (name === 'return' || name === 'space') { |
|
|
const currentItem = items[activeSettingIndex]; |
|
|
if ( |
|
|
currentItem?.type === 'number' || |
|
|
currentItem?.type === 'string' |
|
|
) { |
|
|
startEditing(currentItem.value); |
|
|
} else { |
|
|
currentItem?.toggle(); |
|
|
} |
|
|
} else if (/^[0-9]$/.test(key.sequence || '') && !editingKey) { |
|
|
const currentItem = items[activeSettingIndex]; |
|
|
if (currentItem?.type === 'number') { |
|
|
startEditing(currentItem.value, key.sequence); |
|
|
} |
|
|
} else if (ctrl && (name === 'c' || name === 'l')) { |
|
|
|
|
|
const currentSetting = items[activeSettingIndex]; |
|
|
if (currentSetting) { |
|
|
const defaultValue = getDefaultValue(currentSetting.value); |
|
|
const defType = currentSetting.type; |
|
|
if (defType === 'boolean') { |
|
|
const booleanDefaultValue = |
|
|
typeof defaultValue === 'boolean' ? defaultValue : false; |
|
|
setPendingSettings((prev) => |
|
|
setPendingSettingValue( |
|
|
currentSetting.value, |
|
|
booleanDefaultValue, |
|
|
prev, |
|
|
), |
|
|
); |
|
|
} else if (defType === 'number' || defType === 'string') { |
|
|
if ( |
|
|
typeof defaultValue === 'number' || |
|
|
typeof defaultValue === 'string' |
|
|
) { |
|
|
setPendingSettings((prev) => |
|
|
setPendingSettingValueAny( |
|
|
currentSetting.value, |
|
|
defaultValue, |
|
|
prev, |
|
|
), |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
setModifiedSettings((prev) => { |
|
|
const updated = new Set(prev); |
|
|
updated.delete(currentSetting.value); |
|
|
return updated; |
|
|
}); |
|
|
|
|
|
|
|
|
setRestartRequiredSettings((prev) => { |
|
|
const updated = new Set(prev); |
|
|
updated.delete(currentSetting.value); |
|
|
return updated; |
|
|
}); |
|
|
|
|
|
|
|
|
if (!requiresRestart(currentSetting.value)) { |
|
|
const immediateSettings = new Set([currentSetting.value]); |
|
|
const toSaveValue = |
|
|
currentSetting.type === 'boolean' |
|
|
? typeof defaultValue === 'boolean' |
|
|
? defaultValue |
|
|
: false |
|
|
: typeof defaultValue === 'number' || |
|
|
typeof defaultValue === 'string' |
|
|
? defaultValue |
|
|
: undefined; |
|
|
const immediateSettingsObject = |
|
|
toSaveValue !== undefined |
|
|
? setPendingSettingValueAny( |
|
|
currentSetting.value, |
|
|
toSaveValue, |
|
|
{} as Settings, |
|
|
) |
|
|
: ({} as Settings); |
|
|
|
|
|
saveModifiedSettings( |
|
|
immediateSettings, |
|
|
immediateSettingsObject, |
|
|
settings, |
|
|
selectedScope, |
|
|
); |
|
|
|
|
|
|
|
|
setGlobalPendingChanges((prev) => { |
|
|
if (!prev.has(currentSetting.value)) return prev; |
|
|
const next = new Map(prev); |
|
|
next.delete(currentSetting.value); |
|
|
return next; |
|
|
}); |
|
|
} else { |
|
|
|
|
|
if ( |
|
|
(currentSetting.type === 'boolean' && |
|
|
typeof defaultValue === 'boolean') || |
|
|
(currentSetting.type === 'number' && |
|
|
typeof defaultValue === 'number') || |
|
|
(currentSetting.type === 'string' && |
|
|
typeof defaultValue === 'string') |
|
|
) { |
|
|
setGlobalPendingChanges((prev) => { |
|
|
const next = new Map(prev); |
|
|
next.set(currentSetting.value, defaultValue as PendingValue); |
|
|
return next; |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (showRestartPrompt && name === 'r') { |
|
|
|
|
|
const restartRequiredSettings = |
|
|
getRestartRequiredFromModified(modifiedSettings); |
|
|
const restartRequiredSet = new Set(restartRequiredSettings); |
|
|
|
|
|
if (restartRequiredSet.size > 0) { |
|
|
saveModifiedSettings( |
|
|
restartRequiredSet, |
|
|
pendingSettings, |
|
|
settings, |
|
|
selectedScope, |
|
|
); |
|
|
|
|
|
|
|
|
setGlobalPendingChanges((prev) => { |
|
|
if (prev.size === 0) return prev; |
|
|
const next = new Map(prev); |
|
|
for (const key of restartRequiredSet) { |
|
|
next.delete(key); |
|
|
} |
|
|
return next; |
|
|
}); |
|
|
} |
|
|
|
|
|
setShowRestartPrompt(false); |
|
|
setRestartRequiredSettings(new Set()); |
|
|
if (onRestartRequest) onRestartRequest(); |
|
|
} |
|
|
if (name === 'escape') { |
|
|
if (editingKey) { |
|
|
commitEdit(editingKey); |
|
|
} else { |
|
|
onSelect(undefined, selectedScope); |
|
|
} |
|
|
} |
|
|
}, |
|
|
{ isActive: true }, |
|
|
); |
|
|
|
|
|
return ( |
|
|
<Box |
|
|
borderStyle="round" |
|
|
borderColor={Colors.Gray} |
|
|
flexDirection="row" |
|
|
padding={1} |
|
|
width="100%" |
|
|
height="100%" |
|
|
> |
|
|
<Box flexDirection="column" flexGrow={1}> |
|
|
<Text bold color={Colors.AccentBlue}> |
|
|
Settings |
|
|
</Text> |
|
|
<Box height={1} /> |
|
|
{showScrollUp && <Text color={Colors.Gray}>▲</Text>} |
|
|
{visibleItems.map((item, idx) => { |
|
|
const isActive = |
|
|
focusSection === 'settings' && |
|
|
activeSettingIndex === idx + scrollOffset; |
|
|
|
|
|
const scopeSettings = settings.forScope(selectedScope).settings; |
|
|
const mergedSettings = settings.merged; |
|
|
|
|
|
let displayValue: string; |
|
|
if (editingKey === item.value) { |
|
|
// Show edit buffer with advanced cursor highlighting |
|
|
if (cursorVisible && editCursorPos < cpLen(editBuffer)) { |
|
|
// Cursor is in the middle or at start of text |
|
|
const beforeCursor = cpSlice(editBuffer, 0, editCursorPos); |
|
|
const atCursor = cpSlice( |
|
|
editBuffer, |
|
|
editCursorPos, |
|
|
editCursorPos + 1, |
|
|
); |
|
|
const afterCursor = cpSlice(editBuffer, editCursorPos + 1); |
|
|
displayValue = |
|
|
beforeCursor + chalk.inverse(atCursor) + afterCursor; |
|
|
} else if (cursorVisible && editCursorPos >= cpLen(editBuffer)) { |
|
|
// Cursor is at the end - show inverted space |
|
|
displayValue = editBuffer + chalk.inverse(' '); |
|
|
} else { |
|
|
// Cursor not visible |
|
|
displayValue = editBuffer; |
|
|
} |
|
|
} else if (item.type === 'number' || item.type === 'string') { |
|
|
// For numbers/strings, get the actual current value from pending settings |
|
|
const path = item.value.split('.'); |
|
|
const currentValue = getNestedValue(pendingSettings, path); |
|
|
|
|
|
const defaultValue = getDefaultValue(item.value); |
|
|
|
|
|
if (currentValue !== undefined && currentValue !== null) { |
|
|
displayValue = String(currentValue); |
|
|
} else { |
|
|
displayValue = |
|
|
defaultValue !== undefined && defaultValue !== null |
|
|
? String(defaultValue) |
|
|
: ''; |
|
|
} |
|
|
|
|
|
// Add * if value differs from default OR if currently being modified |
|
|
const isModified = modifiedSettings.has(item.value); |
|
|
const effectiveCurrentValue = |
|
|
currentValue !== undefined && currentValue !== null |
|
|
? currentValue |
|
|
: defaultValue; |
|
|
const isDifferentFromDefault = |
|
|
effectiveCurrentValue !== defaultValue; |
|
|
|
|
|
if (isDifferentFromDefault || isModified) { |
|
|
displayValue += '*'; |
|
|
} |
|
|
} else { |
|
|
// For booleans and other types, use existing logic |
|
|
displayValue = getDisplayValue( |
|
|
item.value, |
|
|
scopeSettings, |
|
|
mergedSettings, |
|
|
modifiedSettings, |
|
|
pendingSettings, |
|
|
); |
|
|
} |
|
|
const shouldBeGreyedOut = isDefaultValue(item.value, scopeSettings); |
|
|
|
|
|
// Generate scope message for this setting |
|
|
const scopeMessage = getScopeMessageForSetting( |
|
|
item.value, |
|
|
selectedScope, |
|
|
settings, |
|
|
); |
|
|
|
|
|
return ( |
|
|
<React.Fragment key={item.value}> |
|
|
<Box flexDirection="row" alignItems="center"> |
|
|
<Box minWidth={2} flexShrink={0}> |
|
|
<Text color={isActive ? Colors.AccentGreen : Colors.Gray}> |
|
|
{isActive ? '●' : ''} |
|
|
</Text> |
|
|
</Box> |
|
|
<Box minWidth={50}> |
|
|
<Text |
|
|
color={isActive ? Colors.AccentGreen : Colors.Foreground} |
|
|
> |
|
|
{item.label} |
|
|
{scopeMessage && ( |
|
|
<Text color={Colors.Gray}> {scopeMessage}</Text> |
|
|
)} |
|
|
</Text> |
|
|
</Box> |
|
|
<Box minWidth={3} /> |
|
|
<Text |
|
|
color={ |
|
|
isActive |
|
|
? Colors.AccentGreen |
|
|
: shouldBeGreyedOut |
|
|
? Colors.Gray |
|
|
: Colors.Foreground |
|
|
} |
|
|
> |
|
|
{displayValue} |
|
|
</Text> |
|
|
</Box> |
|
|
<Box height={1} /> |
|
|
</React.Fragment> |
|
|
); |
|
|
})} |
|
|
{showScrollDown && <Text color={Colors.Gray}>▼</Text>} |
|
|
|
|
|
<Box height={1} /> |
|
|
|
|
|
<Box marginTop={1} flexDirection="column"> |
|
|
<Text bold={focusSection === 'scope'} wrap="truncate"> |
|
|
{focusSection === 'scope' ? '> ' : ' '}Apply To |
|
|
</Text> |
|
|
<RadioButtonSelect |
|
|
items={scopeItems} |
|
|
initialIndex={0} |
|
|
onSelect={handleScopeSelect} |
|
|
onHighlight={handleScopeHighlight} |
|
|
isFocused={focusSection === 'scope'} |
|
|
showNumbers={focusSection === 'scope'} |
|
|
/> |
|
|
</Box> |
|
|
|
|
|
<Box height={1} /> |
|
|
<Text color={Colors.Gray}> |
|
|
(Use Enter to select, Tab to change focus) |
|
|
</Text> |
|
|
{showRestartPrompt && ( |
|
|
<Text color={Colors.AccentYellow}> |
|
|
To see changes, Gemini CLI must be restarted. Press r to exit and |
|
|
apply changes now. |
|
|
</Text> |
|
|
)} |
|
|
</Box> |
|
|
</Box> |
|
|
); |
|
|
} |
|
|
|