MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / TextInput

Function TextInput

source code/components/TextInput.tsx:39–125  ·  view source on GitHub ↗
(props: Props)

Source from the content-addressed store, hash-verified

37 highlights?: TextHighlight[];
38};
39export default function TextInput(props: Props): React.ReactNode {
40 const [theme] = useTheme();
41 const isTerminalFocused = useTerminalFocus();
42 // Hoisted to mount-time — this component re-renders on every keystroke.
43 const accessibilityEnabled = useMemo(() => isEnvTruthy(process.env.CLAUDE_CODE_ACCESSIBILITY), []);
44 const settings = useSettings();
45 const reducedMotion = settings.prefersReducedMotion ?? false;
46 const voiceState = feature('VOICE_MODE') ?
47 // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
48 useVoiceState(s => s.voiceState) : 'idle' as const;
49 const isVoiceRecording = voiceState === 'recording';
50 const audioLevels = feature('VOICE_MODE') ?
51 // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
52 useVoiceState(s_0 => s_0.voiceAudioLevels) : [];
53 const smoothedRef = useRef<number[]>(new Array(CURSOR_WAVEFORM_WIDTH).fill(0));
54 const needsAnimation = isVoiceRecording && !reducedMotion;
55 const [animRef, animTime] = feature('VOICE_MODE') ?
56 // biome-ignore lint/correctness/useHookAtTopLevel: feature() is a compile-time constant
57 useAnimationFrame(needsAnimation ? 50 : null) : [() => {}, 0];
58
59 // Show hint when terminal regains focus and clipboard has an image
60 useClipboardImageHint(isTerminalFocused, !!props.onImagePaste);
61
62 // Cursor invert function: mini waveform during voice recording,
63 // standard chalk.inverse otherwise. No warmup pulse — the ~120ms
64 // warmup window is too short for a 1s-period pulse to register, and
65 // driving TextInput re-renders at 50ms during warmup (while spaces
66 // are simultaneously arriving every 30-80ms) causes visible stutter.
67 const canShowCursor = isTerminalFocused && !accessibilityEnabled;
68 let invert: (text: string) => string;
69 if (!canShowCursor) {
70 invert = (text: string) => text;
71 } else if (isVoiceRecording && !reducedMotion) {
72 // Single-bar waveform from the latest audio level
73 const smoothed = smoothedRef.current;
74 const raw = audioLevels.length > 0 ? audioLevels[audioLevels.length - 1] ?? 0 : 0;
75 const target = Math.min(raw * LEVEL_BOOST, 1);
76 smoothed[0] = (smoothed[0] ?? 0) * SMOOTH + target * (1 - SMOOTH);
77 const displayLevel = smoothed[0] ?? 0;
78 const barIndex = Math.max(1, Math.min(Math.round(displayLevel * (BARS.length - 1)), BARS.length - 1));
79 const isSilent = raw < SILENCE_THRESHOLD;
80 const hue = animTime / 1000 * 90 % 360;
81 const {
82 r,
83 g,
84 b
85 } = isSilent ? {
86 r: 128,
87 g: 128,
88 b: 128
89 } : hueToRgb(hue);
90 invert = () => chalk.rgb(r, g, b)(BARS[barIndex]!);
91 } else {
92 invert = chalk.inverse;
93 }
94 const textInputState = useTextInput({
95 value: props.value,
96 onChange: props.onChange,

Callers

nothing calls this directly

Calls 11

useThemeFunction · 0.85
useTerminalFocusFunction · 0.85
isEnvTruthyFunction · 0.85
useSettingsFunction · 0.85
useVoiceStateFunction · 0.85
useAnimationFrameFunction · 0.85
useClipboardImageHintFunction · 0.85
hueToRgbFunction · 0.85
useTextInputFunction · 0.85
colorFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected