@@ -140,21 +140,22 @@ func findUserInputEndIdx(userInputStartIdx int, msg []rune, userInput []rune) in
140140 return msgIdx
141141}
142142
143- // skipTrailingInputBoxLine skips the next line if it contains any of the markers.
144- // In case of Gemini and Cursor, the user input is echoed back in a box
145- // This function searches for the markers passed by the caller and skips the next line
146- // if it contains all of them in the same order.
147- func skipTrailingInputBoxLine (lines []string , lastUserInputLineIdx * int , markers ... string ) {
148- if * lastUserInputLineIdx + 1 >= len (lines ) {
149- return
143+ // skipTrailingInputBoxLine checks if the next line contains all the given markers
144+ // and returns the incremented index if found. In case of Gemini and Cursor, the user
145+ // input is echoed back in a box. This function searches for the markers passed by the
146+ // caller and returns (currentIdx+1, true) if the next line contains all of them in the same order,
147+ // otherwise returns (currentIdx, false).
148+ func skipTrailingInputBoxLine (lines []string , currentIdx int , markers ... string ) (idx int , found bool ) {
149+ if currentIdx + 1 >= len (lines ) {
150+ return currentIdx , false
150151 }
151- line := lines [* lastUserInputLineIdx + 1 ]
152+ line := lines [currentIdx + 1 ]
152153 for _ , m := range markers {
153154 if ! strings .Contains (line , m ) {
154- return
155+ return currentIdx , false
155156 }
156157 }
157- * lastUserInputLineIdx ++
158+ return currentIdx + 1 , true
158159}
159160
160161// RemoveUserInput removes the user input from the message.
@@ -186,8 +187,15 @@ func RemoveUserInput(msgRaw string, userInputRaw string) string {
186187 // that doesn't contain the echoed user input.
187188 lastUserInputLineIdx := msgRuneLineLocations [userInputEndIdx ]
188189
189- skipTrailingInputBoxLine (msgLines , & lastUserInputLineIdx , "╯" , "╰" ) // Gemini
190- skipTrailingInputBoxLine (msgLines , & lastUserInputLineIdx , "┘" , "└" ) // Cursor
190+ // Skip Gemini trailing input box line
191+ if idx , found := skipTrailingInputBoxLine (msgLines , lastUserInputLineIdx , "╯" , "╰" ); found {
192+ lastUserInputLineIdx = idx
193+ }
194+
195+ // Skip Cursor trailing input box line
196+ if idx , found := skipTrailingInputBoxLine (msgLines , lastUserInputLineIdx , "┘" , "└" ); found {
197+ lastUserInputLineIdx = idx
198+ }
191199
192200 return strings .Join (msgLines [lastUserInputLineIdx + 1 :], "\n " )
193201}
0 commit comments