Skip to content

Commit 267aa5e

Browse files
committed
fix: terminal cursor stuff
1 parent 1c4c140 commit 267aa5e

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

npm-app/src/cli-handlers/chat.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { green, yellow, cyan, bold, gray, blue, red, magenta } from 'picocolors'
1+
import { green, yellow, cyan, bold, gray, blue } from 'picocolors'
22
import stringWidth from 'string-width'
33
import wrapAnsi from 'wrap-ansi'
44

5+
import { logger } from '../utils/logger'
56
import {
67
ENTER_ALT_BUFFER,
78
EXIT_ALT_BUFFER,
89
CLEAR_SCREEN,
9-
HIDE_CURSOR,
1010
SHOW_CURSOR,
1111
MOVE_CURSOR,
12-
SET_CURSOR_STEADY_BAR,
1312
SET_CURSOR_DEFAULT,
1413
DISABLE_CURSOR_BLINK,
14+
CURSOR_SET_INVISIBLE_BLOCK,
1515
} from '../utils/terminal'
16-
import { logger } from '../utils/logger'
1716

1817
// Constants
1918
const SIDE_PADDING = 2
@@ -182,18 +181,21 @@ function resetChatState(): void {
182181
}
183182

184183
function setupRealCursor(): void {
185-
// Set the real cursor to steady bar style and disable blinking
186-
// This is the actual cursor that shows where typing will occur
187-
process.stdout.write(SET_CURSOR_STEADY_BAR)
184+
// Hide cursor using invisible block style
185+
process.stdout.write(CURSOR_SET_INVISIBLE_BLOCK)
186+
187+
// Disable cursor blinking for better invisibility
188188
process.stdout.write(DISABLE_CURSOR_BLINK)
189189
}
190190

191191
function restoreDefaultRealCursor(): void {
192-
// Restore the real cursor to default style
192+
// Restore cursor to default style and visibility
193193
process.stdout.write(SET_CURSOR_DEFAULT)
194194
}
195195

196196
function positionRealCursor(): void {
197+
// Position cursor at the input area where typing occurs
198+
// Cursor hiding is handled separately in setupRealCursor()
197199
const metrics = getTerminalMetrics()
198200
const inputAreaHeight = calculateInputAreaHeight(metrics)
199201

@@ -227,9 +229,6 @@ function positionRealCursor(): void {
227229

228230
process.stdout.write(MOVE_CURSOR(cursorRow, cursorCol))
229231
}
230-
231-
// Show the real cursor
232-
process.stdout.write(SHOW_CURSOR)
233232
}
234233

235234
export function isInChatMode(): boolean {
@@ -404,14 +403,6 @@ function updateContentLines() {
404403
}
405404
})
406405

407-
// Add fake visual cursor indicator for assistant messages that are currently streaming
408-
// This is NOT the real cursor - it's a visual character (▊) to show streaming status
409-
if (message.isStreaming && message.role === 'assistant') {
410-
const indentSize = stringWidth(prefix)
411-
const fakeVisualCursor = ' '.repeat(indentSize) + gray('▊')
412-
lines.push(' '.repeat(metrics.sidePadding) + fakeVisualCursor)
413-
}
414-
415406
if (index < chatState.messages.length - 1) {
416407
lines.push('') // Add spacing between messages
417408
}

npm-app/src/utils/terminal.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ export const SHOW_CURSOR = '\x1b[?25h'
1414
export const MOVE_CURSOR = (row: number, col: number) => `\x1b[${row};${col}H`
1515

1616
// Cursor style control (DECSCUSR)
17-
export const SET_CURSOR_STEADY_BLOCK = '\x1b[2 q'
18-
export const SET_CURSOR_STEADY_BAR = '\x1b[6 q'
1917
export const SET_CURSOR_DEFAULT = '\x1b[0 q'
2018

2119
// Disable cursor blinking (DEC Private Mode 12)
2220
export const DISABLE_CURSOR_BLINK = '\x1b[?12l'
23-
export const ENABLE_CURSOR_BLINK = '\x1b[?12h'
2421

2522
// Alternative cursor control sequences (used in spinner)
2623
export const HIDE_CURSOR_ALT = '\u001B[?25l'
2724
export const SHOW_CURSOR_ALT = '\u001B[?25h'
2825

26+
// Invisible cursor style
27+
export const CURSOR_SET_INVISIBLE_BLOCK = '\x1b[0 q' // Invisible block
28+
2929
// Terminal control utilities
3030
export const TerminalControl = {
3131
enterAltBuffer: () => process.stdout.write(ENTER_ALT_BUFFER),

0 commit comments

Comments
 (0)