summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/shared/text-buffer.ts
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-08-21 16:43:56 -0700
committerGitHub <[email protected]>2025-08-21 23:43:56 +0000
commit29699274bb0e8f70b9bedad40ca2d03739318853 (patch)
tree17ff82d54991e72deba93eb40e4b7d068b881cb5 /packages/cli/src/ui/components/shared/text-buffer.ts
parent10286934e6a549dcad557adecfc087552e13c983 (diff)
feat(settings) support editing string settings. (#6732)
Diffstat (limited to 'packages/cli/src/ui/components/shared/text-buffer.ts')
-rw-r--r--packages/cli/src/ui/components/shared/text-buffer.ts54
1 files changed, 6 insertions, 48 deletions
diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts
index 93f6e360..389a4799 100644
--- a/packages/cli/src/ui/components/shared/text-buffer.ts
+++ b/packages/cli/src/ui/components/shared/text-buffer.ts
@@ -4,8 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import stripAnsi from 'strip-ansi';
-import { stripVTControlCharacters } from 'util';
import { spawnSync } from 'child_process';
import fs from 'fs';
import os from 'os';
@@ -13,7 +11,12 @@ import pathMod from 'path';
import { useState, useCallback, useEffect, useMemo, useReducer } from 'react';
import stringWidth from 'string-width';
import { unescapePath } from '@google/gemini-cli-core';
-import { toCodePoints, cpLen, cpSlice } from '../../utils/textUtils.js';
+import {
+ toCodePoints,
+ cpLen,
+ cpSlice,
+ stripUnsafeCharacters,
+} from '../../utils/textUtils.js';
import { handleVimAction, VimAction } from './vim-buffer-actions.js';
export type Direction =
@@ -494,51 +497,6 @@ export const replaceRangeInternal = (
};
};
-/**
- * Strip characters that can break terminal rendering.
- *
- * Uses Node.js built-in stripVTControlCharacters to handle VT sequences,
- * then filters remaining control characters that can disrupt display.
- *
- * Characters stripped:
- * - ANSI escape sequences (via strip-ansi)
- * - VT control sequences (via Node.js util.stripVTControlCharacters)
- * - C0 control chars (0x00-0x1F) except CR/LF which are handled elsewhere
- * - C1 control chars (0x80-0x9F) that can cause display issues
- *
- * Characters preserved:
- * - All printable Unicode including emojis
- * - DEL (0x7F) - handled functionally by applyOperations, not a display issue
- * - CR/LF (0x0D/0x0A) - needed for line breaks
- */
-function stripUnsafeCharacters(str: string): string {
- const strippedAnsi = stripAnsi(str);
- const strippedVT = stripVTControlCharacters(strippedAnsi);
-
- return toCodePoints(strippedVT)
- .filter((char) => {
- const code = char.codePointAt(0);
- if (code === undefined) return false;
-
- // Preserve CR/LF for line handling
- if (code === 0x0a || code === 0x0d) return true;
-
- // Remove C0 control chars (except CR/LF) that can break display
- // Examples: BELL(0x07) makes noise, BS(0x08) moves cursor, VT(0x0B), FF(0x0C)
- if (code >= 0x00 && code <= 0x1f) return false;
-
- // Remove C1 control chars (0x80-0x9F) - legacy 8-bit control codes
- if (code >= 0x80 && code <= 0x9f) return false;
-
- // Preserve DEL (0x7F) - it's handled functionally by applyOperations as backspace
- // and doesn't cause rendering issues when displayed
-
- // Preserve all other characters including Unicode/emojis
- return true;
- })
- .join('');
-}
-
export interface Viewport {
height: number;
width: number;