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
Merge branch 'fix2-flip' into release-0.3.3-merge
razorback162ae3e4f25e74
diff --cc CHANGELOG.mdindex 4e8610f,f750858..611029e--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -30,10 -28,11 +30,11 @@@ All releases of Intelligent UI for Clau- When `$.ui.selection()` fails, a `ui.copy` of picture cells and `/iui grab` copy again (before, they said that a newer copy came first).- A clipboard read that fails (an error or the 2 s timeout), or a late read of one of the mod's last 4 copies, no longer cancels a newer copy.- In herdr, the mod now uses the font and the background of the terminal that herdr runs in (Ghostty, kitty, iTerm2, cmux or Rio). Before, it used Menlo and the OS appearance, so the text could be dark on a dark background.- - With the `auto` theme, the background comes from herdr: herdr gives the background of the terminal in front (OSC 11). This also works with `herdr --remote`. If an answer does not come, the mod keeps the last background for up to 2 more checks.+ - With the `auto` theme, the background comes from herdr: herdr gives the background of the terminal in front (OSC 11). This also works with `herdr --remote`. The mod asks only at the start and when you change to a different terminal, never on a timer, because the question reads the tty that Claude Code reads. Refer to [Limitations](docs/limitations.md).- The font comes from the herdr client that you use. You can attach to one herdr server from more than one terminal, for example from Ghostty and from kitty. On macOS, the mod uses the client in the terminal app in front. When the app in front is not a terminal (for example a browser), it keeps the last client. On Linux, and between two clients in the same app, it uses the client where you typed last. When you change to a different terminal, the mod finds it at the next check (every 1 s), reads its font and draws the pictures again. If the mod cannot find the client, it uses the variables of the terminal that started the herdr server.- In herdr, a tall page of a long answer did not show (herdr does not send an image that is too large to the terminal). Refer to [Limitations](docs/limitations.md).- - At a page break between two blocks (for example a paragraph and a list, or a table and a heading), the next page starts with the same gap as in one page. Before, the gap was lost. With the row grid off, the gap can be up to 1 row larger.+ - herdr in iTerm2: the last rows of a page taller than 255 rows no longer go missing, and a picture that two sessions stored at the same time no longer stays blank.+ - At a page break between two blocks (for example a paragraph and a list, or a table and a heading), the next page starts with the same gap as in one page. Before, the gap was lost. With the row grid off, the gap can be up to 1 row larger. At a break between two items of a list, the gap is the gap between the items (it was 1 or 2 rows too large).### Changeddiff --cc docs/how-it-works.mdindex 2355000,a2ed3af..beb10eb--- a/docs/how-it-works.md+++ b/docs/how-it-works.md@@@ -92,9 -92,9 +92,9 @@@ The terminal comes before the OS: a darIn **herdr**, `TERM_PROGRAM` is `herdr`, so it does not name the terminal that herdr runs in. Intelligent UI does these steps:-- **Background:** herdr answers OSC 11 with the background of the terminal in front. In herdr, this is source 0, before the sources above. It also works with `herdr --remote`, where the mod runs on the remote computer. Claude Code reads some answers first. If no answer comes, Intelligent UI keeps the last answer until 3 checks in a row get no answer. Then it uses the sources above.-- **Terminal and font:** herdr runs a server, and one or more clients (`herdr`, `herdr --session <name>`, `herdr session attach <name>`) attach to it from terminals. Intelligent UI finds the herdr server above its own process. Then it lists the herdr clients of this user that have a tty (one `ps`). With more than one herdr server, it keeps only the clients that connect to its own server (`lsof`). On macOS, it uses a client in the terminal app in front (`lsappinfo`, by the app's bundle id). If there are two or more such clients, it uses the one whose tty was read last (the access time of the tty changes when you type in that terminal). If the app in front has no client (for example, a browser), it keeps the client that it used before. On Linux, and when it cannot read the app in front, it uses the client whose tty was read last. The tty time alone is not sufficient: iTerm2 answers each picture that herdr sends (herdr puts `q=2`, no answer, only in the first part of the upload), so the tty of the iTerm2 client is read each time that the mod draws pictures, also when you do not type there. An answer of this type from a terminal on Linux is not known. It reads the variables of that client (Linux: `/proc/<pid>/environ`; macOS: `ps eww`) and the terminal app above it (the nearest process with no tty). The terminal app comes first, then `TERM`, `TERM_PROGRAM` and the variables of each terminal. Intelligent UI then uses that terminal's sources above (with that client's `ITERM_PROFILE`, `KITTY_CONFIG_DIRECTORY`, `GHOSTTY_BIN_DIR`, `GHOSTTY_RESOURCES_DIR`, `RIO_CONFIG_HOME` and `COLORFGBG`) and its font for the text size. It checks the client every 1 s. This check reads only the app in front and the tty times of the known clients (one small `sh` with `lsappinfo` and `stat`, approximately 0.01 s of CPU time). The full check with the process list (approximately 0.1 s of CPU time) runs only when the 1 s check finds a change (a different client, a terminal in front with no known client, or a tty that is gone), and every 10 s to find new and gone clients. When the terminal changes, it reads the font and the background again and draws the pictures again.+- **Background:** herdr answers OSC 11 with the background of the terminal in front. In herdr, this is source 0, before the sources above. It also works with `herdr --remote`, where the mod runs on the remote computer. The question reads the tty that Claude Code reads (refer to [Limitations](limitations.md)), so Intelligent UI asks only at the start and when it changes to a different herdr client, never on a timer. It asks only when no key came in the prompt box for 2 s, when the mod is on and draws pictures in herdr, and when the theme was `auto` at the start or at the change of client. Claude Code reads some answers first. If no answer comes, it asks again at the next checks, 3 times at most. Then it uses the sources above. It keeps an answer while the sources above give the same mode as when the answer came. When they change (for example, the OS appearance changes and the terminal's theme follows it), it uses them.+- **Terminal and font:** herdr runs a server, and one or more clients (`herdr`, `herdr --session <name>`, `herdr session attach <name>`) attach to it from terminals. Intelligent UI finds the herdr server above its own process. Then it lists the herdr clients of this user that have a tty (one `ps`). With more than one herdr server, it keeps only the clients that connect to its own server (`lsof`). On macOS, it uses a client in the terminal app in front (`lsappinfo`, by the app's bundle id). If there are two or more such clients, it uses the one whose tty was read last (the access time of the tty changes when you type in that terminal). If the app in front has no client (for example, a browser), it keeps the client that it used before. On Linux, and when it cannot read the app in front, it uses the client whose tty was read last. The tty time alone is not sufficient: iTerm2 answers each picture that herdr sends (herdr puts `q=2`, no answer, only in the first part of the upload), so the tty of the iTerm2 client is read each time that the mod draws pictures, also when you do not type there. An answer of this type from a terminal on Linux is not known. It reads the variables of that client (Linux: `/proc/<pid>/environ`; macOS: `ps eww`; the shell that reads them keeps only the terminal's variables, `CLIENT_NAMES` in `hooks/lib/terminal.ts`) and the terminal app above it (the nearest process with no tty). The terminal app comes first, then `TERM`, `TERM_PROGRAM` and the variables of each terminal. Intelligent UI then uses that terminal's sources above (with that client's `ITERM_PROFILE`, `KITTY_CONFIG_DIRECTORY`, `GHOSTTY_BIN_DIR`, `GHOSTTY_RESOURCES_DIR`, `RIO_CONFIG_HOME` and `COLORFGBG`) and its font for the text size. It checks the client every 1 s. This check reads only the app in front and the tty times of the known clients (one small `sh` with `lsappinfo` and `stat`, approximately 0.01 s of CPU time). The full check with the process list (approximately 0.1 s of CPU time) runs only when the 1 s check finds a change (a different client, a terminal in front with no known client, or a tty that is gone), and every 10 s to find new and gone clients. When no client is attached (a detached pane), there is no 1 s check, only the full check every 10 s. The checks run only while the mod is on and Claude Code draws pictures in herdr. When the terminal changes, it reads the font and the background again and draws the pictures again.- - **iTerm2:** herdr runs a terminal of its own for each pane. It draws a picture of Claude Code (kitty placeholder cells) in the outer terminal as one kitty placement for each row, with a source rectangle: row k of a picture that is H pixels tall and R rows tall shows the source rows from floor(k × H / R), floor(H / R) rows tall. iTerm2 3.6 and 3.7 count the top of a source rectangle from the bottom of the image. When the client is iTerm2 (not with `herdr --remote`), Intelligent UI stores each picture with the band of each row at the rows that iTerm2 reads for that row (`hooks/lib/flip.ts`). Before this, a page is made exactly R × B pixels tall (B is a whole number), so the change is the reverse order of the bands. Pictures under rows are first made by Typst at their size in cells. The render key includes this mode, so a change of client draws new files.+ - **iTerm2:** herdr runs a terminal of its own for each pane. It draws a picture of Claude Code (kitty placeholder cells) in the outer terminal as one kitty placement for each row, with a source rectangle: row k of a picture that is H pixels tall and R rows tall shows the source rows from floor(k × H / R), floor(H / R) rows tall. iTerm2 3.6 and 3.7 count the top of a source rectangle from the bottom of the image. When the client is iTerm2 (not with `herdr --remote`), Intelligent UI stores each picture with the band of each row at the rows that iTerm2 reads for that row (`hooks/lib/flip.ts`). Before this, a page is made exactly R × B pixels tall (B = H / R, rounded): the last row is repeated, or, when the page is taller, each row gets the band that herdr shows for it (so no rows are cut at the bottom). Thus the change is the reverse order of the bands. Pictures under rows are first made by Typst at their size in cells. The render key includes this mode, so a change of client draws new files.- **Fallback:** if it finds no client, it uses the variables that herdr keeps of the terminal that started the herdr server: `CMUX_*` for cmux, `GHOSTTY_RESOURCES_DIR` or `GHOSTTY_BIN_DIR` for Ghostty, `KITTY_PID` or `KITTY_INSTALLATION_DIR` for kitty, `ITERM_PROFILE` for iTerm2. If it finds none, it uses `COLORFGBG`, then the OS appearance.-Intelligent UI checks the theme every 3 s (in herdr, also at once when the terminal changes). After a change, each mode's pictures compile once. `/iui probe` asks the terminal for its background with OSC 11 (5 times) and shows the raw answers. This is a test of whether the answer can reach the mod. The 3 s check uses OSC 11 only in herdr.+Intelligent UI checks the theme every 3 s (in herdr, also at once when the terminal changes). After a change, each mode's pictures compile once. `/iui probe` asks the terminal for its background with OSC 11 (5 times) and shows the raw answers. This is a test of whether the answer can reach the mod. The 3 s check never uses OSC 11. Only in herdr, the mod uses OSC 11 at the start and for a new client (see above).