这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vibe-kit/grok-cli",
"version": "0.0.19",
"version": "0.0.20",
"description": "An open-source AI agent that brings the power of Grok directly into your terminal.",
"main": "dist/index.js",
"bin": {
Expand Down
40 changes: 33 additions & 7 deletions src/hooks/use-input-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function useInputHandler({
isConfirmationActive = false,
}: UseInputHandlerProps) {
const [input, setInput] = useState("");
const [cursorPosition, setCursorPosition] = useState(0);
const [showCommandSuggestions, setShowCommandSuggestions] = useState(false);
const [selectedCommandIndex, setSelectedCommandIndex] = useState(0);
const [showModelSelection, setShowModelSelection] = useState(false);
Expand Down Expand Up @@ -86,6 +87,7 @@ export function useInputHandler({
confirmationService.resetSession();

setInput("");
setCursorPosition(0);
return true;
}

Expand Down Expand Up @@ -127,6 +129,7 @@ Examples:
};
setChatHistory((prev) => [...prev, helpEntry]);
setInput("");
setCursorPosition(0);
return true;
}

Expand All @@ -139,6 +142,7 @@ Examples:
setShowModelSelection(true);
setSelectedModelIndex(0);
setInput("");
setCursorPosition(0);
return true;
}

Expand Down Expand Up @@ -167,6 +171,7 @@ Available models: ${modelNames.join(", ")}`,
}

setInput("");
setCursorPosition(0);
return true;
}

Expand Down Expand Up @@ -371,6 +376,7 @@ Respond with ONLY the commit message, no additional text.`;
setIsProcessing(false);
setIsStreaming(false);
setInput("");
setCursorPosition(0);
return true;
}

Expand Down Expand Up @@ -428,6 +434,7 @@ Respond with ONLY the commit message, no additional text.`;
}

setInput("");
setCursorPosition(0);
return true;
}

Expand All @@ -444,6 +451,7 @@ Respond with ONLY the commit message, no additional text.`;

setIsProcessing(true);
setInput("");
setCursorPosition(0);

try {
setIsStreaming(true);
Expand Down Expand Up @@ -642,7 +650,9 @@ Respond with ONLY the commit message, no additional text.`;
filteredSuggestions.length - 1
);
const selectedCommand = filteredSuggestions[safeIndex];
setInput(selectedCommand.command + " ");
const newInput = selectedCommand.command + " ";
setInput(newInput);
setCursorPosition(newInput.length);
setShowCommandSuggestions(false);
setSelectedCommandIndex(0);
return;
Expand Down Expand Up @@ -693,20 +703,35 @@ Respond with ONLY the commit message, no additional text.`;
return;
}

// Handle left and right arrow keys for cursor movement
if (key.leftArrow && !showCommandSuggestions && !showModelSelection) {
setCursorPosition(prev => Math.max(0, prev - 1));
return;
}

if (key.rightArrow && !showCommandSuggestions && !showModelSelection) {
setCursorPosition(prev => Math.min(input.length, prev + 1));
return;
}

if (key.backspace || key.delete) {
const newInput = input.slice(0, -1);
setInput(newInput);
if (cursorPosition > 0) {
const newInput = input.slice(0, cursorPosition - 1) + input.slice(cursorPosition);
setInput(newInput);
setCursorPosition(prev => prev - 1);

if (!newInput.startsWith("/")) {
setShowCommandSuggestions(false);
setSelectedCommandIndex(0);
if (!newInput.startsWith("/")) {
setShowCommandSuggestions(false);
setSelectedCommandIndex(0);
}
}
return;
}

if (inputChar && !key.ctrl && !key.meta) {
const newInput = input + inputChar;
const newInput = input.slice(0, cursorPosition) + inputChar + input.slice(cursorPosition);
setInput(newInput);
setCursorPosition(prev => prev + 1);

if (newInput.startsWith("/")) {
setShowCommandSuggestions(true);
Expand All @@ -720,6 +745,7 @@ Respond with ONLY the commit message, no additional text.`;

return {
input,
cursorPosition,
showCommandSuggestions,
selectedCommandIndex,
showModelSelection,
Expand Down
8 changes: 7 additions & 1 deletion src/ui/components/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ import { Box, Text } from "ink";

interface ChatInputProps {
input: string;
cursorPosition: number;
isProcessing: boolean;
isStreaming: boolean;
}

export function ChatInput({
input,
cursorPosition,
isProcessing,
isStreaming,
}: ChatInputProps) {
const beforeCursor = input.slice(0, cursorPosition);
const afterCursor = input.slice(cursorPosition);

return (
<Box borderStyle="round" borderColor="gray" paddingX={1} marginTop={1}>
<Text color="gray">❯ </Text>
<Text>
{input}
{beforeCursor}
{!isProcessing && !isStreaming && <Text color="white">█</Text>}
{afterCursor}
</Text>
</Box>
);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/components/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function ChatInterfaceWithAgent({ agent }: { agent: GrokAgent }) {

const {
input,
cursorPosition,
showCommandSuggestions,
selectedCommandIndex,
showModelSelection,
Expand Down Expand Up @@ -210,6 +211,7 @@ function ChatInterfaceWithAgent({ agent }: { agent: GrokAgent }) {

<ChatInput
input={input}
cursorPosition={cursorPosition}
isProcessing={isProcessing}
isStreaming={isStreaming}
/>
Expand Down
Loading