Repository navigation
fix(terminal): give Korean lines room: widen Hangul instead of enlarging it, and size rows for it - #2243
Conversation
…Korean lines keep their gap
…here the Latin line is shorter
…composition box at the edge
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 26 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The failing Native Windows mirrored terminal check (not a required check) does not come from this PR. |
|
Merging 457f187. Codex was at capacity, so an omo reviewer on gpt-6.1-sol and an independent second reviewer reviewed it; both pass with no MEDIUM or above. The row height follows xterm's own device-pixel rounding and goes through the existing fit and socket resize path; a real Chromium/xterm probe at DPR 2 measured stable rows across font changes (13px: 16.5px cells, 24 rows; 16px: 20px, 20 rows). Hangul runs are stretched within their two cells with the following spans at the compensated edge, selecting six Hangul cells copies exactly the text, and narrow Latin glyphs are never stretched. Main's glyph fit enlarged own-height Hangul by 1.085x; this head draws it at 1x and widens it instead. |
…ht line follows each Korean word (#2263) ## What it fixes Closes #2262. In the terminal, Korean text on a background colour showed a thin light vertical line right after each Korean word: in Claude Code's prompt block, in a highlighted line, and in inverse video. The owner reported it in Ovis for Mac. Reproduced on the test MacBook Air (isolated herdr session and test servers) in the real Ovis.app, in a WKWebView with the app's configuration, and in Mac Chrome; also in Linux Chrome. It shows at 1x and 2x, on light and dark themes. It is already there at b48c66a, before #2243, so #2243 did not cause it; it dates from the glyph fit itself. ## The cause `lib/terminalGlyphs.ts` fits a Hangul syllable to its two cells: - it centers the syllable with `padding-left` and a negative `margin-right`; - it widens it with `scaleX` (before #2243, it enlarged the font size instead); - it trims the trailing half with `clip-path`. All of that was written on xterm's own span, which also paints the cells' background (SGR background, inverse, block cursor). The clipped and stretched box ended inside a device pixel, while the next span's background starts on a whole one. The pixel between them was drawn half-covered, so a line of the pane's colour showed through. ## The change The fit goes on a span inside xterm's (marked with the module's `BOX_CLASS`, so the observer leaves it alone). xterm's span keeps its background on a box that is neither stretched nor clipped, and its own letter-spacing becomes 0. The inner span inherits `text-decoration` and `font-weight`, because xterm makes every span of a row an inline-block, which an underline does not reach into. The text, the columns and the copy are unchanged: the run still closes on the Latin row's column, and an underline stays under its cells. | Ovis for Mac (real app), main | This PR | |---|---| |  |  | WKWebView with the app's configuration, light theme. Top: b48c66a (before #2243). Middle: main. Bottom: this PR.    ## Checks - **New browser check** `scripts/terminal-hangul-seam-regression.ts` (added to `ci-browser.sh`). It draws Korean on dark, light and inverse backgrounds with the bundled faces, then reads the screenshot's device pixels on both sides of each fitted run's right edge, at 1x and 2x on light and dark themes. It also checks that the closing bar of `|가나다라마바사|` stands on the Latin row's column. - Fails on main and at b48c66a: 16 to 20 stray pixels per configuration, for example `204,202,198` against the block's `38,38,38`. - Passes with this PR, with 0 stray pixels in Linux Chrome and Mac Chrome 156. - **WKWebView probe** (the app's configuration, not committed), stray pixels at the 21 fitted edges: main 16 light / 10 dark; b48c66a 14 / 10; this PR 0 / 0. - **Unit test**: `bun test src/lib/terminalGlyphs.test.ts` passes (34 tests). The fitted-run case now asserts that xterm's span carries no transform or clip and that the fit is on the inner span; it fails on main. - **`bun run check fast`**: pass (typecheck, build, 8177 unit tests, 0 fail). - **Performance**, measured the same way in Chrome, Safari and the app's WKWebView on the Mac, main → this PR: - keystroke-to-paint median about 33 ms in each, unchanged; - a 3 s Korean flood at 59-60 fps in each, unchanged. - QA ran in a fresh clone in `/tmp` on the test Mac, against isolated herdr sessions. Everything started for it is stopped and removed afterwards. ## Reviews - **omo-native-code-reviewer: PASS (APPROVE).** No HIGH or MEDIUM findings. It reran the new check against main's `terminalGlyphs.ts` (fails) and this branch (passes), and checked block, bar and underline cursors, bold, italic, dim, underline and strikethrough in Chromium. Two LOW notes, both fixed in the second commit: - `terminal-ipad-ime-regression.ts` compared the pending syllable's size with xterm's outer span. The enlarged size now sits on the inner span, so the check reads the inner span (passes). - The seam check sampled the pane's colour three device pixels into the next cell, where a full-height `|` could sit. It now samples at the row's far end (passes). - **Codex (gpt-6.1-sol, fast, xhigh): PASS.** No findings. It went over cursors, decorations, inheritance, copy, the late-face path, observer re-entrancy, the IME view and the emoji path. ## Related The lane also measured Mac app vs Safari PWA vs Chrome terminal parity. With no coding font installed the three are identical: DOM renderer, Menlo, 16.5px rows, same latency and fps. With JetBrains Mono installed, Chrome draws it, while Safari and the app draw Menlo, so row height and count differ. That needs a product choice and is not part of this PR.
…ery device, so Mac app, Safari and Chrome match (#2272) ## What it changes The owner saw Ovis for Mac and the PWA or web app look different. For example, the terminal's Korean row count did not match between them. This came out of the mac-pwa-parity measurements (the seam that report also found is fixed separately in #2263). Measured on the test MacBook Air with the same isolated test server, a 1200x760 viewport at 2x, 13px and light theme. The same measuring script ran in Chrome 156, Safari 27 and a WKWebView with Ovis for Mac's configuration: - **With no coding font installed, the three already matched:** Menlo, 16.5px rows, DOM renderer, keystroke-to-paint about 33ms, about 60fps under a Korean flood. No performance gap between the surfaces was measurable. - **With JetBrains Mono installed, they did not.** - Chrome draws the installed copy, with 17px rows and 936px for 120 columns. - Safari hides installed fonts from pages, so it draws Menlo. - Ovis for Mac draws Menlo too: its WKWebView draws installed fonts but its canvas, which xterm measures with, cannot see them, so #1942 drops them. - Rows were therefore 17px against 16.5px. A 900px-tall pane held 52 rows in Chrome and 54 in the app. - **The bundled "JetBrains Mono Web" face was dropped in the app too** when JetBrains Mono was installed. Its `@font-face` read `local("JetBrains Mono Regular")` first, so it resolved to the installed copy. Dori chose the option that makes every surface the same: the bundled JetBrains Mono becomes the terminal's default Latin face on every device. The owner did not pick an option, and he tests main before a release. ## The change - **The terminal's first text font is `"JetBrains Mono Web"`** (`lib/fontFamily.ts`), ahead of the installed JetBrains Mono, Fira Code, D2Coding, Menlo, Consolas and Noto Sans Mono CJK KR. Those now draw only if the face does not load. A font typed in Settings still goes first. The icon font and Ovis Hangul Mono keep their places. - **The face comes from the bundled files only** (`fonts/fonts.css`): no `local()` copy, which the app's canvas cannot measure, and a new **bold** (`JetBrainsMono-Bold.woff2`, JetBrains Mono v2.304 unchanged) so bold text is not synthesized. `measurableFontStack` always keeps the face, as it keeps the bundled icon and Hangul faces. - **The grid is measured from the face, never from a fallback.** xterm measures its cell only when the family is set, so the terminal opens without the face while it has not loaded (`openingFontStack`). The font effect (`useTerminalRefits.ts`) then loads the stack and sets it whole, exactly as for a font typed in Settings. If the face is slower than the effect's 3s wait, it is set when it arrives (`monoFaceArrived`, which waits on the face alone: the font set's load for a whole stack rejects as soon as any one face fails). A face that arrives while two fingers pinch keeps the pinch's live size, and the shared pty is sized once, when the fingers lift (`pinchingRef`). - **A new terminal's pane is attached only once its first font is set** (`usePaneAttach.ts`, `fontSettled`). The font effect settles a shared signal after its first apply, which `loadFontStack`'s existing 3s bound already limits, and the first fit and `attach` wait for it. Before, a cold load without an installed JetBrains Mono attached the pty at the fallback's grid. On Linux that was Noto's 19px rows (169x42 in the merge pass's run, 132x35 here). The pty was then resized again when the face arrived (141x47, 110x39), so the program reflowed twice. Now the attach goes out once, at the face's grid. A face slower than 3s still attaches at the fallback's grid and is set when it comes, as before. Without this, the terminal measured a fallback's cell, the face arrived, and xterm re-measured without a refit. In the check below, the grid then ran 1030px wide in an 880px pane. - **License:** `THIRD_PARTY_NOTICES.md` now lists both files under the release's OFL 1.1 text (already included, identical to the release's `OFL.txt`). `DESIGN.md` records the decision. Zed similarly draws its terminal in a face it ships (`.ZedMono`). ## Every surface, measured (13px) Rows are for the same 1200x760 window. The Hangul gap is the row minus the Hangul ink (0.913em = 11.87px). | Surface | Latin face (main → this PR) | Row px | Grid for 120 cols | Hangul gap px | Keystroke-to-paint median ms | Flood fps | |---|---|---|---|---|---|---| | Chrome, Mac, no font installed | Menlo → JetBrains Mono Web | 16.5 → 17 | 939 → 936 | 4.6 → 5.1 | 33.1 → 33.2 | 60.2 → 60.2 | | Safari, Mac, no font installed | Menlo → JetBrains Mono Web | 16.5 → 17 | 939 → 936 | 4.6 → 5.1 | 34 → 49* | 59.5 → 58.5 | | Ovis for Mac, no font installed | Menlo → JetBrains Mono Web | 16.5 → 17 | 939 → 936 | 4.6 → 5.1 | 33 → 33 | 59.8 → 59.0 | | Chrome, Mac, JetBrains Mono installed | JetBrains Mono → JetBrains Mono Web | 17 → 17 | 936 → 936 | 5.1 → 5.1 | 33 → 33.2 | 59.6 → 60.2 | | Safari, Mac, JetBrains Mono installed | Menlo → JetBrains Mono Web | 16.5 → 17 | 939 → 936 | 4.6 → 5.1 | 48 → 35 | 59.8 → 59.4 | | Ovis for Mac, JetBrains Mono installed | Menlo → JetBrains Mono Web | 16.5 → 17 | 939 → 936 | 4.6 → 5.1 | 34 → 33 | 59.8 → 59.6 | | Chrome, Linux (1x and 2x) | Noto Sans Mono CJK KR (19px, from #2243's table) → JetBrains Mono Web | 19 → 17 | - | 6 → 5.1 | - | - | *Safari's median moves between 33 and 49ms from run to run on both builds; Chrome and the app do not. At this window every Mac surface holds 40 rows, before and after. Rows differed before only when the window height fell between 16.5px and 17px steps (a 900px pane: 52 against 54). Now every surface has the same row, so the counts match at any size. A pane on Linux gains rows (19 → 17px); one on a Mac or on Windows with Consolas loses about 3% of them (16.5 → 17px). Windows and the iPhone were not measured in this PR. **Bundle size:** +94,588 bytes (`JetBrainsMono-Bold.woff2`). The regular face (92,164 bytes) was already shipped for the chat. A device now fetches the regular face when the terminal opens (most pages already fetched it for the chrome's code text), and the bold only when bold text is drawn. Both are fingerprinted assets the service worker keeps. ## Before and after (the Mac with JetBrains Mono installed) | | main | this PR | |---|---|---| | Chrome |  |  | | Safari |  |  | | Ovis for Mac |  |  | (The light lines after Korean words in the dark rows are the seam #2263 fixes; this branch does not include it.) ## Checks - **New browser check** `scripts/terminal-bundled-mono-regression.ts` (added to `ci-browser.sh`). It holds the face's download until the terminal has drawn its rows, so the face always arrives late, and checks at 1x and 2x that: - the terminal opened without the face; - the cell is the face's advance (7.79 against 7.80px); - the row is `terminalLineHeight`'s for the face (17px), with a Hangul gap of 5.13px; - the grid fits its host again; - `|가나다라마바사|` closes on the Latin row's column. It also checks the pty: when the face arrives within the font effect's wait, the pane's `attach` frame carries the face's grid (110x39) and no `resize` follows. A slow face sends one resize, for its grid. Frames are counted only after a definite signal: the DOM change made in the same task as the frame (the font family set, the pinch badge hidden) or the attach frame itself. Nothing polls animation frames. It also covers three late cases: - the face is slower than the font effect's wait; - a font typed in Settings fails to load (404) while the face still loads; - the face arrives mid-pinch on a 390x844 touch screen, both when the pinch grew the font (13 → 22px) and when it came back to the saved size. The live size must hold, no resize may be sent while the fingers are down, and exactly one must be sent when they lift. Results: - Passes here. - Fails on main: the face never becomes the terminal's. - Fails on a mutant that opens with the face while it loads: the grid stays 1030px wide in an 880px pane. - Fails on a mutant that waits on the whole stack: the face never applies after the typed font's 404. - Fails on a mutant that ignores the pinch: the size snaps back to 13px from 22. - Fails on a mutant that attaches without waiting for the first font: attached at 132x35, then resized to 110x39. - `scripts/terminal-pinch-regression.ts` still passes. - **Unit tests:** `bun test src/lib/fontFamily.test.ts src/lib/typography.test.ts` cover the new stack order, both weights with no `local()`, `measurableFontStack` keeping the face, and `openingFontStack`. They fail on main. - **`bun run check fast`:** pass (typecheck, build, 8192 unit tests, 0 fail). - **QA:** in a fresh clone in `/tmp` on the test Mac, against an isolated herdr session; a JetBrains Mono installed for the test was removed afterwards. ## Reviews - **omo-native-code-reviewer: PASS (APPROVE)**, with three MEDIUMs, all fixed: - The slow-face path was untested. Now covered by the slow-face case. - A dead `try/catch` around `fonts.check`, with a misnamed test. Both removed. - A late face during a live pinch. Fixed with `pinchingRef`, below. LOW notes fixed: the late-wait comment, and the sourced 0.913 constant in the check. LOW notes left: - Every cold load ends with one forced pty resize once the face is set. This is the same path a font typed in Settings already takes. On Windows it does change the grid, from Consolas to JetBrains Mono. - An unquoted "JetBrains Mono Web" typed in Settings is not recognised as the bundled face. It still draws, but is waited for like any typed font. - typography.test repeats a check of the stack's head. - **Codex (gpt-6.1-sol, fast, xhigh): PASS** on the third pass. - First pass: BLOCK with two MEDIUMs. A late face overwrote an active pinch. The late wait loaded the whole stack, so a typed font's 404 ended it before the face arrived. Fixed with `monoFaceArrived` and a pinch guard. - Second pass: BLOCK with two MEDIUMs. The guard missed the first apply and a pinch at the saved size, which got two resizes. Replaced the guard with an explicit `pinchingRef` shared with the pinch handler. `finishPinch` now sizes the pty once when a pinch that kept its size ends on a different grid. - Third pass on the delta: no findings, including touchcancel, unmount, a chat view taking over, and the Settings handoff. - `bun run check fast` on the final commit: pass (typecheck, build, 8192 unit tests, 0 fail).
…ith main (#2253) Fixes the **Native Windows mirrored terminal** check (`windows-terminal-qa.yml`, from #2211) failing on #2243 and #2242 at `Timed out: new native output after wheel pan` (and an `EBUSY` that hid the error), while it passed on #2246. ## Root cause The workflow checked out `github.event.pull_request.head.sha`. A branch cut before #2211 (524273e) ran **its own old copy** of `scripts/windows-terminal-browser-qa.ts`, against an app that already folds a wide mirrored pane to a phone's width (#1961). #2211 fixed that script in four places: it chooses Original width (`ovis:mirror-wrap` = false), waits for the grid to overflow, places the IME caret by the measured cell width, and retries the EBUSY cleanup. The old copy still has all of them. #2243 (base b48c66a) and #2242 (base 615c92b) predate #2211; #2246 (base 84824f1) does not. The workflow file itself comes from the merge ref, so the job ran on those PRs anyway. Nothing in the product is wrong: the failing PRs tested a stale script. ## Change - `windows-terminal-qa.yml` checks out `${{ github.sha }}`: the pull request's merge with its base, as every job in `ci.yml` does. Schedule and dispatch runs are unchanged (they already fell back to `github.sha`). `windows-install.yml` keeps the head SHA for its own reason (`install.ps1 -Ref` must name the checked-out commit); this workflow builds and runs the checkout in place. - `scripts/ci-setup.test.ts`: the QA job's checkout ref must be `${{ github.sha }}`. It fails on main (`Received: "${{ github.event.pull_request.head.sha || github.sha }}"`) and passes with the change. - `docs/development.md` and a changelog fragment say so. ## Verification Native Windows 11 VM (`winvm`, herdr 0.9.3, Bun 1.4.2), fresh `%TEMP%` clones, through `dori heavy`: | Checkout | Script | Result | | --- | --- | --- | | #2243 head 457f187 | its own (pre-#2211), plus diagnostics | **0/3**: all time out at `new native output after wheel pan` (one hides it behind EBUSY, as on #2242). Diagnostics: herdr's pane shows `PPP…> Q`, while the host has `scrollWidth 390 == clientWidth 390`, so the grid is folded, not at Original width | | #2243 head 457f187 | its own plus only `ovis:mirror-wrap = false` | wheel-pan step **3/3 PASS**; then each run fails at `a visible cursor keeps its composition anchor`, the fixed-52-column bug #2211 also fixed | | `refs/pull/2243/merge` 3493d80 (what this workflow now checks out) | current | **3/3 PASS**, all four PASS lines | | main 5c20a88 | current | **10/10 PASS** in a row, all four PASS lines each | - GitHub runner, all green with four PASS lines: - this PR's own run, which checked out `Merge d1bea76 into adfdef6` (7e74dbd), i.e. the merge: https://github.com/devswha/ovis/actions/runs/40688443672 - a manual dispatch on this branch: https://github.com/devswha/ovis/actions/runs/40688514345 - a manual dispatch on main adfdef6: https://github.com/devswha/ovis/actions/runs/40688525315 - `bun run check fast` green (workflow syntax/actionlint, typecheck, build, unit tests: 8163 pass, 0 fail) on this head, d1bea76. ## Reviews - omo-native-code-reviewer: **PASS**, no CRITICAL/HIGH/MEDIUM. LOW notes, left as is: "Re-run jobs" reuses the original merge commit (as in `ci.yml`; a push or reopen picks up a newer base); "merge with main" is strictly the merge with the base branch (PRs here target main); the test's `!` would throw a TypeError instead of a clean failure if the checkout step were removed, as in its neighbours. - Codex Sol 6.1 Fast xhigh: **PASS**, no findings. Its note: the step still depends on echo and mirror delivery within 15 s, so the same timeout label on a current-base PR would be a new cause (a real regression or a starved runner), not this one.
What it fixes
In Ovis for Mac's terminal, Korean lines nearly touched: wrapped Korean text read as one block while Latin lines looked normal. The owner reported it after #2062 (0.4.19). Reproduced on the test MacBook Air in the real app (released 0.4.19 and main draw the same) on an isolated herdr session and test server, and measured in a WKWebView with the app's configuration and in Chrome on the same Mac.
The cause has two parts, both measured at the default 13px:
glyphFit(lib/terminalGlyphs.ts) enlarges a two-cell glyph that fills less than 90% of its cells. The bundled D2Coding Hangul advances 1em against Menlo's 0.6em cell, so every syllable was drawn at 14.09px (1.084x). Its ink then took 13 to 13.5px of the 15px row, leaving 1.5 to 2px between Korean lines.The change
glyphFit). A wide glyph is stretched horizontally (transform: scaleX, up to 1.1x, the horizontal scaling Korean typesetting calls jangpyeong) to fill its two cells, and its font size grows only past that (the iPhone's narrower Apple SD Gothic Neo still needs 1.2x in total). Letter-spacing, padding and margin are written in the span's own unstretched lengths, so the syllable stays centered and the next span keeps its column (|가나다라마바사|still closes on the Latin row's bar). The IME composition box gets the same fit. Horizontal spacing between syllables is unchanged (median 2.5px, D2Coding's own side bearings).lib/terminalLineHeight.ts). xterm'slineHeightis computed from the Latin line xterm measures (a canvas's font bounding box of "W"). A row is made Hangul's ink (0.913em) plus a gap of 0.35em, rounded to whole device pixels as xterm rounds, and never shorter than the font's own line. It is set again wherever the font's family or size changes: the fit entry, the observe and fixed-grid resets, a pinch, the Settings font effect, and the mount. A fixedlineHeight: 1.1was tried first and dropped: on Linux, where Noto Sans Mono CJK KR's 19px line already leaves Hangul 6px, it took 2 to 3 rows of 35 (3 of 28 at 16px) for nothing (last column of the table).The trade-off, approved by the owner: on devices whose terminal font is Menlo or Consolas (Mac, iPhone at 16px, Windows), a pane holds about a tenth fewer rows. In Ovis for Mac's default 1200x800 window at 13px that is 44 rows down to 40; a 900px-tall terminal goes from 60 to 54. Devices whose Latin line is already tall (Linux with Noto Sans Mono CJK KR, JetBrains Mono typed in Settings, the iPhone at 13px) keep every row.
Before and after (Ovis for Mac, real app on the test Mac)
Every surface, measured
Each surface opened isolated test servers built from main and from this branch, with the terminal font size set in the page's settings before it started, and the same Korean sample in a 1200x760 viewport (the iPhone at its own 402x714). The Hangul line gap is the row height minus the ink of the Hangul as drawn (enlarged on main, widened here).
On the iPhone the pane's grid is the herdr pane's, so rows are given per 640px of screen. Windows Chrome's canvas reports ink in whole pixels, so its gaps are rounded up a little; its rows are the same as the Mac's at each size. A live font change also takes effect: in Windows Chrome, Settings 13px → 16px → 13px redrew rows of 16 → 20 → 16px without a reload.
Design reference
Zed's terminal draws rows taller than its font's line by default (
terminal.line_height"comfortable", 1.618: zed-industries/zed#6096), and Warp defaults to 1.2 (warpdotdev/warp#1294). This PR does not apply one factor everywhere. It sizes the row for Hangul plus a gap, so every device ends up with the same gap (4.1 to 4.7px at 13px, 5.4 to 6px at 16px) and a device whose line is already tall loses nothing. Terminal.app and iTerm2 draw a fallback syllable at its own size and leave the gap beside it; here it keeps its height and is widened into its cells. No external code was adapted.Checks
bun test src/lib/terminalGlyphs.test.ts src/lib/terminalLineHeight.test.ts: pass. NewglyphFitand DOM cases fail on main: the Hangul span came out atfont-size: 14.04pxinstead of ascaleXat 13px, and a syllable with a mark that does not compose (한\u0301) moved the next column on a code-point count.stretchedViewkeeps xterm's move of a long IME composition at the right edge.terminalLineHeightis checked against xterm's own rounding at 8 to 32px and pixel ratios 1 to 3, for both Menlo's and Consolas's lines.bun run check fast: pass on 457f187 (typecheck, build, 8133 unit tests, 0 fail)./tmpon the test Mac (real Ovis.app built from main, pointed at the test servers through a shim home), Windows 11 Chrome, this PC's Linux Chrome and the iOS Simulator (Safari engine), all on an isolated herdr session. No Android device was available. Everything started for it was stopped and removed afterwards.Reviews
omo-native-code-reviewer: PASS. One MEDIUM: the stretched span's margin counted code points instead of characters, which would shift the next column after an emoji with U+FE0F or a mark that does not compose. Fixed in 457f187 (grapheme count, with a regression test that fails on the old count). Three LOW notes, recorded here and not changed:
Codex: BLOCK on the first pass with three MEDIUMs:
stretchedViewwrites xterm's move again with the stretched width. Checked in Chromium (Linux, macOS) and WebKit: the right edge lands on the room left.Re-review of the delta: PASS.