From 3bc5f61704300e612579db2510293f3cf5bf713e Mon Sep 17 00:00:00 2001 From: Callum Alpass Date: Tue, 3 Nov 2026 03:33:24 +1100 Subject: [PATCH] Theme the scrollbars OpenTUI's default track is a fixed dark grey, which showed as a dark strip in the light and terminal themes. --- src/ui/DetailsPanel.tsx | 4 ++-- src/ui/DiffView.tsx | 4 ++-- src/ui/PullRequestView.tsx | 4 ++-- src/ui/ThreadView.tsx | 4 ++-- src/ui/theme.ts | 3 +++ test/app/streaming.test.tsx | 14 ++++++++++++++ 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/ui/DetailsPanel.tsx b/src/ui/DetailsPanel.tsx index 489fc3f..d5d9d4d 100644 --- a/src/ui/DetailsPanel.tsx +++ b/src/ui/DetailsPanel.tsx @@ -3,7 +3,7 @@ import type { ReactNode } from "react"; import { MAX_DETAIL_FILES, type ChangedFile, type DetailsAction, type DetailsFold, type LineageLine, type ThreadDetails } from "../model/details.ts"; import { Button, ClickRow } from "./Button.tsx"; import { truncate } from "./text.ts"; -import { colors, statusColor } from "./theme.ts"; +import { colors, scrollbarOptions, statusColor } from "./theme.ts"; /** Rows stay readable when the panel takes the conversation's place on a narrow terminal. */ const IN_PLACE_MAX_WIDTH = 64; @@ -46,7 +46,7 @@ export function DetailsPanel(props: { overflow="hidden" backgroundColor={colors.panel} > - + {!details ? ( {props.empty ?? "No thread selected."} ) : ( diff --git a/src/ui/DiffView.tsx b/src/ui/DiffView.tsx index bd779f1..df9485d 100644 --- a/src/ui/DiffView.tsx +++ b/src/ui/DiffView.tsx @@ -4,7 +4,7 @@ import type { MouseEvent, ScrollBoxRenderable } from "@opentui/core"; import type { RefObject } from "react"; import { isLeftClick, useHover } from "./Button.tsx"; -import { colors, useMarkdownStyle } from "./theme.ts"; +import { colors, scrollbarOptions, useMarkdownStyle } from "./theme.ts"; export interface DiffState { readonly cwd: string; @@ -37,7 +37,7 @@ export function DiffView(props: { readonly diff: DiffState; readonly split: bool {diff.status === "error" ? {`Could not load the diff: ${diff.error ?? "unknown error"}`} : null} {diff.status === "ready" && files.length === 0 ? No changes. : null} {diff.truncated ? The diff was too large and is cut short. : null} - + {files.map((file, index) => ( props.onFile(index)} /> diff --git a/src/ui/PullRequestView.tsx b/src/ui/PullRequestView.tsx index c80e822..af20c48 100644 --- a/src/ui/PullRequestView.tsx +++ b/src/ui/PullRequestView.tsx @@ -3,7 +3,7 @@ import type { RefObject } from "react"; import type { PullRequestLine } from "../model/pullRequests.ts"; import { Button, isLeftClick, isRightClick, useHover } from "./Button.tsx"; -import { colors, type Palette } from "./theme.ts"; +import { colors, type Palette, scrollbarOptions } from "./theme.ts"; export interface PullRequestViewState { readonly status: "loading" | "ready" | "error"; @@ -41,7 +41,7 @@ export function PullRequestView(props: { readonly view: PullRequestViewState; re {view.status === "loading" ? Loading pull request… : null} {view.status === "error" ? {`Could not load the pull request: ${view.error ?? "unknown error"}`} : null} - + {view.lines.map((line, index) => line.kind === "title" && index > 0 ? ( diff --git a/src/ui/ThreadView.tsx b/src/ui/ThreadView.tsx index a3b5660..f58d4c1 100644 --- a/src/ui/ThreadView.tsx +++ b/src/ui/ThreadView.tsx @@ -18,7 +18,7 @@ import type { T3Session, ThreadHistory } from "../client/session.ts"; import { liveWorkEntryLabel, workEntryDisplayLabel, type MessagesTimelineRow, type Timeline, type WorkLogEntry } from "../model/timeline.ts"; import { blockFor } from "../model/transcript.ts"; import { firstLine, truncate } from "./text.ts"; -import { colors, toneColor, useMarkdownStyle } from "./theme.ts"; +import { colors, scrollbarOptions, toneColor, useMarkdownStyle } from "./theme.ts"; /** What a right-click in the conversation was on. */ export type ConversationTarget = @@ -74,7 +74,7 @@ export function ThreadView(props: { ) : null} {props.error ? {props.error} : null} - + {/* Prose stops at reading width on wide terminals; the composer below stays full width. */} {props.loading && !timeline ? Loading… : null} diff --git a/src/ui/theme.ts b/src/ui/theme.ts index 5f8bab4..88fbd38 100644 --- a/src/ui/theme.ts +++ b/src/ui/theme.ts @@ -162,6 +162,9 @@ export const statusColor = (tone: StatusTone): string => colors[STATUS_COLORS[to const TONE_COLORS: Record = { normal: "text", muted: "muted", good: "good", bad: "bad", warn: "warn" }; export const toneColor = (tone: Tone): string => colors[TONE_COLORS[tone]]; +/** A scrollbox's bars in the palette: OpenTUI's own track is dark whatever the theme. */ +export const scrollbarOptions = () => ({ trackOptions: { foregroundColor: colors.muted, backgroundColor: colors.element } }); + let markdownStyles = new WeakMap(); /** One per renderer: a SyntaxStyle belongs to the renderer's native scene that created it. */ diff --git a/test/app/streaming.test.tsx b/test/app/streaming.test.tsx index d8dbf6e..40a8e7e 100644 --- a/test/app/streaming.test.tsx +++ b/test/app/streaming.test.tsx @@ -1,5 +1,8 @@ import { afterEach, describe, expect, test } from "bun:test"; +import { RGBA } from "@opentui/core"; + +import { applyTheme, colors } from "../../src/ui/theme.ts"; import { withReply } from "./fixtures.ts"; import { fakeSession, renderApp } from "./harness.tsx"; @@ -8,6 +11,7 @@ const open = async (...args: Parameters) => (app = await rende afterEach(() => { app?.destroy(); app = null; + applyTheme("dark"); }); const table = "| Name | Value |\n| --- | --- |\n| alpha | 1 |\n| beta | a longer cell |\n"; @@ -55,3 +59,13 @@ describe("streaming replies", () => { expect(content(app.frame())).toBe(before); }); }); + +test("a long answer's scrollbar takes the palette's colours, in the light theme too", async () => { + applyTheme("light"); + const app = await open({ session: fakeSession({ projection: withReply(paragraphs(0, 60), false) }) }); + const backgrounds = new Set(); + for (const line of app.renderer.currentRenderBuffer.getSpanLines() as unknown as { spans: { bg: RGBA }[] }[]) for (const span of line.spans) backgrounds.add(span.bg.toString()); + // OpenTUI's own track is a dark grey. + expect(backgrounds.has(RGBA.fromHex("#252527").toString())).toBe(false); + expect(backgrounds.has(RGBA.fromHex(colors.element).toString())).toBe(true); +});