| 1 | import { Box, Text } from "ink"; |
| 2 | import React, { useEffect, useState } from "react"; |
| 3 | |
| 4 | import { setExitMessageCallback, shouldShowExitMessage } from "../../index.js"; |
| 5 | import type { PermissionMode } from "../../permissions/types.js"; |
| 6 | import type { NavigationScreen } from "../context/NavigationContext.js"; |
| 7 | import { FreeTrialStatus } from "../FreeTrialStatus.js"; |
| 8 | import { UpdateNotification } from "../UpdateNotification.js"; |
| 9 | |
| 10 | import { ContextPercentageDisplay } from "./ContextPercentageDisplay.js"; |
| 11 | import { ModeIndicator } from "./ModeIndicator.js"; |
| 12 | import { ResponsiveRepoDisplay } from "./ResponsiveRepoDisplay.js"; |
| 13 | |
| 14 | export interface BottomStatusBarProps { |
| 15 | currentMode: PermissionMode; |
| 16 | remoteUrl?: string; |
| 17 | isRemoteMode: boolean; |
| 18 | services: any; |
| 19 | navState: any; |
| 20 | navigateTo: (screen: NavigationScreen, data?: any) => void; |
| 21 | closeCurrentScreen: () => void; |
| 22 | contextPercentage?: number; |
| 23 | hasImageInClipboard?: boolean; |
| 24 | } |
| 25 | |
| 26 | export const BottomStatusBar: React.FC<BottomStatusBarProps> = ({ |
| 27 | currentMode, |
| 28 | remoteUrl, |
| 29 | isRemoteMode, |
| 30 | services, |
| 31 | navState, |
| 32 | navigateTo, |
| 33 | closeCurrentScreen, |
| 34 | contextPercentage, |
| 35 | hasImageInClipboard, |
| 36 | }) => { |
| 37 | const [_refreshTrigger, setRefreshTrigger] = useState(0); |
| 38 | |
| 39 | useEffect(() => { |
| 40 | setExitMessageCallback(() => { |
| 41 | setRefreshTrigger((prev) => prev + 1); |
| 42 | }); |
| 43 | }, []); |
| 44 | |
| 45 | const showingExitMessage = shouldShowExitMessage(); |
| 46 | |
| 47 | return ( |
| 48 | <Box flexDirection="row" justifyContent="space-between" alignItems="center"> |
| 49 | <Box marginLeft={2} flexDirection="row" alignItems="center"> |
| 50 | {currentMode === "normal" && ( |
| 51 | <React.Fragment> |
| 52 | {hasImageInClipboard ? ( |
| 53 | <Text key="image-paste-hint" color="cyan" wrap="truncate-start"> |
| 54 | Press Ctrl+V to paste image |
| 55 | </Text> |
| 56 | ) : showingExitMessage ? ( |
| 57 | <Text key="repo-url" color="dim" wrap="truncate-start"> |
| 58 | {"ctrl+c to exit"} |
| 59 | </Text> |
| 60 | ) : ( |
| 61 | <ResponsiveRepoDisplay remoteUrl={remoteUrl} /> |
| 62 | )} |
| 63 | <Text key="repo-separator"> </Text> |
| 64 | </React.Fragment> |
| 65 | )} |
| 66 | <ModeIndicator /> |
| 67 | {contextPercentage !== undefined && contextPercentage > 75 && ( |
| 68 | <React.Fragment> |
| 69 | <Text key="context-separator" color="dim"> |
| 70 | {" "} |
| 71 | •{" "} |
| 72 | </Text> |
| 73 | <ContextPercentageDisplay percentage={contextPercentage} /> |
| 74 | </React.Fragment> |
| 75 | )} |
| 76 | </Box> |
| 77 | <Box> |
| 78 | {!isRemoteMode && services.model?.model && ( |
| 79 | <FreeTrialStatus |
| 80 | apiClient={services.apiClient?.apiClient || undefined} |
| 81 | model={services.model.model} |
| 82 | onTransitionStateChange={(shouldShow) => { |
| 83 | if (shouldShow && navState.currentScreen === "chat") { |
| 84 | navigateTo("free-trial"); |
| 85 | } else if ( |
| 86 | !shouldShow && |
| 87 | navState.currentScreen === "free-trial" |
| 88 | ) { |
| 89 | closeCurrentScreen(); |
| 90 | } |
| 91 | }} |
| 92 | /> |
| 93 | )} |
| 94 | </Box> |
| 95 | <Box marginRight={2} marginLeft={2}> |
| 96 | <UpdateNotification isRemoteMode={isRemoteMode} /> |
| 97 | </Box> |
| 98 | </Box> |
| 99 | ); |
| 100 | }; |