Theme the scrollbars
OpenTUI's default track is a fixed dark grey, which showed as a dark strip in the light and terminal themes.
This commit is contained in:
1 parent
ffade010a2
commit
3bc5f61704
6 files changed
+25
-8
No files matched your search
@@ -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 { MAX_DETAIL_FILES, type ChangedFile, type DetailsAction, type DetailsFold, type LineageLine, type ThreadDetails } from "../model/details.ts";
|
||||||
import { Button, ClickRow } from "./Button.tsx";
|
import { Button, ClickRow } from "./Button.tsx";
|
||||||
import { truncate } from "./text.ts";
|
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. */
|
/** Rows stay readable when the panel takes the conversation's place on a narrow terminal. */
|
||||||
const IN_PLACE_MAX_WIDTH = 64;
|
const IN_PLACE_MAX_WIDTH = 64;
|
||||||
@@ -46,7 +46,7 @@ export function DetailsPanel(props: {
|
|||||||
overflow="hidden"
|
overflow="hidden"
|
||||||
backgroundColor={colors.panel}
|
backgroundColor={colors.panel}
|
||||||
>
|
>
|
||||||
<scrollbox flexGrow={1} minHeight={0} paddingLeft={1} paddingRight={1}>
|
<scrollbox flexGrow={1} minHeight={0} paddingLeft={1} paddingRight={1} scrollbarOptions={scrollbarOptions()}>
|
||||||
{!details ? (
|
{!details ? (
|
||||||
<text fg={colors.faint}>{props.empty ?? "No thread selected."}</text>
|
<text fg={colors.faint}>{props.empty ?? "No thread selected."}</text>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@ import type { MouseEvent, ScrollBoxRenderable } from "@opentui/core";
|
|||||||
import type { RefObject } from "react";
|
import type { RefObject } from "react";
|
||||||
|
|
||||||
import { isLeftClick, useHover } from "./Button.tsx";
|
import { isLeftClick, useHover } from "./Button.tsx";
|
||||||
import { colors, useMarkdownStyle } from "./theme.ts";
|
import { colors, scrollbarOptions, useMarkdownStyle } from "./theme.ts";
|
||||||
|
|
||||||
export interface DiffState {
|
export interface DiffState {
|
||||||
readonly cwd: string;
|
readonly cwd: string;
|
||||||
@@ -37,7 +37,7 @@ export function DiffView(props: { readonly diff: DiffState; readonly split: bool
|
|||||||
{diff.status === "error" ? <text fg={colors.bad} flexShrink={0}>{`Could not load the diff: ${diff.error ?? "unknown error"}`}</text> : null}
|
{diff.status === "error" ? <text fg={colors.bad} flexShrink={0}>{`Could not load the diff: ${diff.error ?? "unknown error"}`}</text> : null}
|
||||||
{diff.status === "ready" && files.length === 0 ? <text fg={colors.muted} flexShrink={0}>No changes.</text> : null}
|
{diff.status === "ready" && files.length === 0 ? <text fg={colors.muted} flexShrink={0}>No changes.</text> : null}
|
||||||
{diff.truncated ? <text fg={colors.warn} flexShrink={0}>The diff was too large and is cut short.</text> : null}
|
{diff.truncated ? <text fg={colors.warn} flexShrink={0}>The diff was too large and is cut short.</text> : null}
|
||||||
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0}>
|
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0} scrollbarOptions={scrollbarOptions()}>
|
||||||
{files.map((file, index) => (
|
{files.map((file, index) => (
|
||||||
<box key={file.path} id={`diff-file-${index}`} flexDirection="column" marginTop={1}>
|
<box key={file.path} id={`diff-file-${index}`} flexDirection="column" marginTop={1}>
|
||||||
<FileHeader path={file.path} selected={index === props.selected} canExpand={diff.source !== undefined} onPress={() => props.onFile(index)} />
|
<FileHeader path={file.path} selected={index === props.selected} canExpand={diff.source !== undefined} onPress={() => props.onFile(index)} />
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { RefObject } from "react";
|
|||||||
|
|
||||||
import type { PullRequestLine } from "../model/pullRequests.ts";
|
import type { PullRequestLine } from "../model/pullRequests.ts";
|
||||||
import { Button, isLeftClick, isRightClick, useHover } from "./Button.tsx";
|
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 {
|
export interface PullRequestViewState {
|
||||||
readonly status: "loading" | "ready" | "error";
|
readonly status: "loading" | "ready" | "error";
|
||||||
@@ -41,7 +41,7 @@ export function PullRequestView(props: { readonly view: PullRequestViewState; re
|
|||||||
</box>
|
</box>
|
||||||
{view.status === "loading" ? <text fg={colors.muted} flexShrink={0}>Loading pull request…</text> : null}
|
{view.status === "loading" ? <text fg={colors.muted} flexShrink={0}>Loading pull request…</text> : null}
|
||||||
{view.status === "error" ? <text fg={colors.bad} flexShrink={0}>{`Could not load the pull request: ${view.error ?? "unknown error"}`}</text> : null}
|
{view.status === "error" ? <text fg={colors.bad} flexShrink={0}>{`Could not load the pull request: ${view.error ?? "unknown error"}`}</text> : null}
|
||||||
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0}>
|
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0} scrollbarOptions={scrollbarOptions()}>
|
||||||
{view.lines.map((line, index) =>
|
{view.lines.map((line, index) =>
|
||||||
line.kind === "title" && index > 0 ? (
|
line.kind === "title" && index > 0 ? (
|
||||||
<text key={index} fg={colors[LINE_COLORS[line.kind]]} marginTop={1}>
|
<text key={index} fg={colors[LINE_COLORS[line.kind]]} marginTop={1}>
|
||||||
|
|||||||
@@ -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 { liveWorkEntryLabel, workEntryDisplayLabel, type MessagesTimelineRow, type Timeline, type WorkLogEntry } from "../model/timeline.ts";
|
||||||
import { blockFor } from "../model/transcript.ts";
|
import { blockFor } from "../model/transcript.ts";
|
||||||
import { firstLine, truncate } from "./text.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. */
|
/** What a right-click in the conversation was on. */
|
||||||
export type ConversationTarget =
|
export type ConversationTarget =
|
||||||
@@ -74,7 +74,7 @@ export function ThreadView(props: {
|
|||||||
</box>
|
</box>
|
||||||
) : null}
|
) : null}
|
||||||
{props.error ? <text fg={colors.bad} flexShrink={0}>{props.error}</text> : null}
|
{props.error ? <text fg={colors.bad} flexShrink={0}>{props.error}</text> : null}
|
||||||
<scrollbox ref={props.scrollRef} flexGrow={1} flexShrink={1} minHeight={0} stickyScroll stickyStart="bottom">
|
<scrollbox ref={props.scrollRef} flexGrow={1} flexShrink={1} minHeight={0} stickyScroll stickyStart="bottom" scrollbarOptions={scrollbarOptions()}>
|
||||||
{/* Prose stops at reading width on wide terminals; the composer below stays full width. */}
|
{/* Prose stops at reading width on wide terminals; the composer below stays full width. */}
|
||||||
<box flexDirection="column" maxWidth={CONTENT_WIDTH}>
|
<box flexDirection="column" maxWidth={CONTENT_WIDTH}>
|
||||||
{props.loading && !timeline ? <text fg={colors.muted}>Loading…</text> : null}
|
{props.loading && !timeline ? <text fg={colors.muted}>Loading…</text> : null}
|
||||||
|
|||||||
@@ -162,6 +162,9 @@ export const statusColor = (tone: StatusTone): string => colors[STATUS_COLORS[to
|
|||||||
const TONE_COLORS: Record<Tone, keyof Palette> = { normal: "text", muted: "muted", good: "good", bad: "bad", warn: "warn" };
|
const TONE_COLORS: Record<Tone, keyof Palette> = { normal: "text", muted: "muted", good: "good", bad: "bad", warn: "warn" };
|
||||||
export const toneColor = (tone: Tone): string => colors[TONE_COLORS[tone]];
|
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<NativeResourceOwner, SyntaxStyle>();
|
let markdownStyles = new WeakMap<NativeResourceOwner, SyntaxStyle>();
|
||||||
|
|
||||||
/** One per renderer: a SyntaxStyle belongs to the renderer's native scene that created it. */
|
/** One per renderer: a SyntaxStyle belongs to the renderer's native scene that created it. */
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { afterEach, describe, expect, test } from "bun:test";
|
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 { withReply } from "./fixtures.ts";
|
||||||
import { fakeSession, renderApp } from "./harness.tsx";
|
import { fakeSession, renderApp } from "./harness.tsx";
|
||||||
|
|
||||||
@@ -8,6 +11,7 @@ const open = async (...args: Parameters<typeof renderApp>) => (app = await rende
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
app?.destroy();
|
app?.destroy();
|
||||||
app = null;
|
app = null;
|
||||||
|
applyTheme("dark");
|
||||||
});
|
});
|
||||||
|
|
||||||
const table = "| Name | Value |\n| --- | --- |\n| alpha | 1 |\n| beta | a longer cell |\n";
|
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);
|
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<string>();
|
||||||
|
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);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user