2025-05-17 21:25:28 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-05-15 04:11:28 +00:00
|
|
|
import type { FC } from 'react';
|
|
|
|
|
import { useRef } from 'react';
|
2025-05-17 21:25:28 -07:00
|
|
|
import { Box, Text } from 'ink';
|
2025-09-10 10:57:07 -07:00
|
|
|
import { theme } from '../semantic-colors.js';
|
2025-06-25 05:41:11 -07:00
|
|
|
import { ApprovalMode } from '@google/gemini-cli-core';
|
2026-03-09 23:26:33 +00:00
|
|
|
import { formatCommand } from '../key/keybindingUtils.js';
|
|
|
|
|
import { Command } from '../key/keyBindings.js';
|
2026-05-15 04:11:28 +00:00
|
|
|
import { useMouseClick } from '../hooks/useMouseClick.js';
|
|
|
|
|
import { useUIActions } from '../contexts/UIActionsContext.js';
|
|
|
|
|
import { useUIState } from '../contexts/UIStateContext.js';
|
2025-05-17 21:25:28 -07:00
|
|
|
|
2026-01-21 10:19:47 -05:00
|
|
|
interface ApprovalModeIndicatorProps {
|
2025-06-02 22:05:45 +02:00
|
|
|
approvalMode: ApprovalMode;
|
2026-02-17 12:36:59 -05:00
|
|
|
allowPlanMode?: boolean;
|
2025-06-02 22:05:45 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-15 04:11:28 +00:00
|
|
|
export const ApprovalModeIndicator: FC<ApprovalModeIndicatorProps> = ({
|
2025-06-02 22:05:45 +02:00
|
|
|
approvalMode,
|
2026-02-17 12:36:59 -05:00
|
|
|
allowPlanMode,
|
2025-06-02 22:05:45 +02:00
|
|
|
}) => {
|
2026-05-15 04:11:28 +00:00
|
|
|
const { mouseMode } = useUIState();
|
|
|
|
|
const { cycleApprovalMode } = useUIActions();
|
|
|
|
|
const boxRef = useRef(null);
|
|
|
|
|
|
2026-05-15 19:49:16 +00:00
|
|
|
/**
|
|
|
|
|
* Click handler for switching approval modes.
|
|
|
|
|
* See: https://github.com/google-gemini/gemini-cli/issues/27035
|
|
|
|
|
*/
|
2026-05-15 04:11:28 +00:00
|
|
|
useMouseClick(boxRef, () => {
|
|
|
|
|
cycleApprovalMode();
|
|
|
|
|
});
|
|
|
|
|
|
2025-06-02 22:05:45 +02:00
|
|
|
let textColor = '';
|
|
|
|
|
let textContent = '';
|
|
|
|
|
let subText = '';
|
|
|
|
|
|
2026-03-06 18:34:26 +00:00
|
|
|
const cycleHint = formatCommand(Command.CYCLE_APPROVAL_MODE);
|
2026-05-15 04:11:28 +00:00
|
|
|
const clickHint = mouseMode ? 'click or ' : '';
|
2026-03-06 18:34:26 +00:00
|
|
|
const yoloHint = formatCommand(Command.TOGGLE_YOLO);
|
|
|
|
|
|
2025-06-02 22:05:45 +02:00
|
|
|
switch (approvalMode) {
|
|
|
|
|
case ApprovalMode.AUTO_EDIT:
|
2025-09-11 10:34:29 -07:00
|
|
|
textColor = theme.status.warning;
|
2026-03-06 18:34:26 +00:00
|
|
|
textContent = 'auto-accept edits';
|
2026-02-17 12:36:59 -05:00
|
|
|
subText = allowPlanMode
|
2026-05-15 04:11:28 +00:00
|
|
|
? `${clickHint}${cycleHint} to plan`
|
|
|
|
|
: `${clickHint}${cycleHint} to manual`;
|
2026-01-21 10:19:47 -05:00
|
|
|
break;
|
|
|
|
|
case ApprovalMode.PLAN:
|
|
|
|
|
textColor = theme.status.success;
|
2026-03-06 18:34:26 +00:00
|
|
|
textContent = 'plan';
|
2026-05-15 04:11:28 +00:00
|
|
|
subText = `${clickHint}${cycleHint} to manual`;
|
2025-06-02 22:05:45 +02:00
|
|
|
break;
|
|
|
|
|
case ApprovalMode.YOLO:
|
2025-09-10 10:57:07 -07:00
|
|
|
textColor = theme.status.error;
|
2026-03-06 18:34:26 +00:00
|
|
|
textContent = 'YOLO';
|
|
|
|
|
subText = yoloHint;
|
2025-06-02 22:05:45 +02:00
|
|
|
break;
|
|
|
|
|
case ApprovalMode.DEFAULT:
|
|
|
|
|
default:
|
2026-02-06 19:23:59 -05:00
|
|
|
textColor = theme.text.accent;
|
|
|
|
|
textContent = '';
|
2026-05-15 04:11:28 +00:00
|
|
|
subText = `${clickHint}${cycleHint} to accept edits`;
|
2025-06-02 22:05:45 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-05-15 04:11:28 +00:00
|
|
|
<Box ref={boxRef}>
|
2025-06-02 22:05:45 +02:00
|
|
|
<Text color={textColor}>
|
2026-02-06 19:23:59 -05:00
|
|
|
{textContent ? textContent : null}
|
|
|
|
|
{subText ? (
|
|
|
|
|
<Text color={theme.text.secondary}>
|
|
|
|
|
{textContent ? ' ' : ''}
|
|
|
|
|
{subText}
|
|
|
|
|
</Text>
|
|
|
|
|
) : null}
|
2025-06-02 22:05:45 +02:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|