2025-09-26 21:27:00 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type React from 'react';
|
|
|
|
|
import { Box } from 'ink';
|
|
|
|
|
import { Notifications } from '../components/Notifications.js';
|
|
|
|
|
import { MainContent } from '../components/MainContent.js';
|
|
|
|
|
import { DialogManager } from '../components/DialogManager.js';
|
|
|
|
|
import { Composer } from '../components/Composer.js';
|
|
|
|
|
import { ExitWarning } from '../components/ExitWarning.js';
|
|
|
|
|
import { useUIState } from '../contexts/UIStateContext.js';
|
2025-10-10 13:18:38 -07:00
|
|
|
import { useFlickerDetector } from '../hooks/useFlickerDetector.js';
|
2025-11-11 07:50:11 -08:00
|
|
|
import { useAlternateBuffer } from '../hooks/useAlternateBuffer.js';
|
|
|
|
|
import { CopyModeWarning } from '../components/CopyModeWarning.js';
|
2026-01-30 09:53:09 -08:00
|
|
|
import { BackgroundShellDisplay } from '../components/BackgroundShellDisplay.js';
|
|
|
|
|
import { StreamingState } from '../types.js';
|
2025-09-26 21:27:00 -04:00
|
|
|
|
2025-10-01 14:50:33 -07:00
|
|
|
export const DefaultAppLayout: React.FC = () => {
|
2025-09-26 21:27:00 -04:00
|
|
|
const uiState = useUIState();
|
2025-11-11 07:50:11 -08:00
|
|
|
const isAlternateBuffer = useAlternateBuffer();
|
|
|
|
|
|
2025-10-10 13:18:38 -07:00
|
|
|
const { rootUiRef, terminalHeight } = uiState;
|
|
|
|
|
useFlickerDetector(rootUiRef, terminalHeight);
|
2025-11-11 07:50:11 -08:00
|
|
|
// If in alternate buffer mode, need to leave room to draw the scrollbar on
|
|
|
|
|
// the right side of the terminal.
|
2025-09-26 21:27:00 -04:00
|
|
|
return (
|
2025-10-10 13:18:38 -07:00
|
|
|
<Box
|
|
|
|
|
flexDirection="column"
|
2026-01-26 15:23:54 -08:00
|
|
|
width={uiState.terminalWidth}
|
2026-01-23 07:21:55 +08:00
|
|
|
height={isAlternateBuffer ? terminalHeight : undefined}
|
|
|
|
|
paddingBottom={isAlternateBuffer ? 1 : undefined}
|
2025-11-04 16:21:00 -08:00
|
|
|
flexShrink={0}
|
|
|
|
|
flexGrow={0}
|
|
|
|
|
overflow="hidden"
|
2025-11-11 07:50:11 -08:00
|
|
|
ref={uiState.rootUiRef}
|
2025-10-10 13:18:38 -07:00
|
|
|
>
|
2025-09-26 21:27:00 -04:00
|
|
|
<MainContent />
|
|
|
|
|
|
2026-01-30 09:53:09 -08:00
|
|
|
{uiState.isBackgroundShellVisible &&
|
|
|
|
|
uiState.backgroundShells.size > 0 &&
|
|
|
|
|
uiState.activeBackgroundShellPid &&
|
|
|
|
|
uiState.backgroundShellHeight > 0 &&
|
|
|
|
|
uiState.streamingState !== StreamingState.WaitingForConfirmation && (
|
|
|
|
|
<Box height={uiState.backgroundShellHeight} flexShrink={0}>
|
|
|
|
|
<BackgroundShellDisplay
|
|
|
|
|
shells={uiState.backgroundShells}
|
|
|
|
|
activePid={uiState.activeBackgroundShellPid}
|
|
|
|
|
width={uiState.terminalWidth}
|
|
|
|
|
height={uiState.backgroundShellHeight}
|
|
|
|
|
isFocused={
|
|
|
|
|
uiState.embeddedShellFocused && !uiState.dialogsVisible
|
|
|
|
|
}
|
|
|
|
|
isListOpenProp={uiState.isBackgroundShellListOpen}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2025-11-11 07:50:11 -08:00
|
|
|
<Box
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
ref={uiState.mainControlsRef}
|
|
|
|
|
flexShrink={0}
|
|
|
|
|
flexGrow={0}
|
2026-01-26 15:23:54 -08:00
|
|
|
width={uiState.terminalWidth}
|
2025-11-11 07:50:11 -08:00
|
|
|
>
|
2025-09-26 21:27:00 -04:00
|
|
|
<Notifications />
|
2025-11-11 07:50:11 -08:00
|
|
|
<CopyModeWarning />
|
2025-09-26 21:27:00 -04:00
|
|
|
|
2025-11-14 19:06:30 -08:00
|
|
|
{uiState.customDialog ? (
|
|
|
|
|
uiState.customDialog
|
|
|
|
|
) : uiState.dialogsVisible ? (
|
2025-09-29 14:19:19 -07:00
|
|
|
<DialogManager
|
2026-01-26 15:23:54 -08:00
|
|
|
terminalWidth={uiState.terminalWidth}
|
2025-09-29 14:19:19 -07:00
|
|
|
addItem={uiState.historyManager.addItem}
|
|
|
|
|
/>
|
2025-09-26 21:27:00 -04:00
|
|
|
) : (
|
2026-01-27 16:06:24 -08:00
|
|
|
<Composer isFocused={true} />
|
2025-09-26 21:27:00 -04:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<ExitWarning />
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|