Skip to content

Commit f144ba5

Browse files
refactor(components): reuse SelectPromptHint in ModelPicker, PlanApproval, ToolApproval
1 parent 989ceec commit f144ba5

4 files changed

Lines changed: 24 additions & 15 deletions

File tree

src/components/ModelPicker.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Text, useInput } from 'ink';
33
import { useEffect, useState } from 'react';
44

55
import { ollama } from '../utils';
6-
import { SelectPrompt } from './SelectPrompt';
6+
import { SelectPrompt, SelectPromptHint } from './SelectPrompt';
77

88
interface Props {
99
currentModel: string;
@@ -58,9 +58,7 @@ export function ModelPicker({ currentModel, onSelect, onClose }: Props) {
5858
onChange={onSelect}
5959
onEscape={onClose}
6060
>
61-
<Text dimColor>
62-
Select a model (↑↓ + Enter to confirm, Esc to cancel)
63-
</Text>
61+
<SelectPromptHint message="Select a model" />
6462
</SelectPrompt>
6563
);
6664
}

src/components/PlanApproval.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Box, Text } from 'ink';
22
import { useCallback } from 'react';
33

44
import { MODE } from '../constants';
5-
import { SelectPrompt } from './SelectPrompt';
5+
import { SelectPrompt, SelectPromptHint } from './SelectPrompt';
66

77
interface Props {
88
planContent: string;
@@ -42,9 +42,7 @@ export function PlanApproval({ planContent, onModeChange }: Props) {
4242
<Text>{planContent}</Text>
4343
</Box>
4444

45-
<Text dimColor>
46-
Select execution mode (↑↓ + Enter to confirm, Esc to cancel)
47-
</Text>
45+
<SelectPromptHint message="Select execution mode" />
4846
</Box>
4947
</SelectPrompt>
5048
);

src/components/SelectPrompt.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import type { SelectProps } from '@inkjs/ui';
22
import { Select } from '@inkjs/ui';
3-
import { Box, useInput } from 'ink';
4-
import type { ReactNode } from 'react';
3+
import { Box, Text, useInput } from 'ink';
54

65
export interface SelectPromptProps extends SelectProps {
7-
children?: ReactNode;
6+
children?: React.ReactNode;
87
onEscape?: () => void;
98
}
109

10+
interface SelectPromptHintProps {
11+
message?: string;
12+
escapeLabel?: string;
13+
}
14+
1115
export function SelectPrompt({
1216
children,
1317
onEscape,
@@ -27,3 +31,14 @@ export function SelectPrompt({
2731
</Box>
2832
);
2933
}
34+
35+
export function SelectPromptHint({
36+
message = 'Select option',
37+
escapeLabel = 'cancel',
38+
}: SelectPromptHintProps) {
39+
return (
40+
<Text dimColor>
41+
{message} (↑↓ + Enter to confirm, Esc to {escapeLabel})
42+
</Text>
43+
);
44+
}

src/components/ToolApproval.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useCallback } from 'react';
33

44
import { DECISION } from '../constants';
55
import type { ToolCall } from '../utils/ollama';
6-
import { SelectPrompt } from './SelectPrompt';
6+
import { SelectPrompt, SelectPromptHint } from './SelectPrompt';
77

88
interface Props {
99
toolCall: ToolCall;
@@ -46,9 +46,7 @@ export function ToolApproval({ toolCall, onDecision }: Props) {
4646
</Text>
4747
</Box>
4848

49-
<Text dimColor>
50-
Select approval action (↑↓ + Enter to confirm, Esc to reject)
51-
</Text>
49+
<SelectPromptHint message="Select approval action" escapeLabel="reject" />
5250
</SelectPrompt>
5351
);
5452
}

0 commit comments

Comments
 (0)