|
| 1 | +import type { Plugin } from "@opencode/plugin/tui" |
| 2 | +import type { SessionMessageAssistant, SessionMessageAssistantText } from "@opencode/client" |
| 3 | +import { useTerminalDimensions } from "@opentui/solid" |
| 4 | +import { createSignal } from "solid-js" |
| 5 | +import { useConfig } from "../../../config" |
| 6 | +import { createTimelineAnchors } from "../../../routes/session/anchors" |
| 7 | +import { TextPart } from "../../../routes/session/message-parts" |
| 8 | +import { context } from "../../../routes/session/render-context" |
| 9 | +import { StoryFooter } from "./footer" |
| 10 | +import type { Story } from "./index" |
| 11 | + |
| 12 | +const text = `Click, double-click, drag, right-click, or Ctrl/Shift+click the links below. |
| 13 | +
|
| 14 | +**Long bare URL:** https://www.rockauto.com/en/catalog/dodge,2004,ram+1500,4.7l+v8,1432463,brake+&+wheel+hub,brake+pad,1684 |
| 15 | +
|
| 16 | +**Named link:** read [the OpenTUI terminal capabilities guide](https://github.com/anomalyco/opentui/blob/main/packages/core/docs/terminal-capabilities.mdx) for details. |
| 17 | +
|
| 18 | +**URL in inline code (not linked):** \`https://github.com/anomalyco/opencode/issues/51727#issuecomment-wrapped-link\` |
| 19 | +
|
| 20 | +**Relative link (not http):** see [link.tsx](packages/tui/src/ui/link.tsx). |
| 21 | +
|
| 22 | +| Issue | Link | |
| 23 | +| --- | --- | |
| 24 | +| Wrapped links | https://github.com/anomalyco/opencode/issues/51727 | |
| 25 | +| Ctrl+click | https://github.com/anomalyco/opencode/issues/44442 | |
| 26 | +
|
| 27 | +- A list item ending in https://example.com/a/very/long/path/that/keeps/going/until/it/wraps/around` |
| 28 | + |
| 29 | +const part: SessionMessageAssistantText = { type: "text", text } |
| 30 | +const message: SessionMessageAssistant = { |
| 31 | + id: "link-clicks", |
| 32 | + type: "assistant", |
| 33 | + agent: "build", |
| 34 | + model: { providerID: "fixture", id: "fixture" }, |
| 35 | + time: { created: 0, completed: 1 }, |
| 36 | + content: [part], |
| 37 | +} |
| 38 | + |
| 39 | +function LinkClicksStory(props: { context: Plugin.Context }) { |
| 40 | + const dimensions = useTerminalDimensions() |
| 41 | + const theme = props.context.theme |
| 42 | + const config = useConfig() |
| 43 | + const [narrow, setNarrow] = createSignal(true) |
| 44 | + const [markdownMode, setMarkdownMode] = createSignal<"source" | "rendered">("rendered") |
| 45 | + const width = () => (narrow() ? Math.min(48, dimensions().width) : dimensions().width) |
| 46 | + |
| 47 | + props.context.keymap.layer(() => ({ |
| 48 | + commands: [ |
| 49 | + { |
| 50 | + bind: "escape", |
| 51 | + title: "Back to storybook", |
| 52 | + group: "Storybook", |
| 53 | + run: () => props.context.ui.router.navigate({ type: "plugin", name: "storybook" }), |
| 54 | + }, |
| 55 | + { |
| 56 | + bind: "w", |
| 57 | + title: "Toggle narrow width", |
| 58 | + group: "Storybook", |
| 59 | + run: () => setNarrow((value) => !value), |
| 60 | + }, |
| 61 | + { |
| 62 | + bind: "m", |
| 63 | + title: "Toggle markdown mode", |
| 64 | + group: "Storybook", |
| 65 | + run: () => setMarkdownMode((mode) => (mode === "rendered" ? "source" : "rendered")), |
| 66 | + }, |
| 67 | + ], |
| 68 | + })) |
| 69 | + |
| 70 | + return ( |
| 71 | + <box |
| 72 | + width={dimensions().width} |
| 73 | + height={dimensions().height} |
| 74 | + flexDirection="column" |
| 75 | + backgroundColor={theme.background.base} |
| 76 | + > |
| 77 | + <context.Provider |
| 78 | + value={{ |
| 79 | + get width() { |
| 80 | + return width() |
| 81 | + }, |
| 82 | + get terminal() { |
| 83 | + return dimensions() |
| 84 | + }, |
| 85 | + sessionID: "link-clicks", |
| 86 | + anchors: createTimelineAnchors(), |
| 87 | + groupExpanded: () => true, |
| 88 | + setGroupExpanded: () => {}, |
| 89 | + thinkingMode: () => "show", |
| 90 | + markdownMode, |
| 91 | + groupExploration: () => false, |
| 92 | + diffWrapMode: () => "word", |
| 93 | + models: () => [], |
| 94 | + messageIndex: () => undefined, |
| 95 | + legacyTurns: () => false, |
| 96 | + config: config.data, |
| 97 | + mutatePending: async () => false, |
| 98 | + pendingDelivery: () => undefined, |
| 99 | + }} |
| 100 | + > |
| 101 | + <scrollbox flexGrow={1} minHeight={0}> |
| 102 | + <box width={width()} paddingTop={1} paddingRight={2}> |
| 103 | + <TextPart part={part} message={message} last /> |
| 104 | + </box> |
| 105 | + </scrollbox> |
| 106 | + </context.Provider> |
| 107 | + <StoryFooter |
| 108 | + context={props.context} |
| 109 | + title="storybook / Link clicks" |
| 110 | + details={[`${width()} cols`, markdownMode()]} |
| 111 | + controls={[ |
| 112 | + { shortcut: "w", label: "narrow/full width" }, |
| 113 | + { shortcut: "m", label: "rendered/source" }, |
| 114 | + { shortcut: "esc", label: "back" }, |
| 115 | + ]} |
| 116 | + /> |
| 117 | + </box> |
| 118 | + ) |
| 119 | +} |
| 120 | + |
| 121 | +export const linkClicksStory: Story = { |
| 122 | + id: "link-clicks", |
| 123 | + title: "Link clicks", |
| 124 | + render: (context) => <LinkClicksStory context={context} />, |
| 125 | +} |
0 commit comments