mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,48 +1,41 @@
|
||||
import * as React from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import { type Command, formatDescriptionWithSource } from '../../commands.js'
|
||||
import { truncate } from '../../utils/truncate.js'
|
||||
import { Box, Text, useTabHeaderFocus } from '@anthropic/ink'
|
||||
import { Select } from '../CustomSelect/select.js'
|
||||
import * as React from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { type Command, formatDescriptionWithSource } from '../../commands.js';
|
||||
import { truncate } from '../../utils/truncate.js';
|
||||
import { Box, Text, useTabHeaderFocus } from '@anthropic/ink';
|
||||
import { Select } from '../CustomSelect/select.js';
|
||||
|
||||
type Props = {
|
||||
commands: Command[]
|
||||
maxHeight: number
|
||||
columns: number
|
||||
title: string
|
||||
onCancel: () => void
|
||||
emptyMessage?: string
|
||||
}
|
||||
commands: Command[];
|
||||
maxHeight: number;
|
||||
columns: number;
|
||||
title: string;
|
||||
onCancel: () => void;
|
||||
emptyMessage?: string;
|
||||
};
|
||||
|
||||
export function Commands({
|
||||
commands,
|
||||
maxHeight,
|
||||
columns,
|
||||
title,
|
||||
onCancel,
|
||||
emptyMessage,
|
||||
}: Props): React.ReactNode {
|
||||
const { headerFocused, focusHeader } = useTabHeaderFocus()
|
||||
const maxWidth = Math.max(1, columns - 10)
|
||||
const visibleCount = Math.max(1, Math.floor((maxHeight - 10) / 2))
|
||||
export function Commands({ commands, maxHeight, columns, title, onCancel, emptyMessage }: Props): React.ReactNode {
|
||||
const { headerFocused, focusHeader } = useTabHeaderFocus();
|
||||
const maxWidth = Math.max(1, columns - 10);
|
||||
const visibleCount = Math.max(1, Math.floor((maxHeight - 10) / 2));
|
||||
|
||||
const options = useMemo(() => {
|
||||
// Custom commands can appear more than once (e.g. same name at user and
|
||||
// project scope). Dedupe by name to avoid React key collisions in Select.
|
||||
const seen = new Set<string>()
|
||||
const seen = new Set<string>();
|
||||
return commands
|
||||
.filter(cmd => {
|
||||
if (seen.has(cmd.name)) return false
|
||||
seen.add(cmd.name)
|
||||
return true
|
||||
if (seen.has(cmd.name)) return false;
|
||||
seen.add(cmd.name);
|
||||
return true;
|
||||
})
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map(cmd => ({
|
||||
label: `/${cmd.name}`,
|
||||
value: cmd.name,
|
||||
description: truncate(formatDescriptionWithSource(cmd), maxWidth, true),
|
||||
}))
|
||||
}, [commands, maxWidth])
|
||||
}));
|
||||
}, [commands, maxWidth]);
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" paddingY={1}>
|
||||
@@ -66,5 +59,5 @@ export function Commands({
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import * as React from 'react'
|
||||
import { Box, Text } from '@anthropic/ink'
|
||||
import { PromptInputHelpMenu } from '../PromptInput/PromptInputHelpMenu.js'
|
||||
import * as React from 'react';
|
||||
import { Box, Text } from '@anthropic/ink';
|
||||
import { PromptInputHelpMenu } from '../PromptInput/PromptInputHelpMenu.js';
|
||||
|
||||
export function General(): React.ReactNode {
|
||||
return (
|
||||
<Box flexDirection="column" paddingY={1} gap={1}>
|
||||
<Box>
|
||||
<Text>
|
||||
Claude understands your codebase, makes edits with your permission,
|
||||
and executes commands — right from your terminal.
|
||||
Claude understands your codebase, makes edits with your permission, and executes commands — right from your
|
||||
terminal.
|
||||
</Text>
|
||||
</Box>
|
||||
<Box flexDirection="column">
|
||||
@@ -18,5 +18,5 @@ export function General(): React.ReactNode {
|
||||
<PromptInputHelpMenu gap={2} fixedWidth={true} />
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,66 +1,55 @@
|
||||
import * as React from 'react'
|
||||
import { useExitOnCtrlCDWithKeybindings } from 'src/hooks/useExitOnCtrlCDWithKeybindings.js'
|
||||
import { useShortcutDisplay } from 'src/keybindings/useShortcutDisplay.js'
|
||||
import * as React from 'react';
|
||||
import { useExitOnCtrlCDWithKeybindings } from 'src/hooks/useExitOnCtrlCDWithKeybindings.js';
|
||||
import { useShortcutDisplay } from 'src/keybindings/useShortcutDisplay.js';
|
||||
import {
|
||||
builtInCommandNames,
|
||||
type Command,
|
||||
type CommandResultDisplay,
|
||||
INTERNAL_ONLY_COMMANDS,
|
||||
} from '../../commands.js'
|
||||
import { useIsInsideModal } from '../../context/modalContext.js'
|
||||
import { useTerminalSize } from '../../hooks/useTerminalSize.js'
|
||||
import { Box, Link, Text, Tab, Tabs, Pane } from '@anthropic/ink'
|
||||
import { useKeybinding } from '../../keybindings/useKeybinding.js'
|
||||
import { Commands } from './Commands.js'
|
||||
import { General } from './General.js'
|
||||
} from '../../commands.js';
|
||||
import { useIsInsideModal } from '../../context/modalContext.js';
|
||||
import { useTerminalSize } from '../../hooks/useTerminalSize.js';
|
||||
import { Box, Link, Text, Tab, Tabs, Pane } from '@anthropic/ink';
|
||||
import { useKeybinding } from '../../keybindings/useKeybinding.js';
|
||||
import { Commands } from './Commands.js';
|
||||
import { General } from './General.js';
|
||||
|
||||
type Props = {
|
||||
onClose: (
|
||||
result?: string,
|
||||
options?: { display?: CommandResultDisplay },
|
||||
) => void
|
||||
commands: Command[]
|
||||
}
|
||||
onClose: (result?: string, options?: { display?: CommandResultDisplay }) => void;
|
||||
commands: Command[];
|
||||
};
|
||||
|
||||
export function HelpV2({ onClose, commands }: Props): React.ReactNode {
|
||||
const { rows, columns } = useTerminalSize()
|
||||
const maxHeight = Math.floor(rows / 2)
|
||||
const { rows, columns } = useTerminalSize();
|
||||
const maxHeight = Math.floor(rows / 2);
|
||||
// Inside the modal slot, FullscreenLayout already caps height and Pane/Tabs
|
||||
// use flexShrink=0 (see #23592) — our own height= constraint would clip the
|
||||
// footer since Tabs won't shrink to fit. Let the modal slot handle sizing.
|
||||
const insideModal = useIsInsideModal()
|
||||
const insideModal = useIsInsideModal();
|
||||
|
||||
const close = () => onClose('Help dialog dismissed', { display: 'system' })
|
||||
useKeybinding('help:dismiss', close, { context: 'Help' })
|
||||
const exitState = useExitOnCtrlCDWithKeybindings(close)
|
||||
const dismissShortcut = useShortcutDisplay('help:dismiss', 'Help', 'esc')
|
||||
const close = () => onClose('Help dialog dismissed', { display: 'system' });
|
||||
useKeybinding('help:dismiss', close, { context: 'Help' });
|
||||
const exitState = useExitOnCtrlCDWithKeybindings(close);
|
||||
const dismissShortcut = useShortcutDisplay('help:dismiss', 'Help', 'esc');
|
||||
|
||||
const builtinNames = builtInCommandNames()
|
||||
let builtinCommands = commands.filter(
|
||||
cmd => builtinNames.has(cmd.name) && !cmd.isHidden,
|
||||
)
|
||||
let antOnlyCommands: Command[] = []
|
||||
const builtinNames = builtInCommandNames();
|
||||
let builtinCommands = commands.filter(cmd => builtinNames.has(cmd.name) && !cmd.isHidden);
|
||||
let antOnlyCommands: Command[] = [];
|
||||
|
||||
// We have to do this in an `if` to help treeshaking
|
||||
if (process.env.USER_TYPE === 'ant') {
|
||||
const internalOnlyNames = new Set(INTERNAL_ONLY_COMMANDS.map(_ => _.name))
|
||||
builtinCommands = builtinCommands.filter(
|
||||
cmd => !internalOnlyNames.has(cmd.name),
|
||||
)
|
||||
antOnlyCommands = commands.filter(
|
||||
cmd => internalOnlyNames.has(cmd.name) && !cmd.isHidden,
|
||||
)
|
||||
const internalOnlyNames = new Set(INTERNAL_ONLY_COMMANDS.map(_ => _.name));
|
||||
builtinCommands = builtinCommands.filter(cmd => !internalOnlyNames.has(cmd.name));
|
||||
antOnlyCommands = commands.filter(cmd => internalOnlyNames.has(cmd.name) && !cmd.isHidden);
|
||||
}
|
||||
|
||||
const customCommands = commands.filter(
|
||||
cmd => !builtinNames.has(cmd.name) && !cmd.isHidden,
|
||||
)
|
||||
const customCommands = commands.filter(cmd => !builtinNames.has(cmd.name) && !cmd.isHidden);
|
||||
|
||||
const tabs = [
|
||||
<Tab key="general" title="general">
|
||||
<General />
|
||||
</Tab>,
|
||||
]
|
||||
];
|
||||
|
||||
tabs.push(
|
||||
<Tab key="commands" title="commands">
|
||||
@@ -72,7 +61,7 @@ export function HelpV2({ onClose, commands }: Props): React.ReactNode {
|
||||
onCancel={close}
|
||||
/>
|
||||
</Tab>,
|
||||
)
|
||||
);
|
||||
|
||||
tabs.push(
|
||||
<Tab key="custom" title="custom-commands">
|
||||
@@ -85,7 +74,7 @@ export function HelpV2({ onClose, commands }: Props): React.ReactNode {
|
||||
onCancel={close}
|
||||
/>
|
||||
</Tab>,
|
||||
)
|
||||
);
|
||||
|
||||
if (process.env.USER_TYPE === 'ant' && antOnlyCommands.length > 0) {
|
||||
tabs.push(
|
||||
@@ -98,18 +87,14 @@ export function HelpV2({ onClose, commands }: Props): React.ReactNode {
|
||||
onCancel={close}
|
||||
/>
|
||||
</Tab>,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" height={insideModal ? undefined : maxHeight}>
|
||||
<Pane color="professionalBlue">
|
||||
<Tabs
|
||||
title={
|
||||
process.env.USER_TYPE === 'ant'
|
||||
? '/help'
|
||||
: `Claude Code v${MACRO.VERSION}`
|
||||
}
|
||||
title={process.env.USER_TYPE === 'ant' ? '/help' : `Claude Code v${MACRO.VERSION}`}
|
||||
color="professionalBlue"
|
||||
defaultTab="general"
|
||||
>
|
||||
@@ -117,8 +102,7 @@ export function HelpV2({ onClose, commands }: Props): React.ReactNode {
|
||||
</Tabs>
|
||||
<Box marginTop={1}>
|
||||
<Text>
|
||||
For more help:{' '}
|
||||
<Link url="https://code.claude.com/docs/en/overview" />
|
||||
For more help: <Link url="https://code.claude.com/docs/en/overview" />
|
||||
</Text>
|
||||
</Box>
|
||||
<Box marginTop={1}>
|
||||
@@ -132,5 +116,5 @@ export function HelpV2({ onClose, commands }: Props): React.ReactNode {
|
||||
</Box>
|
||||
</Pane>
|
||||
</Box>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user