33 * Copyright 2025 Autohand AI LLC
44 * SPDX-License-Identifier: Apache-2.0
55 */
6- import React , { useEffect , useMemo , useRef , useState } from 'react' ;
6+ import React , { useMemo , useRef } from 'react' ;
77import { Box , Text , useCursor , type DOMElement } from 'ink' ;
88import { useTheme } from '../theme/ThemeContext.js' ;
99import { buildMultiLineRenderState } from '../inputPrompt.js' ;
@@ -38,23 +38,6 @@ function getAbsoluteInkPosition(
3838 return { left, top } ;
3939}
4040
41- function renderHardwareCursorFallback ( line : string , cursorColumn : number ) : string {
42- if ( cursorColumn < 0 || cursorColumn >= line . length ) {
43- return line ;
44- }
45-
46- // Some terminals let Ink hide the hardware cursor after redraws, so keep a
47- // visible cursor cell without dropping the character at the cursor offset.
48- const rightBorder = line . slice ( - 1 ) ;
49- const beforeRightBorder = line . slice ( 0 , - 1 ) ;
50- const shiftedContent = beforeRightBorder . slice (
51- cursorColumn ,
52- Math . max ( cursorColumn , beforeRightBorder . length - 1 )
53- ) ;
54-
55- return `${ beforeRightBorder . slice ( 0 , cursorColumn ) } █${ shiftedContent } ${ rightBorder } ` ;
56- }
57-
5841export interface InputLineProps {
5942 value : string ;
6043 cursorOffset : number ;
@@ -84,7 +67,6 @@ function InputLineComponent({
8467 const { theme } = useTheme ( ) ;
8568 const rootRef = useRef < DOMElement > ( null ) ;
8669 const { setCursorPosition } = useCursor ( ) ;
87- const [ cursorVisible , setCursorVisible ] = useState ( true ) ;
8870
8971 const borderToken = borderStyle === 'plan'
9072 ? 'warning'
@@ -120,25 +102,6 @@ function InputLineComponent({
120102 } ;
121103 } , [ value , cursorOffset , width , borderStyle , placeholderText , nextPromptSuggestion , inlineGhostSuffix ] ) ;
122104
123- useEffect ( ( ) => {
124- if ( ! isActive ) {
125- setCursorVisible ( true ) ;
126- return ;
127- }
128-
129- const timer = setInterval ( ( ) => {
130- setCursorVisible ( ( visible ) => ! visible ) ;
131- } , 530 ) ;
132-
133- return ( ) => {
134- clearInterval ( timer ) ;
135- } ;
136- } , [ isActive ] ) ;
137-
138- useEffect ( ( ) => {
139- setCursorVisible ( true ) ;
140- } , [ value , cursorOffset ] ) ;
141-
142105 const cursorPosition = ( ( ) => {
143106 if ( ! isActive ) {
144107 return undefined ;
@@ -153,18 +116,6 @@ function InputLineComponent({
153116
154117 setCursorPosition ( cursorPosition ) ;
155118
156- const renderedLines = useMemo ( ( ) => {
157- if ( ! isActive || ! cursorVisible ) {
158- return displayData . plainLines ;
159- }
160-
161- return displayData . plainLines . map ( ( line , index ) => (
162- index === displayData . cursorRow
163- ? renderHardwareCursorFallback ( line , displayData . cursorColumn )
164- : line
165- ) ) ;
166- } , [ cursorVisible , displayData . cursorColumn , displayData . cursorRow , displayData . plainLines , isActive ] ) ;
167-
168119 const renderContentLine = ( line : string , index : number ) => {
169120 return (
170121 < Text key = { index } >
@@ -186,7 +137,7 @@ function InputLineComponent({
186137 return (
187138 < Box ref = { rootRef } flexDirection = "column" >
188139 < Text > { theme . fgBg ( borderToken , 'userMessageBg' , borders . top ) } </ Text >
189- { renderedLines . map ( renderContentLine ) }
140+ { displayData . plainLines . map ( renderContentLine ) }
190141 < Text > { theme . fgBg ( borderToken , 'userMessageBg' , borders . bottom ) } </ Text >
191142 </ Box >
192143 ) ;
0 commit comments