diff --git a/src/ui/IntroMessage.tsx b/src/ui/IntroMessage.tsx index 96895e046..7aad51014 100644 --- a/src/ui/IntroMessage.tsx +++ b/src/ui/IntroMessage.tsx @@ -1,6 +1,6 @@ import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; import { Box, Text } from "ink"; -import React from "react"; +import React, { useMemo } from "react"; import { parseArgs } from "../args.js"; import { MCPService } from "../services/MCPService.js"; @@ -19,20 +19,30 @@ const IntroMessage: React.FC = ({ model, mcpService, }) => { + // Get MCP prompts directly (not memoized since they can change after first render) const mcpPrompts = mcpService.getState().prompts ?? []; - // Show all rules in a single section - const args = parseArgs(); - const commandLineRules = args.rules || []; - const configRules = - config.rules?.map((rule: any) => - typeof rule === "string" ? rule : rule?.name || "Unknown", - ) || []; + // Memoize expensive operations to avoid running on every resize + const { allRules, modelCapable } = useMemo(() => { + // Show all rules in a single section + const args = parseArgs(); + const commandLineRules = args.rules || []; + const configRules = + config.rules?.map((rule: any) => + typeof rule === "string" ? rule : rule?.name || "Unknown", + ) || []; - const allRules = [...commandLineRules, ...configRules]; + const allRules = [...commandLineRules, ...configRules]; - // Check if model is capable - now checking both name and model properties - const modelCapable = isModelCapable(model.provider, model.name, model.model); + // Check if model is capable - now checking both name and model properties + const modelCapable = isModelCapable( + model.provider, + model.name, + model.model, + ); + + return { allRules, modelCapable }; + }, [config.rules, model.provider, model.name, model.model]); return ( diff --git a/src/ui/components/StaticChatContent.tsx b/src/ui/components/StaticChatContent.tsx index 8294b81a0..39c23cd4f 100644 --- a/src/ui/components/StaticChatContent.tsx +++ b/src/ui/components/StaticChatContent.tsx @@ -1,6 +1,6 @@ import type { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; -import { Static } from "ink"; -import React from "react"; +import { Static, useStdout } from "ink"; +import React, { useCallback, useEffect, useRef, useState } from "react"; import type { MCPService } from "../../services/MCPService.js"; import { useTerminalSize } from "../hooks/useTerminalSize.js"; @@ -24,55 +24,72 @@ export const StaticChatContent: React.FC = ({ messages, renderMessage, }) => { - const { columns } = useTerminalSize(); - // Create a combined array of items to render + const { columns, rows } = useTerminalSize(); + const { stdout } = useStdout(); + + // State for managing static refresh with key-based remounting (gemini-cli approach) + const [staticKey, setStaticKey] = useState(0); + const isInitialMount = useRef(true); + + // Refresh function that clears terminal and remounts Static component + const refreshStatic = useCallback(() => { + // Clear terminal completely before remounting + stdout.write("\x1b[2J\x1b[H"); + setStaticKey((prev) => prev + 1); + }, [stdout]); + + // Debounced terminal resize handler (300ms like gemini-cli) + useEffect(() => { + // Skip refreshing Static during first mount + if (isInitialMount.current) { + isInitialMount.current = false; + return; + } + + // Debounce so it doesn't fire too often during resize + const handler = setTimeout(() => { + refreshStatic(); + }, 300); + + return () => { + clearTimeout(handler); + }; + }, [columns, rows, refreshStatic]); + + // Create static items array (similar to gemini-cli's approach) const staticItems = React.useMemo(() => { - const items: Array<{ - type: "intro" | "message"; - data: DisplayMessage | null; - index?: number; - }> = []; + const items: React.ReactElement[] = []; // Add intro message as first item if it should be shown if (showIntroMessage && config && model && mcpService) { - items.push({ type: "intro", data: null }); + items.push( + , + ); } // Add all chat messages messages.forEach((message, index) => { - items.push({ type: "message", data: message, index }); + items.push(renderMessage(message, index)); }); return items; - }, [showIntroMessage, config, model, mcpService, messages]); + }, [showIntroMessage, config, model, mcpService, messages, renderMessage]); return ( - {(item) => { - if (item.type === "intro" && config && model && mcpService) { - return ( - - ); - } else if ( - item.type === "message" && - item.data && - item.index !== undefined - ) { - return renderMessage(item.data, item.index); - } - return null; - }} + {(item) => item} ); }; diff --git a/src/ui/hooks/useUserInput.ts b/src/ui/hooks/useUserInput.ts index 5d22fe0fd..ae0dea719 100644 --- a/src/ui/hooks/useUserInput.ts +++ b/src/ui/hooks/useUserInput.ts @@ -21,6 +21,12 @@ export function handleControlKeys(options: ControlKeysOptions): boolean { return true; } + // Handle Ctrl+L to refresh screen (clear terminal artifacts) + if (key.ctrl && input === "l") { + process.stdout.write("\x1b[2J\x1b[H"); + return true; + } + // Handle Shift+Tab to cycle through modes if (key.tab && key.shift && !showSlashCommands && !showFileSearch) { cycleModes().catch((error) => {