mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 08:31:14 -07:00
39 lines
981 B
TypeScript
39 lines
981 B
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { useEffect } from 'react';
|
|
import { writeToStdout } from '@google/gemini-cli-core';
|
|
|
|
const ENABLE_BRACKETED_PASTE = '\x1b[?2004h';
|
|
const DISABLE_BRACKETED_PASTE = '\x1b[?2004l';
|
|
|
|
/**
|
|
* Enables and disables bracketed paste mode in the terminal.
|
|
*
|
|
* This hook ensures that bracketed paste mode is enabled when the component
|
|
* mounts and disabled when it unmounts or when the process exits.
|
|
*/
|
|
export const useBracketedPaste = () => {
|
|
const cleanup = () => {
|
|
writeToStdout(DISABLE_BRACKETED_PASTE);
|
|
};
|
|
|
|
useEffect(() => {
|
|
writeToStdout(ENABLE_BRACKETED_PASTE);
|
|
|
|
process.on('exit', cleanup);
|
|
process.on('SIGINT', cleanup);
|
|
process.on('SIGTERM', cleanup);
|
|
|
|
return () => {
|
|
cleanup();
|
|
process.removeListener('exit', cleanup);
|
|
process.removeListener('SIGINT', cleanup);
|
|
process.removeListener('SIGTERM', cleanup);
|
|
};
|
|
}, []);
|
|
};
|