Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 70 additions & 10 deletions src/tui/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from 'chalk';
import * as fs from 'fs';
import {
Box,
Text,
Expand All @@ -17,8 +18,11 @@ import type { Settings } from '../types/Settings';
import type { WidgetItem } from '../types/Widget';
import {
CCSTATUSLINE_COMMANDS,
getActiveClaudeSettingsPath,
getClaudeLocalSettingsPath,
getClaudeSettingsPath,
getExistingStatusLine,
hasLocalSettings,
installStatusLine,
isBunxAvailable,
isClaudeCodeVersionAtLeast,
Expand Down Expand Up @@ -47,6 +51,7 @@ import { loadClaudeStatusLineState } from './claude-status';
import {
ColorMenu,
ConfirmDialog,
FileTargetSelect,
GlobalOverridesMenu,
InstallMenu,
ItemsEditor,
Expand Down Expand Up @@ -78,6 +83,7 @@ type AppScreen = 'main'
| 'confirm'
| 'powerline'
| 'install'
| 'fileTarget'
| 'refreshInterval';

interface ConfirmDialogState {
Expand Down Expand Up @@ -117,6 +123,13 @@ export const App: React.FC = () => {
const [existingStatusLine, setExistingStatusLine] = useState<string | null>(null);
const [flashMessage, setFlashMessage] = useState<FlashMessage | null>(null);
const [previewIsTruncated, setPreviewIsTruncated] = useState(false);
const [localSettingsDetected, setLocalSettingsDetected] = useState(false);
const [pendingInstall, setPendingInstall] = useState<{
command: string;
displayName: string;
useBunx: boolean;
targetPath?: string;
} | null>(null);
const [currentRefreshInterval, setCurrentRefreshInterval] = useState<number | null>(null);
const [supportsRefreshInterval] = useState(() => isClaudeCodeVersionAtLeast('2.1.97'));

Expand All @@ -132,6 +145,7 @@ export const App: React.FC = () => {
setOriginalSettings(cloneSettings(loadedSettings));
});
void isInstalled().then(setIsClaudeInstalled);
setLocalSettingsDetected(hasLocalSettings());

// Check for Powerline fonts on startup (use sync version that doesn't call execSync)
const fontStatus = checkPowerlineFonts();
Expand Down Expand Up @@ -188,24 +202,42 @@ export const App: React.FC = () => {
}
});

const handleInstallSelection = useCallback((command: string, displayName: string, useBunx: boolean) => {
const handleInstallSelection = useCallback((command: string, displayName: string, useBunx: boolean, targetPath?: string) => {
const effectiveTarget = targetPath ?? getClaudeSettingsPath();

void getExistingStatusLine().then((existing) => {
const isAlreadyInstalled = isKnownCommand(existing ?? '');
let message: string;

if (existing && !isAlreadyInstalled) {
message = `This will modify ${getClaudeSettingsPath()}\n\nA status line is already configured: "${existing}"\nReplace it with ${command}?`;
message = `This will modify ${effectiveTarget}\n\nA status line is already configured: "${existing}"\nReplace it with ${command}?`;
} else if (isAlreadyInstalled) {
message = `ccstatusline is already installed in ${getClaudeSettingsPath()}\nUpdate it with ${command}?`;
message = `ccstatusline is already installed in ${getActiveClaudeSettingsPath()}\nUpdate it with ${command} in ${effectiveTarget}?`;
} else {
message = `This will modify ${getClaudeSettingsPath()} to add ccstatusline with ${displayName}.\nContinue?`;
message = `This will modify ${effectiveTarget} to add ccstatusline with ${displayName}.\nContinue?`;
}

// Warn if installing to global while local has a statusLine (install won't take effect)
if (targetPath !== getClaudeLocalSettingsPath() && hasLocalSettings()) {
try {
const localContent = fs.readFileSync(getClaudeLocalSettingsPath(), 'utf-8');
const localData = JSON.parse(localContent) as { statusLine?: { command?: string } };
if (localData.statusLine?.command) {
message += '\n\n\u26a0 settings.local.json has a statusLine entry that will take precedence over this file. The install may not take effect.';
}
} catch {
// Can't read local — skip warning
}
}

setConfirmDialog({
message,
cancelScreen: 'install',
action: async () => {
await installStatusLine(useBunx, supportsRefreshInterval);
await installStatusLine(useBunx, {
targetPath,
supportsRefreshInterval
});
const installedStatusLineState = await loadClaudeStatusLineState();
setIsClaudeInstalled(true);
setExistingStatusLine(installedStatusLineState.existingStatusLine ?? command);
Expand All @@ -220,13 +252,23 @@ export const App: React.FC = () => {

const handleNpxInstall = useCallback(() => {
setMenuSelections(prev => ({ ...prev, install: 0 }));
handleInstallSelection(CCSTATUSLINE_COMMANDS.NPM, 'npx', false);
}, [handleInstallSelection]);
if (localSettingsDetected) {
setPendingInstall({ command: CCSTATUSLINE_COMMANDS.NPM, displayName: 'npx', useBunx: false });
setScreen('fileTarget');
} else {
handleInstallSelection(CCSTATUSLINE_COMMANDS.NPM, 'npx', false);
}
}, [handleInstallSelection, localSettingsDetected]);

const handleBunxInstall = useCallback(() => {
setMenuSelections(prev => ({ ...prev, install: 1 }));
handleInstallSelection(CCSTATUSLINE_COMMANDS.BUNX, 'bunx', true);
}, [handleInstallSelection]);
if (localSettingsDetected) {
setPendingInstall({ command: CCSTATUSLINE_COMMANDS.BUNX, displayName: 'bunx', useBunx: true });
setScreen('fileTarget');
} else {
handleInstallSelection(CCSTATUSLINE_COMMANDS.BUNX, 'bunx', true);
}
}, [handleInstallSelection, localSettingsDetected]);

const handleInstallMenuCancel = useCallback(() => {
setMenuSelections(clearInstallMenuSelection);
Expand All @@ -241,7 +283,7 @@ export const App: React.FC = () => {
if (isClaudeInstalled) {
// Uninstall
setConfirmDialog({
message: `This will remove ccstatusline from ${getClaudeSettingsPath()}. Continue?`,
message: `This will remove ccstatusline from ${getActiveClaudeSettingsPath()}. Continue?`,
action: async () => {
await uninstallStatusLine();
setIsClaudeInstalled(false);
Expand Down Expand Up @@ -507,6 +549,24 @@ export const App: React.FC = () => {
onSelectBunx={handleBunxInstall}
onCancel={handleInstallMenuCancel}
initialSelection={menuSelections.install}
localSettingsDetected={localSettingsDetected}
/>
)}
{screen === 'fileTarget' && pendingInstall && (
<FileTargetSelect
onSelect={(targetPath) => {
handleInstallSelection(
pendingInstall.command,
pendingInstall.displayName,
pendingInstall.useBunx,
targetPath
);
setPendingInstall(null);
}}
onCancel={() => {
setPendingInstall(null);
setScreen('install');
}}
/>
)}
{screen === 'refreshInterval' && (
Expand Down
80 changes: 80 additions & 0 deletions src/tui/components/FileTargetSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as fs from 'fs';
import {
Box,
Text,
useInput
} from 'ink';
import React from 'react';

import type { ClaudeSettings } from '../../types/ClaudeSettings';
import {
getClaudeLocalSettingsPath,
getClaudeSettingsPath
} from '../../utils/claude-settings';

import { List } from './List';

export interface FileTargetSelectProps {
onSelect: (targetPath: string) => void;
onCancel: () => void;
}

export const FileTargetSelect: React.FC<FileTargetSelectProps> = ({
onSelect,
onCancel
}) => {
useInput((_, key) => {
if (key.escape) {
onCancel();
}
});

const globalPath = getClaudeSettingsPath();
const localPath = getClaudeLocalSettingsPath();

// Check if local already has a statusLine — installing to global would be overridden
let localHasStatusLine = false;
try {
const content = fs.readFileSync(localPath, 'utf-8');
const data = JSON.parse(content) as ClaudeSettings;
localHasStatusLine = !!data.statusLine?.command;
} catch {
// file unreadable — no warning needed
}

const items = [
{
label: 'settings.json',
sublabel: localHasStatusLine
? '(will be overridden by settings.local.json)'
: '(default)',
value: 'global'
},
{ label: 'settings.local.json', sublabel: '(local override)', value: 'local' }
];

return (
<Box flexDirection='column'>
<Text bold>settings.local.json detected</Text>
<Box marginTop={1}>
<Text dimColor>Select which file to install to:</Text>
</Box>
<List
color='blue'
marginTop={1}
items={items}
onSelect={(value) => {
if (value === 'back') {
onCancel();
return;
}
onSelect(value === 'local' ? localPath : globalPath);
}}
showBackButton={true}
/>
<Box marginTop={1}>
<Text dimColor>Press Enter to select, ESC to go back</Text>
</Box>
</Box>
);
};
10 changes: 6 additions & 4 deletions src/tui/components/InstallMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface InstallMenuProps {
onSelectBunx: () => void;
onCancel: () => void;
initialSelection?: number;
localSettingsDetected?: boolean;
}

export const InstallMenu: React.FC<InstallMenuProps> = ({
Expand All @@ -24,7 +25,8 @@ export const InstallMenu: React.FC<InstallMenuProps> = ({
onSelectNpx,
onSelectBunx,
onCancel,
initialSelection = 0
initialSelection = 0,
localSettingsDetected = false
}) => {
useInput((_, key) => {
if (key.escape) {
Expand Down Expand Up @@ -97,9 +99,9 @@ export const InstallMenu: React.FC<InstallMenuProps> = ({

<Box marginTop={2}>
<Text dimColor>
The selected command will be written to
{' '}
{getClaudeSettingsPath()}
{localSettingsDetected
? 'You will be asked which settings file to target next.'
: `The selected command will be written to ${getClaudeSettingsPath()}`}
</Text>
</Box>

Expand Down
1 change: 1 addition & 0 deletions src/tui/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Barrel file - exports all components and their types
export * from './ColorMenu';
export * from './ConfirmDialog';
export * from './FileTargetSelect';
export * from './GlobalOverridesMenu';
export * from './InstallMenu';
export * from './ItemsEditor';
Expand Down
Loading