fix(tui): hide terminal cursor behind toast notifications (#60249)

Co-authored-by: Daniel Smolsky <dannysmo@gmail.com>
This commit is contained in:
Richard
2026-10-31 22:42:12 +01:00
committed by GitHub
Unverified
parent dc4775a64d
commit b5f856e1e2
2 changed files with 55 additions and 2 deletions
+8
View File
@@ -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={() => {
+47 -2
View File
@@ -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(
() => (
<ConfigProvider config={createTuiResolvedConfig()}>
<ThemeProvider mode="dark" source={emptyThemeSource}>
<ToastProvider>
<Capture />
<embeddedTerminal ref={(value) => (terminal = value)} width="100%" height="100%" />
<Toast />
</ToastProvider>
</ThemeProvider>
</ConfigProvider>
),
{ 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()
}
})