Skip to content

Commit 4934950

Browse files
committed
feat(tui): switch rich media from the Experiments dialog
Moving rich media to the rich_media flag left release users only experimental.rich_media in the TUI config or OPENCODE_FLAGS to turn it on. It is back in the Experiments dialog, which writes that key. An entry backed by a feature flag shows the flag's resolved value, so in local and dev builds, where the flag is on by default, it reads on before anything is set, and a toggle writes the opposite.
1 parent 134752b commit 4934950

2 files changed

Lines changed: 92 additions & 1 deletion

File tree

‎packages/tui/src/component/dialog-experiments.tsx‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { createMemo, createSignal } from "solid-js"
2+
import type { ConfigFlag } from "@opencode/schema/config/flag"
23
import { useConfig, useNewDesigns } from "../config"
4+
import { flagEnabled } from "../config/flag"
5+
import { useTuiApp } from "../context/runtime"
36
import { DIALOG_LIST_INSET } from "../ui/dialog"
47
import { DialogSelect } from "../ui/dialog-select"
58
import { useTheme } from "../context/theme"
@@ -9,6 +12,11 @@ type Experiment = {
912
id: string
1013
title: string
1114
description: string
15+
/**
16+
* The feature flag the entry switches, whose id is its key in the TUI config. A flag is on by default in local and
17+
* dev builds, so the entry shows its resolved value rather than only the config's.
18+
*/
19+
flag?: ConfigFlag.Key
1220
}
1321

1422
// In-flight features anyone can opt into. Each entry is temporary: an
@@ -25,17 +33,32 @@ export const experiments: Experiment[] = [
2533
title: "TUI tools",
2634
description: "Let the agent open terminals in this TUI (requires server support)",
2735
},
36+
{
37+
id: "rich_media",
38+
title: "Rich media",
39+
description: "Inline video, a fullscreen media viewer and picture-in-picture",
40+
flag: "rich_media",
41+
},
2842
]
2943

3044
export function DialogExperiments() {
3145
const config = useConfig()
46+
const app = useTuiApp()
3247
const newDesigns = useNewDesigns()
3348
const theme = useTheme()
3449
const toast = useToast()
3550
const [selected, setSelected] = createSignal<Experiment>()
3651
const [saving, setSaving] = createSignal(false)
3752

38-
const enabled = (experiment: Experiment) => config.data.experimental?.[experiment.id] === true
53+
const enabled = (experiment: Experiment) =>
54+
experiment.flag
55+
? flagEnabled({
56+
key: experiment.flag,
57+
experimental: config.data.experimental,
58+
channel: app.channel,
59+
overrides: process.env.OPENCODE_FLAGS,
60+
})
61+
: config.data.experimental?.[experiment.id] === true
3962

4063
const options = createMemo(() =>
4164
experiments.map((experiment) => ({
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/** @jsxImportSource @opentui/solid */
2+
import { testRender } from "@opentui/solid"
3+
import { expect, test } from "bun:test"
4+
import { onMount } from "solid-js"
5+
import { DialogExperiments } from "../../src/component/dialog-experiments"
6+
import { ConfigProvider, type Info, type Interface } from "../../src/config"
7+
import { Keymap } from "../../src/context/keymap"
8+
import { TuiAppProvider } from "../../src/context/runtime"
9+
import { ThemeProvider } from "../../src/context/theme"
10+
import { DialogProvider, useDialog } from "../../src/ui/dialog"
11+
import { ToastProvider } from "../../src/ui/toast"
12+
import { emptyThemeSource, tmpdir } from "../fixture/fixture"
13+
import { TestTuiContexts } from "../fixture/tui-environment"
14+
import { createTuiResolvedConfig } from "../fixture/tui-runtime"
15+
16+
// [build channel, shown before, written by a toggle, shown after]
17+
test.each([
18+
["latest", "off", true, "on"],
19+
["local", "on", false, "off"],
20+
] as const)("rich media in a %s build shows %p and a toggle writes %p", async (channel, before, written, after) => {
21+
await using temporary = await tmpdir()
22+
const info: Info = {}
23+
const service: Interface = {
24+
get: async () => info,
25+
update: async (update) => {
26+
update(info)
27+
return info
28+
},
29+
}
30+
const app = await testRender(
31+
() => (
32+
<TestTuiContexts directory={temporary.path} paths={{ state: temporary.path }}>
33+
<TuiAppProvider value={{ name: "test", version: "test", channel }}>
34+
<ConfigProvider config={createTuiResolvedConfig(info)} service={service}>
35+
<ThemeProvider mode="dark" source={emptyThemeSource}>
36+
<Keymap.Provider>
37+
<ToastProvider>
38+
<DialogProvider>
39+
{(() => {
40+
const dialog = useDialog()
41+
onMount(() => dialog.replace(() => <DialogExperiments />))
42+
return null
43+
})()}
44+
</DialogProvider>
45+
</ToastProvider>
46+
</Keymap.Provider>
47+
</ThemeProvider>
48+
</ConfigProvider>
49+
</TuiAppProvider>
50+
</TestTuiContexts>
51+
),
52+
{ width: 100, height: 24, kittyKeyboard: true },
53+
)
54+
const row = (frame: string) => frame.split("\n").find((line) => line.includes("Rich media")) ?? ""
55+
56+
try {
57+
app.renderer.start()
58+
await app.waitForFrame((frame) => row(frame).trimEnd().endsWith(before))
59+
// Rich media is the third entry.
60+
app.mockInput.pressArrow("down")
61+
app.mockInput.pressArrow("down")
62+
app.mockInput.pressEnter()
63+
await app.waitForFrame((frame) => row(frame).trimEnd().endsWith(after))
64+
expect(info.experimental?.rich_media).toBe(written)
65+
} finally {
66+
app.renderer.destroy()
67+
}
68+
})

0 commit comments

Comments
 (0)