2025-05-17 21:25:28 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
import type React 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';
|
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-01-21 10:19:47 -05:00
|
|
|
export const ApprovalModeIndicator: React.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
|
|
|
}) => {
|
|
|
|
|
let textColor = '';
|
|
|
|
|
let textContent = '';
|
|
|
|
|
let subText = '';
|
|
|
|
|
|
2026-03-06 18:34:26 +00:00
|
|
|
const cycleHint = formatCommand(Command.CYCLE_APPROVAL_MODE);
|
|
|
|
|
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-03-06 18:34:26 +00:00
|
|
|
? `${cycleHint} to plan`
|
|
|
|
|
: `${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';
|
|
|
|
|
subText = `${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-03-06 18:34:26 +00:00
|
|
|
subText = `${cycleHint} to accept edits`;
|
2025-06-02 22:05:45 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box>
|
|
|
|
|
<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>
|
|
|
|
|
);
|
|
|
|
|
};
|