Upgrade OpenTUI to 0.8.1
The native library now comes from a package per platform, so the bundle leaves those imports to run time. A SyntaxStyle belongs to the renderer that made it, so the markdown style is kept per renderer.
This commit is contained in:
1 parent
e2d2892c52
commit
b35263b41b
6 files changed
+41
-31
No files matched your search
+3
-2
@@ -4,7 +4,7 @@ import type { MouseEvent, ScrollBoxRenderable } from "@opentui/core";
|
||||
import type { RefObject } from "react";
|
||||
|
||||
import { isLeftClick, useHover } from "./Button.tsx";
|
||||
import { colors, getMarkdownStyle } from "./theme.ts";
|
||||
import { colors, useMarkdownStyle } from "./theme.ts";
|
||||
|
||||
export interface DiffState {
|
||||
readonly cwd: string;
|
||||
@@ -21,6 +21,7 @@ export interface DiffState {
|
||||
/** Working-tree or checkpoint changes through the same unified diff renderer. */
|
||||
export function DiffView(props: { readonly diff: DiffState; readonly scrollRef: RefObject<ScrollBoxRenderable | null>; readonly selected: number; readonly expanded: Readonly<Record<string, { patch?: string; error?: string }>>; readonly onFile: (index: number) => void }) {
|
||||
const { diff } = props;
|
||||
const markdownStyle = useMarkdownStyle();
|
||||
const files = diff.patch ? splitPatch(diff.patch) : [];
|
||||
return (
|
||||
<box flexGrow={1} minHeight={0} flexDirection="column" paddingLeft={2} paddingRight={1} backgroundColor={colors.bg}>
|
||||
@@ -45,7 +46,7 @@ export function DiffView(props: { readonly diff: DiffState; readonly scrollRef:
|
||||
diff={props.expanded[file.path]?.patch ?? file.patch}
|
||||
view="unified"
|
||||
{...(filetypeOf(file.path) ? { filetype: filetypeOf(file.path)! } : {})}
|
||||
syntaxStyle={getMarkdownStyle()}
|
||||
syntaxStyle={markdownStyle}
|
||||
showLineNumbers
|
||||
wrapMode="none"
|
||||
fg={colors.text}
|
||||
|
||||
@@ -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, getMarkdownStyle, toneColor } from "./theme.ts";
|
||||
import { colors, toneColor, useMarkdownStyle } from "./theme.ts";
|
||||
|
||||
/** What a right-click in the conversation was on. */
|
||||
export type ConversationTarget =
|
||||
@@ -165,6 +165,7 @@ const Row = memo(function Row(props: {
|
||||
readonly mouse: ConversationMouse;
|
||||
}) {
|
||||
const { row, workspaceRoot, mouse } = props;
|
||||
const markdownStyle = useMarkdownStyle();
|
||||
switch (row.kind) {
|
||||
case "message": {
|
||||
const { message } = row;
|
||||
@@ -178,7 +179,7 @@ const Row = memo(function Row(props: {
|
||||
if (message.role === "system") return <text marginTop={1} fg={colors.muted} onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>{message.text}</text>;
|
||||
return (
|
||||
<box marginTop={1} flexDirection="column" onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>
|
||||
<markdown content={message.text || "…"} syntaxStyle={getMarkdownStyle()} streaming={message.streaming} conceal />
|
||||
<markdown content={message.text || "…"} syntaxStyle={markdownStyle} streaming={message.streaming} conceal />
|
||||
{summary && summary.files.length > 0 ? <ChangedFiles summary={summary} onOpenTurnDiff={mouse.openTurnDiff} /> : null}
|
||||
{props.footer ? <text marginTop={1} fg={colors.faint}>{props.footer}</text> : null}
|
||||
</box>
|
||||
@@ -228,7 +229,7 @@ const Row = memo(function Row(props: {
|
||||
<text fg={colors.plan}>
|
||||
<strong>Plan</strong>
|
||||
</text>
|
||||
<markdown content={row.proposedPlan.planMarkdown} syntaxStyle={getMarkdownStyle()} conceal />
|
||||
<markdown content={row.proposedPlan.planMarkdown} syntaxStyle={markdownStyle} conceal />
|
||||
</box>
|
||||
);
|
||||
case "event":
|
||||
|
||||
+13
-8
@@ -1,4 +1,5 @@
|
||||
import { SyntaxStyle, type ThemeMode } from "@opentui/core";
|
||||
import { type NativeResourceOwner, SyntaxStyle, type ThemeMode } from "@opentui/core";
|
||||
import { useRenderer } from "@opentui/react";
|
||||
|
||||
import type { StatusTone } from "../model/threads.ts";
|
||||
import type { Tone } from "../model/transcript.ts";
|
||||
@@ -69,7 +70,7 @@ export const colors: Palette = { ...DARK };
|
||||
|
||||
export function applyTheme(mode: ThemeMode): void {
|
||||
Object.assign(colors, mode === "light" ? LIGHT : DARK);
|
||||
markdownStyle = undefined;
|
||||
markdownStyles = new WeakMap();
|
||||
}
|
||||
|
||||
const STATUS_COLORS: Record<StatusTone, keyof Palette> = { info: "info", muted: "muted", warn: "warn", input: "input", bad: "bad", good: "good" };
|
||||
@@ -78,11 +79,14 @@ 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" };
|
||||
export const toneColor = (tone: Tone): string => colors[TONE_COLORS[tone]];
|
||||
|
||||
let markdownStyle: SyntaxStyle | undefined;
|
||||
let markdownStyles = new WeakMap<NativeResourceOwner, SyntaxStyle>();
|
||||
|
||||
/** Created lazily: SyntaxStyle needs the native renderer library loaded. */
|
||||
export function getMarkdownStyle(): SyntaxStyle {
|
||||
markdownStyle ??= SyntaxStyle.fromStyles({
|
||||
/** One per renderer: a SyntaxStyle belongs to the renderer's native scene that created it. */
|
||||
export function useMarkdownStyle(): SyntaxStyle {
|
||||
const owner = useRenderer().nativeScene;
|
||||
let style = markdownStyles.get(owner);
|
||||
if (style) return style;
|
||||
style = SyntaxStyle.fromStyles({
|
||||
default: { fg: colors.text },
|
||||
"markup.heading": { fg: colors.text, bold: true },
|
||||
"markup.strong": { fg: colors.text, bold: true },
|
||||
@@ -96,6 +100,7 @@ export function getMarkdownStyle(): SyntaxStyle {
|
||||
"markup.quote": { fg: colors.muted, italic: true },
|
||||
"markup.raw": { fg: colors.plan },
|
||||
"markup.raw.block": { fg: colors.text },
|
||||
});
|
||||
return markdownStyle;
|
||||
}, owner);
|
||||
markdownStyles.set(owner, style);
|
||||
return style;
|
||||
}
|
||||
Reference in new issue
Block a user