Skip to content

fix: iTerm2 cursor blinking issue - #287

Merged
kommander merged 1 commit into
anomalyco:mainfrom
istarkov:fix-iterm
Nov 10, 2025
Merged

kommander merged 1 commit into
anomalyco:mainfrom
istarkov:fix-iterm

Conversation

@istarkov

@istarkov istarkov commented Nov 9, 2025 •

Copy link
Copy Markdown
Contributor

Closes anomalyco/opencode#3780

This can be fixed either by enabling a checkbox in iTerm2 (see anomalyco/opencode#3780 (comment)) or by merging this PR, which prevents showing the cursor ANSI code on every render.

To reproduce, run the following in iTerm2:

import { render } from "./index"
import { createEffect, createSignal, onCleanup } from "solid-js"

function ScrollFail() {
  const [increasingText, setIncreasingText] = createSignal("Build")

  createEffect(() => {
    const interval = setInterval(() => {
      setIncreasingText((v) => (v.length > 10 ? "" : v + "a"))
    }, 10)

    onCleanup(() => {
      clearInterval(interval)
    })
  })

  return (
    <box flexDirection="column" gap={1}>
      <box flexShrink={0}>
        <text>{increasingText()}</text>
      </box>
      <box flexShrink={0} borderStyle="single" borderColor={"#f0f"}>
        <textarea
          onMouseDown={(r: MouseEvent) => r.target?.focus()}
          cursorColor={"#00f"}
          focusedBackgroundColor={"#eee"}
          minHeight={2}
          maxHeight={6}
        />
      </box>
    </box>
  )
}

render(() => <ScrollFail />)

Before PR

Screen Recording 2025-11-09 at 23 39 12

After PR

Screen Recording 2025-11-09 at 23 40 35

This is a really annoying issue in iTerm2.

On Mac, I've also tested this with WezTerm and VS Code Terminal. There is no issue on either, and I've verified that the PR works on both.

In iTerm2, I've also tested that the blinking cursor still works correctly.

@istarkov
istarkov requested a review from kommander as a code owner November 9, 2025 16:47
@istarkov istarkov changed the title Fix iTerm2 cursor blinking issue fix: iTerm2 cursor blinking issue Nov 9, 2025
@kommander

kommander commented Nov 9, 2025 •

Copy link
Copy Markdown
Collaborator

Thanks! I see the issue. Problem here is that not hiding the cursor for a frame will make it flicker across the screen for other terminals. I want to use Private Mode 2026, which is supported by iTerm2 as well and would alleviate the flickering.

writer.writeAll(ansi.ANSI.syncSet) // "\x1b[?2026h"
// and
writer.writeAll(ansi.ANSI.syncReset) // "\x1b[?2026l"

I agree however that setting the cursor color and style when it did not change for every frame should be avoided.

@istarkov

istarkov commented Nov 10, 2025 •

Copy link
Copy Markdown
Contributor Author

I've restored the hide cursor functionality and it still works well in iTerm2. It seems the actual issue was the color change. This would probably be better to add before entering private mode.

if (styleChanged) { also can be reverted as seems like has no effect too.

if (colorChanged) { is the real fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opentui: Rapid blinking in iTerm2

2 participants