Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
Copy: one toast, when the text is copied
razorback160e1f4974ea65
diff --git a/docs/limitations.md b/docs/limitations.mdindex da3e622..28ad25d 100644--- a/docs/limitations.md+++ b/docs/limitations.md@@ -4,6 +4,7 @@- **Copying text from a picture** (refer to [Copy text from a picture](usage.md#copy-text-from-a-picture)) has these limits:- The automatic copy works only on macOS, and not over ssh (`pbpaste` reads the clipboard of the computer that runs Claude Code). It also needs `/usr/bin/perl` with Apple's PerlObjCBridge (macOS has it), which reads the change counter of the clipboard. If the bridge does not load, the automatic copy is off: the mod does not read the clipboard at intervals in its place. `/iui details` shows the state on the line `Auto copy:`. When the automatic copy is off, the clipboard keeps the picture cells (U+10EEEE plus combining marks), and a paste gives strange characters. Use `/iui grab`, Claude Code's `/copy` (the last answer as Markdown, `/copy 2` for the one before it), or turn the mod off (`/iui off`) to select text.+ - The first copy from a page takes 0.15–0.5 s (2–3 s for a page with a large Typst drawing), and no toast shows during this time. If you paste before the toast "copied N chars of text" shows, the paste gives the picture cells.- The mod copies whole words. It copies a word when the selection covers the middle of the word. In a code block, in a long word (30 characters or more, for example a path or a URL) and in CJK text, it copies each character whose middle is in the selection.- The mod does not copy math, the text in an image, or the text in a Typst drawing.- The cells do not identify the answer. The mod uses the answer of the selected row if it knows it, else the newest answer whose pages fit the selection. A selection in one page of a long answer fits each page that is tall enough, and the mod uses the first one. Thus the text can come from a different page or an older answer of the same width. `/iui dump` shows the page that the mod used.diff --git a/docs/usage.md b/docs/usage.mdindex 658d9b1..078b50b 100644--- a/docs/usage.md+++ b/docs/usage.md@@ -55,7 +55,7 @@ Intelligent UI draws Claude's answers as rendered Markdown pictures. Only the drSelect the text in a picture (an answer, a plan or a Markdown file that Claude sent) with the mouse, as you do with normal text. The selection puts picture cells on the clipboard. On macOS, while the mod is on and has drawn a picture in this session, the mod sees each change of the clipboard (in 0.3 s or less). When the clipboard has picture cells, the mod puts the text under your selection on the clipboard, and a toast shows the number of characters. Wait for this toast, then paste. In fullscreen mode, if this session has a selection, the mod changes the clipboard only when the clipboard holds that selection. Thus a copy from a different Claude Code session usually stays as it is. The mod does not change a clipboard that has no picture cells.-The mod finds the position of each word on a page when you copy from that page for the first time. This takes 0.15–0.5 s, and more (2–3 s) for a page with a large Typst drawing. If it takes more than 0.15 s, a toast shows "reading the picture". The mod keeps the positions in memory, so the next copy from the same page is fast.+The mod finds the position of each word on a page when you copy from that page for the first time. This takes 0.15–0.5 s, and more (2–3 s) for a page with a large Typst drawing. No toast shows while it does this. Only the toast of the copy shows. The mod keeps the positions in memory, so the next copy from the same page is fast.If the clipboard did not change, use `/iui grab`. It reads the last mouse selection of Claude Code (fullscreen mode only) and copies its text. If the copied text is not correct, `/iui dump` shows the cells that the mod found and the page that it used. It also writes all of this to `copy-debug.json` in the cache folder.diff --git a/hooks/lib/probe.ts b/hooks/lib/probe.tsindex a4ee416..0f048e5 100644--- a/hooks/lib/probe.ts+++ b/hooks/lib/probe.ts@@ -63,9 +63,6 @@ const inflight = new Map<string, Promise<PageWords | null>>()const pageKey = (d: Drawn, page: number) => `${d.dir}#${page}`-// Whether page `page` of a drawing is known (no probe needs to run).-export const isProbed = (d: Drawn, page: number) => probed.has(pageKey(d, page))-// The words of page `page` (0-based) of a drawing, for a copy: kept, else// its probe (one run per page at a time). Null when the drawing has no Job// or the probe fails (a failure is not kept: the next copy probes again).diff --git a/hooks/lib/settings.ts b/hooks/lib/settings.tsindex 434fee2..f6aeb76 100644--- a/hooks/lib/settings.ts+++ b/hooks/lib/settings.ts@@ -68,12 +68,10 @@ export const NO_NETWORK = 'http://127.0.0.1:9'export const HOST_POLL_MS = 3000export const HOST_CHECK_MS = 2000// Copy: how often the watcher reads the clipboard's change count (macOS;-// one call in the watcher, no process), the word positions of how many-// pages are kept in memory (a copy probes only the pages it reads), and-// how long a probe runs before a toast says the mod reads the picture.+// one call in the watcher, no process), and the word positions of how+// many pages are kept in memory (a copy probes only the pages it reads).export const CLIP_WAKE_MS = 300export const PROBED_KEPT = 64-export const READING_TOAST_MS = 150// The base every theme merges over (its theme.json and syntax files).export const BASE_THEME = 'vscode'// The theme used when none is chosen, or when the chosen one is not usable.diff --git a/hooks/register.tsx b/hooks/register.tsxindex bc4e9ac..40fbcd0 100644--- a/hooks/register.tsx+++ b/hooks/register.tsx@@ -21,7 +21,7 @@ import { atom, read, update } from 'claude-code'import type { EngineInterface, Register, RenderElement, RenderViewport } from 'claude-code'import {- DEFAULT_THEME, heightText, IMAGE_MAX_COLUMNS, MARGIN_TOP, MAX_HEIGHT, MAX_SIZE, MAX_WIDTH, MIN_HEIGHT, MIN_SIZE, MIN_WIDTH, READING_TOAST_MS, RESULTS_KEPT, TYPST_PROMPT,+ DEFAULT_THEME, heightText, IMAGE_MAX_COLUMNS, MARGIN_TOP, MAX_HEIGHT, MAX_SIZE, MAX_WIDTH, MIN_HEIGHT, MIN_SIZE, MIN_WIDTH, RESULTS_KEPT, TYPST_PROMPT,widthText,} from './lib/settings'import { clip, drawnAnswers, editedPlans, keep, queue, refresh, running, S, subagentPlans, writesLive, type Env } from './lib/state'@@ -34,7 +34,7 @@ import { pollHost, PROBE_RUNS, probeOsc11, showMode, USE_OSC11, watchHost } fromimport { measureFonts } from './lib/typst'import { drawPages } from './lib/draw'import { finalizeAll } from './lib/stream'-import { isProbed, noteDrawn, noteDrawnAgain, noteOnScreen, wordsOf } from './lib/probe'+import { noteDrawn, noteDrawnAgain, noteOnScreen, wordsOf } from './lib/probe'import { codePointsOf, decodeSelection, hasPlaceholders, joinSegments, pageTopsOf, pickPages, textOfRun, type Pick, type Segment } from './lib/copy'import { pagesOf, type Drawing } from './lib/answer'import { setUp } from './lib/env'@@ -208,37 +208,24 @@ function noteCopy($: EngineInterface, note: () => void) {type CopyRead = { text: string; segments: Segment[]; picks: Pick[]; runs: number; resolved: number }// The text for a clipboard (or selection) text with placeholders. A page-// not probed yet is probed now; when that takes longer than-// READING_TOAST_MS, a toast says so.+// not probed yet is probed now, with no toast: only the copy has one.async function readCopy($: EngineInterface, raw: string, requestId?: string): Promise<CopyRead> {const segments = decodeSelection(raw)const picks = pickPages(segments, [...drawnAnswers.values()], requestId)const texts: (string | null)[] = []let resolved = 0- let toast: { cancel: () => void } | null = null- try {- for (const [i, seg] of segments.entries()) {- const pick = picks[i]- const d = pick ? drawnAnswers.get(pick.id) : undefined- const page = pick && d ? d.pages[pick.page] : undefined- if (seg.kind !== 'image' || !pick || !d || !page) {- texts.push(null)- continue- }- if (!toast && !isProbed(d, pick.page)) {- toast = $.clock.after(READING_TOAST_MS, () => {- try {- $.ui.toast('Intelligent UI: reading the picture…')- } catch {}- })- }- const words = await wordsOf($, d, pick.page)- const text = words ? textOfRun(seg.lines, words.items, words.blocks, page) : ''- if (text) resolved++- texts.push(text || null)+ for (const [i, seg] of segments.entries()) {+ const pick = picks[i]+ const d = pick ? drawnAnswers.get(pick.id) : undefined+ const page = pick && d ? d.pages[pick.page] : undefined+ if (seg.kind !== 'image' || !pick || !d || !page) {+ texts.push(null)+ continue}- } finally {- toast?.cancel()+ const words = await wordsOf($, d, pick.page)+ const text = words ? textOfRun(seg.lines, words.items, words.blocks, page) : ''+ if (text) resolved+++ texts.push(text || null)}const runs = segments.filter(seg => seg.kind === 'image').lengthconst read = { text: joinSegments(segments, texts), segments, picks, runs, resolved }diff --git a/tests/copy.test.ts b/tests/copy.test.tsindex 30dc5dd..6638602 100644--- a/tests/copy.test.ts+++ b/tests/copy.test.ts@@ -7,7 +7,6 @@ import {} from '../hooks/register'import { WATCH_RESTART_MS } from '../hooks/lib/frame'import { rowsAfter, type Under } from '../hooks/lib/pictures'-import { READING_TOAST_MS } from '../hooks/lib/settings'import { LONG_MARKS, LONG_MD, LONG_PAGE, SMALL_MARKS, SMALL_MD, SMALL_PAGE, SMALL_PPI } from './copy-fixture'// One screen row of a picture as Claude Code draws it: `lead` (the gutter),@@ -547,14 +546,14 @@ test('positions are kept in memory: copies of the same page share one probe run,const w = world(on)await $.command.run({ command: 'iui', args: '' } as any)await drawAnswer($, w)- // A slow probe: a toast says the mod reads the picture.+ // A slow probe: no toast until the copy is done.+ const before = w.toasts.lengthw.hold()w.copy(COPY)await w.clock.settle()expect(w.queries.length).toBe(1)- expect(w.toasts).not.toContain('Intelligent UI: reading the picture…')- await w.clock.advance(READING_TOAST_MS)- expect(w.toasts).toContain('Intelligent UI: reading the picture…')+ await w.clock.advance(1000)+ expect(w.toasts.length).toBe(before)// /iui grab of the same page meanwhile waits for the same run.w.selection = { text: COPY, requestId: 'ans-1' }const grabbed = $.command.run({ command: 'iui', args: 'grab' } as any)@@ -570,7 +569,7 @@ test('positions are kept in memory: copies of the same page share one probe run,w.selection = undefinedw.copy([cells(1, 0, 97), cells(2, 0, 97), cells(3, 0, 21)].join('\n'))await w.clock.settle()- await w.clock.advance(READING_TOAST_MS)+ await w.clock.advance(1000)expect(w.queries.length).toBe(1)expect(w.copies.length).toBe(3)expect(w.toasts.slice(toasts)).toEqual(['Intelligent UI: copied 35 chars of text'])