From b5f856e1e2212a3d9daa2bdbba7fa24351f1f55e Mon Sep 17 00:00:00 2001 From: Richard <102428955+richardharnisch@users.noreply.github.com> Date: Sat, 31 Oct 2026 22:42:12 +0100 Subject: [PATCH] fix(tui): hide terminal cursor behind toast notifications (#60249) Co-authored-by: Daniel Smolsky --- packages/tui/src/ui/toast.tsx | 8 ++++ packages/tui/test/cli/tui/toast.test.tsx | 49 +++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/packages/tui/src/ui/toast.tsx b/packages/tui/src/ui/toast.tsx index 8f44284c2fa..572da06af57 100644 --- a/packages/tui/src/ui/toast.tsx +++ b/packages/tui/src/ui/toast.tsx @@ -54,6 +54,14 @@ function ToastSurface(props: { borderColor={theme.text.feedback[props.toast.variant].base} border={["left", "right"]} customBorderChars={SplitBorder.customBorderChars} + renderAfter={function () { + // The host terminal draws its cursor above TUI cells, regardless of paint order. + const cursor = renderer.getCursorState() + const x = cursor.x - 1 + const y = cursor.y - 1 + if (!cursor.visible || x < this.x || x >= this.x + this.width || y < this.y || y >= this.y + this.height) return + renderer.setCursorPosition(cursor.x, cursor.y, false) + }} onMouseOver={() => hover(true)} onMouseOut={() => hover(false)} onMouseUp={() => { diff --git a/packages/tui/test/cli/tui/toast.test.tsx b/packages/tui/test/cli/tui/toast.test.tsx index 6b04f68c27e..e7adec527e2 100644 --- a/packages/tui/test/cli/tui/toast.test.tsx +++ b/packages/tui/test/cli/tui/toast.test.tsx @@ -1,8 +1,15 @@ /** @jsxImportSource @opentui/solid */ import { expect, test } from "bun:test" -import { testRender } from "@opentui/solid" +import { EmbeddedTerminalRenderable } from "@opentui/core" +import { extend, testRender } from "@opentui/solid" import { onMount } from "solid-js" -import { ToastProvider, useToast, type ToastContext } from "../../../src/ui/toast" +import { ConfigProvider } from "../../../src/config" +import { ThemeProvider } from "../../../src/context/theme" +import { Toast, ToastProvider, useToast, type ToastContext } from "../../../src/ui/toast" +import { emptyThemeSource } from "../../fixture/fixture" +import { createTuiResolvedConfig } from "../../fixture/tui-runtime" + +extend({ embeddedTerminal: EmbeddedTerminalRenderable }) function captureToast(setToast: (toast: ToastContext) => void) { return function Capture() { @@ -70,3 +77,41 @@ test("activation dismisses a toast without an action", async () => { app.renderer.destroy() } }) + +test("toast hides only the terminal cursor it covers, until dismissed", async () => { + let toast!: ToastContext + let terminal!: EmbeddedTerminalRenderable + const Capture = captureToast((value) => (toast = value)) + const app = await testRender( + () => ( + + + + + (terminal = value)} width="100%" height="100%" /> + + + + + ), + { width: 60, height: 12 }, + ) + try { + await app.renderOnce() + terminal.focus() + terminal.write("\x1b[?25h\x1b[2;1H") + toast.show({ message: "Copied to clipboard", variant: "info", duration: 60_000 }) + await app.renderOnce() + expect(app.renderer.getCursorState().visible).toBe(true) + + terminal.write("\x1b[2;52H") + await app.renderOnce() + expect(app.renderer.getCursorState().visible).toBe(false) + + toast.dismiss() + await app.renderOnce() + expect(app.renderer.getCursorState()).toMatchObject({ x: 52, y: 2, visible: true }) + } finally { + app.renderer.destroy() + } +})