Skip to content

Commit 020745c

Browse files
author
charles wu
committed
fix(cli): align command picker columns
1 parent 5cc1fb3 commit 020745c

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

src/cli/tui/components/command-list.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ export function CommandList({ commands, selectedIndex }: CommandListProps) {
2121

2222
const { endIndex, startIndex } = getVisibleWindow(commands.length, selectedIndex, MAX_VISIBLE_COMMANDS);
2323
const visibleCommands = commands.slice(startIndex, endIndex);
24+
const commandColumnWidth = getCommandColumnWidth(commands);
2425
return (
2526
<Box
2627
flexDirection="column"
28+
width="100%"
2729
borderStyle="single"
2830
borderColor={currentTheme.colors.borderColor}
2931
paddingX={1}
@@ -35,30 +37,32 @@ export function CommandList({ commands, selectedIndex }: CommandListProps) {
3537
{visibleCommands.map((cmd, visibleIndex) => {
3638
const index = startIndex + visibleIndex;
3739
return (
38-
<Box key={cmd.name} flexDirection="row">
39-
<Text
40-
color={index === selectedIndex ? currentTheme.colors.highlightedText : undefined}
41-
bold={index === selectedIndex}
42-
>
43-
{index === selectedIndex ? "❯ " : " "}
44-
</Text>
45-
<Text
46-
color={index === selectedIndex ? currentTheme.colors.highlightedText : undefined}
47-
bold={index === selectedIndex}
48-
>
49-
/{cmd.name}
50-
</Text>
51-
<Text dimColor>
52-
{" "}
53-
[{cmd.type}] {summarizeDescription(cmd.description)}
54-
</Text>
55-
</Box>
40+
<Box key={cmd.name} flexDirection="row">
41+
<Box flexShrink={0} width={commandColumnWidth}>
42+
<Text
43+
color={index === selectedIndex ? currentTheme.colors.highlightedText : undefined}
44+
bold={index === selectedIndex}
45+
>
46+
{index === selectedIndex ? "❯ " : " "}/{cmd.name}
47+
</Text>
48+
</Box>
49+
<Box flexGrow={1} flexShrink={1}>
50+
<Text dimColor>
51+
[{cmd.type}] {summarizeDescription(cmd.description)}
52+
</Text>
53+
</Box>
54+
</Box>
5655
);
5756
})}
5857
</Box>
5958
);
6059
}
6160

61+
function getCommandColumnWidth(commands: SlashCommand[]): number {
62+
const longestCommand = commands.reduce((max, command) => Math.max(max, command.name.length), 0);
63+
return longestCommand + 4;
64+
}
65+
6266
function summarizeDescription(description: string, maxLength = 72): string {
6367
const normalized = description.replace(/\s+/g, " ").trim();
6468
if (normalized.length <= maxLength) return normalized;

0 commit comments

Comments
 (0)