Skip to content

Commit 1e8ae5b

Browse files
authored
fix(cli): fix crash on startup in NO_COLOR mode (#13343) due to ungua… (#13352)
1 parent e8d0e0d commit 1e8ae5b

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

packages/cli/src/ui/components/Banner.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,25 @@
55
*/
66

77
import { Box, Text } from 'ink';
8-
import Gradient from 'ink-gradient';
9-
import { theme } from '../semantic-colors.js';
8+
import { ThemedGradient } from './ThemedGradient.js';
109

1110
interface BannerProps {
1211
bannerText: string;
1312
color: string;
1413
width: number;
1514
}
1615

17-
export const Banner = ({ bannerText, color, width }: BannerProps) => {
18-
const gradient = theme.ui.gradient;
19-
return (
20-
<Box
21-
flexDirection="column"
22-
borderStyle="round"
23-
borderColor={color}
24-
width={width}
25-
paddingLeft={1}
26-
paddingRight={1}
27-
>
28-
<Gradient colors={gradient}>
29-
<Text>{bannerText}</Text>
30-
</Gradient>
31-
</Box>
32-
);
33-
};
16+
export const Banner = ({ bannerText, color, width }: BannerProps) => (
17+
<Box
18+
flexDirection="column"
19+
borderStyle="round"
20+
borderColor={color}
21+
width={width}
22+
paddingLeft={1}
23+
paddingRight={1}
24+
>
25+
<ThemedGradient>
26+
<Text>{bannerText}</Text>
27+
</ThemedGradient>
28+
</Box>
29+
);

packages/cli/src/ui/components/GradientRegression.test.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
import { describe, it, expect, vi } from 'vitest';
88
import { renderWithProviders } from '../../test-utils/render.js';
9-
import { Footer } from './Footer.js';
10-
import { StatsDisplay } from './StatsDisplay.js';
119
import * as SessionContext from '../contexts/SessionContext.js';
1210
import type { SessionStatsState } from '../contexts/SessionContext.js';
11+
import { Banner } from './Banner.js';
12+
import { Footer } from './Footer.js';
13+
import { Header } from './Header.js';
14+
import { ModelDialog } from './ModelDialog.js';
15+
import { StatsDisplay } from './StatsDisplay.js';
1316

1417
// Mock the theme module
1518
vi.mock('../semantic-colors.js', async (importOriginal) => {
@@ -63,6 +66,36 @@ useSessionStatsMock.mockReturnValue({
6366
});
6467

6568
describe('Gradient Crash Regression Tests', () => {
69+
it('<Header /> should not crash when theme.ui.gradient is empty', () => {
70+
const { lastFrame } = renderWithProviders(
71+
<Header version="1.0.0" nightly={false} />,
72+
{
73+
width: 120,
74+
},
75+
);
76+
expect(lastFrame()).toBeDefined();
77+
});
78+
79+
it('<ModelDialog /> should not crash when theme.ui.gradient is empty', () => {
80+
const { lastFrame } = renderWithProviders(
81+
<ModelDialog onClose={() => {}} />,
82+
{
83+
width: 120,
84+
},
85+
);
86+
expect(lastFrame()).toBeDefined();
87+
});
88+
89+
it('<Banner /> should not crash when theme.ui.gradient is empty', () => {
90+
const { lastFrame } = renderWithProviders(
91+
<Banner bannerText="Test Banner" color="blue" width={80} />,
92+
{
93+
width: 120,
94+
},
95+
);
96+
expect(lastFrame()).toBeDefined();
97+
});
98+
6699
it('<Footer /> should not crash when theme.ui.gradient has only one color (or empty) and nightly is true', () => {
67100
const { lastFrame } = renderWithProviders(<Footer />, {
68101
width: 120,

packages/cli/src/ui/components/ModelDialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { useKeypress } from '../hooks/useKeypress.js';
2323
import { theme } from '../semantic-colors.js';
2424
import { DescriptiveRadioButtonSelect } from './shared/DescriptiveRadioButtonSelect.js';
2525
import { ConfigContext } from '../contexts/ConfigContext.js';
26-
import Gradient from 'ink-gradient';
26+
import { ThemedGradient } from './ThemedGradient.js';
2727

2828
interface ModelDialogProps {
2929
onClose: () => void;
@@ -115,9 +115,9 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
115115
<Text bold>Select Model</Text>
116116

117117
<Box marginTop={1} marginBottom={1} flexDirection="column">
118-
<Gradient colors={theme.ui.gradient}>
118+
<ThemedGradient>
119119
<Text>{header}</Text>
120-
</Gradient>
120+
</ThemedGradient>
121121
<Text>{subheader}</Text>
122122
</Box>
123123

0 commit comments

Comments
 (0)