Skip to content

Commit e95474d

Browse files
authored
fix: revert parts of a824064 which caused system theme regression (#23714)
1 parent 96a534d commit e95474d

5 files changed

Lines changed: 66 additions & 21 deletions

File tree

bun.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
"@opentelemetry/exporter-trace-otlp-http": "0.214.0",
124124
"@opentelemetry/sdk-trace-base": "2.6.1",
125125
"@opentelemetry/sdk-trace-node": "2.6.1",
126-
"@opentui/core": "0.1.101",
127-
"@opentui/solid": "0.1.101",
126+
"@opentui/core": "0.1.99",
127+
"@opentui/solid": "0.1.99",
128128
"@parcel/watcher": "2.5.1",
129129
"@pierre/diffs": "catalog:",
130130
"@solid-primitives/event-bus": "1.1.2",

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { render, TimeToFirstDraw, useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
22
import * as Clipboard from "@tui/util/clipboard"
33
import * as Selection from "@tui/util/selection"
4+
import * as Terminal from "@tui/util/terminal"
45
import { createCliRenderer, MouseButton, type CliRendererConfig } from "@opentui/core"
56
import { RouteProvider, useRoute } from "@tui/context/route"
67
import {
@@ -119,6 +120,12 @@ export function tui(input: {
119120
const unguard = win32InstallCtrlCGuard()
120121
win32DisableProcessedInput()
121122

123+
const mode = await Terminal.getTerminalBackgroundColor()
124+
125+
// Re-clear after getTerminalBackgroundColor() because setRawMode(false)
126+
// restores the original console mode, including processed input on Windows.
127+
win32DisableProcessedInput()
128+
122129
const onExit = async () => {
123130
unguard?.()
124131
resolve()
@@ -129,7 +136,6 @@ export function tui(input: {
129136
}
130137

131138
const renderer = await createCliRenderer(rendererConfig(input.config))
132-
const mode = (await renderer.waitForThemeMode(1000)) ?? "dark"
133139

134140
await render(() => {
135141
return (

packages/opencode/src/cli/cmd/tui/util/terminal.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ function parse(color: string): RGBA | null {
1717
return null
1818
}
1919

20+
function mode(background: RGBA | null): "dark" | "light" {
21+
if (!background) return "dark"
22+
const luminance = (0.299 * background.r + 0.587 * background.g + 0.114 * background.b) / 255
23+
return luminance > 0.5 ? "light" : "dark"
24+
}
25+
2026
/**
2127
* Query terminal colors including background, foreground, and palette (0-15).
2228
* Uses OSC escape sequences to retrieve actual terminal color values.
@@ -94,3 +100,36 @@ export async function colors(): Promise<{
94100
}, 1000)
95101
})
96102
}
103+
104+
// Keep startup mode detection separate from `colors()`: the TUI boot path only
105+
// needs OSC 11 and should resolve on the first background response instead of
106+
// waiting on the full palette query used by system theme generation.
107+
export async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
108+
if (!process.stdin.isTTY) return "dark"
109+
110+
return new Promise((resolve) => {
111+
let timeout: NodeJS.Timeout
112+
113+
const cleanup = () => {
114+
process.stdin.setRawMode(false)
115+
process.stdin.removeListener("data", handler)
116+
clearTimeout(timeout)
117+
}
118+
119+
const handler = (data: Buffer) => {
120+
const match = data.toString().match(/\x1b]11;([^\x07\x1b]+)/)
121+
if (!match) return
122+
cleanup()
123+
resolve(mode(parse(match[1])))
124+
}
125+
126+
process.stdin.setRawMode(true)
127+
process.stdin.on("data", handler)
128+
process.stdout.write("\x1b]11;?\x07")
129+
130+
timeout = setTimeout(() => {
131+
cleanup()
132+
resolve("dark")
133+
}, 1000)
134+
})
135+
}

packages/plugin/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"zod": "catalog:"
2323
},
2424
"peerDependencies": {
25-
"@opentui/core": ">=0.1.101",
26-
"@opentui/solid": ">=0.1.101"
25+
"@opentui/core": ">=0.1.99",
26+
"@opentui/solid": ">=0.1.99"
2727
},
2828
"peerDependenciesMeta": {
2929
"@opentui/core": {
@@ -34,8 +34,8 @@
3434
}
3535
},
3636
"devDependencies": {
37-
"@opentui/core": "0.1.101",
38-
"@opentui/solid": "0.1.101",
37+
"@opentui/core": "0.1.99",
38+
"@opentui/solid": "0.1.99",
3939
"@tsconfig/node22": "catalog:",
4040
"@types/node": "catalog:",
4141
"typescript": "catalog:",

0 commit comments

Comments
 (0)