diff --git a/assets/preview.png b/assets/preview.png index 572a255..c7e0bc4 100644 Binary files a/assets/preview.png and b/assets/preview.png differ diff --git a/assets/screenshots/cmdline.png b/assets/screenshots/cmdline.png index 5f73989..8660c21 100644 Binary files a/assets/screenshots/cmdline.png and b/assets/screenshots/cmdline.png differ diff --git a/assets/screenshots/completion.png b/assets/screenshots/completion.png index 6d635fe..95b9f0e 100644 Binary files a/assets/screenshots/completion.png and b/assets/screenshots/completion.png differ diff --git a/assets/screenshots/dashboard.png b/assets/screenshots/dashboard.png index 283b1db..0708689 100644 Binary files a/assets/screenshots/dashboard.png and b/assets/screenshots/dashboard.png differ diff --git a/assets/screenshots/markdown.png b/assets/screenshots/markdown.png index 9df1f23..d333398 100644 Binary files a/assets/screenshots/markdown.png and b/assets/screenshots/markdown.png differ diff --git a/assets/screenshots/telescope.png b/assets/screenshots/telescope.png index 70e492a..ac02f8b 100644 Binary files a/assets/screenshots/telescope.png and b/assets/screenshots/telescope.png differ diff --git a/assets/screenshots/whichkey.png b/assets/screenshots/whichkey.png index 4351477..d072541 100644 Binary files a/assets/screenshots/whichkey.png and b/assets/screenshots/whichkey.png differ diff --git a/scripts/render/page.ts b/scripts/render/page.ts index cf25cef..a419845 100644 --- a/scripts/render/page.ts +++ b/scripts/render/page.ts @@ -1,6 +1,13 @@ /** * Draws a Neovim screen as HTML: every run of cells is placed on the exact * cell grid, so glyphs from fallback fonts (Nerd Font icons) cannot drift. + * + * Backgrounds go in a layer below all text, as in a terminal. Nerd Font + * icons are wider than a cell (1em against JetBrains Mono's 0.6em) and + * spill into the next one, which is usually a space; drawn in one layer, + * that cell's background would cover the icon's right half. Each icon is + * centered on its own cell and overflows evenly into the cells on either + * side; `text-align: center` would start-align it once it overflows. */ import { readFileSync } from "node:fs"; import type { Attr, Screen } from "./ui.ts"; @@ -27,13 +34,14 @@ const esc = (s: string) => s.replace(/&/g, "&").replace(/ /^[ -ɏ─-▟]$/.test(t); -function style(attr: Attr, screen: Screen, cursor = false): string { +/** CSS for a run of cells: `text` for the glyphs, `bg` for its background layer, if any. */ +function style(attr: Attr, screen: Screen, cursor = false): { text: string; bg?: string } { const d = screen.defaults; let fg = attr.foreground ?? d.fg; let bg = attr.background ?? d.bg; if (Boolean(attr.reverse) !== cursor) [fg, bg] = [bg, fg]; const css = [`color:${hex(fg)}`]; - if (bg !== d.bg || attr.reverse || cursor) css.push(`background:${hex(bg)}`); + const background = bg !== d.bg || attr.reverse || cursor ? `background:${hex(bg)}` : undefined; if (attr.bold) css.push("font-weight:700"); if (attr.italic) css.push("font-style:italic"); const lines: string[] = []; @@ -51,20 +59,30 @@ function style(attr: Attr, screen: Screen, cursor = false): string { "text-underline-offset:3px", ); } - return css.join(";"); + return { text: css.join(";"), bg: background }; } function span(row: number, col: number, width: number, text: string, css: string, cls = "") { return `${esc(text)}`; } +function box(row: number, col: number, width: number, css: string) { + return `
`; +} + export function screenHtml( screen: Screen, fonts: Fonts, frame: Frame, showCursor: boolean, ): string { + const backgrounds: string[] = []; const parts: string[] = []; + const run = (row: number, col: number, width: number, text: string, attr: Attr, cls = "") => { + const css = style(attr, screen); + if (css.bg) backgrounds.push(box(row, col, width, css.bg)); + if (text !== "") parts.push(span(row, col, width, text, css.text, cls)); + }; screen.cells.forEach((cells, r) => { let c = 0; while (c < cells.length) { @@ -74,7 +92,7 @@ export function screenHtml( if (!simple(cell.text)) { const wide = cells[c + 1]?.text === ""; const width = wide ? 2 : 1; - if (cell.text !== "") parts.push(span(r, c, width, cell.text, style(attr, screen), " g")); + run(r, c, width, cell.text, attr, " g"); c += width; continue; } @@ -86,7 +104,7 @@ export function screenHtml( text += next.text; end++; } - parts.push(span(r, c, end - c, text, style(attr, screen))); + run(r, c, end - c, text, attr); c = end; } }); @@ -108,11 +126,21 @@ export function screenHtml( : `top:${(row + 1) * LH - LH * pct}px;left:${col * CW}px;width:${CW}px;height:${LH * pct}px`; parts.push(`
`); } else if (cell) { + // Drawn last, background included, so it covers whatever spills into its cell. const css = own?.background !== undefined ? style({ ...colors, reverse: true }, screen, false) : style(colors, screen, true); - parts.push(span(row, col, 1, cell.text || " ", css, simple(cell.text) ? "" : " g")); + parts.push( + span( + row, + col, + 1, + cell.text || " ", + [css.text, css.bg].filter(Boolean).join(";"), + simple(cell.text) ? "" : " g", + ), + ); } } @@ -139,12 +167,13 @@ body { padding: 40px; width: max-content; } .grid { position: relative; width: ${screen.cols * CW}px; height: ${screen.rows * LH}px; font: ${SIZE}px/${LH}px "JetBrains Mono", "Symbols Nerd Font Mono", monospace; font-variant-ligatures: none; } .c { position: absolute; height: ${LH}px; white-space: pre; overflow: visible; } -.g { font-family: "Symbols Nerd Font Mono", "JetBrains Mono", monospace; text-align: center; } +.g { font-family: "Symbols Nerd Font Mono", "JetBrains Mono", monospace; display: flex; justify-content: center; } +.b { position: absolute; height: ${LH}px; } .cursor { position: absolute; }
${dots.map((d) => ``).join("")}
${esc(frame.title)}
-
${parts.join("")}
+
${backgrounds.join("")}${parts.join("")}
`; } diff --git a/scripts/render/sample/pyproject.toml b/scripts/render/sample/pyproject.toml index feb2114..3afb980 100644 --- a/scripts/render/sample/pyproject.toml +++ b/scripts/render/sample/pyproject.toml @@ -7,5 +7,8 @@ dependencies = [] [tool.ruff] line-length = 100 +[tool.ruff.lint] +extend-select = ["DTZ"] + [tool.pytest.ini_options] testpaths = ["tests"]