MCPcopy Create free account
hub / github.com/Noumena-Network/code / TextInput

Function TextInput

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

Callers

nothing calls this directly

Calls 12

isEnvTruthyFunction · 0.90
recordRenderTraceFunction · 0.85
useThemeFunction · 0.85
useTerminalFocusRefFunction · 0.85
useSettingsFunction · 0.85
useVoiceStateFunction · 0.85
useAnimationFrameFunction · 0.85
hueToRgbFunction · 0.85
useTextInputFunction · 0.85
colorFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected