Skip to content

Render at the terminal's real cell pixel size (DPI-aware), with fonts sized to match #18

Open

Description

@planadecu

How rendering is sized now:

  • The canvas is cols*16 × rows*32 px. That's about 1× on a Retina Mac (a cell is about 16×34 device px), so the terminal stretches the image a little.
  • The code comment claims "2x supersample", which is wrong.
  • MAX_PIXELS = 2M (only needed for chafa's WASM) pushes large iTerm2 charts below 1×. For example 200×50 cells becomes 2000×1000 px, which is 10×20 px per cell.
  • renderer.ts sets fontPx = max(10, height/40), so axis labels are about ⅓ of a cell tall, while terminal text is about 0.7 of a cell. Line widths are tripled as a separate workaround.

Proposed fix:

  1. Get the cell size in pixels with CSI 16 t (reply CSI 6;h;w t, supported by kitty, iTerm2, WezTerm, foot and ghostty; check xterm.js). Read the reply before Ink attaches its stdin parser, or it leaks into the app's input like the kitty replies did (Fix kitty reply leak, inline-image cleanup, cursor handling and kitty image IDs #15). Alternatively accept a cellPixelSize/devicePixelRatio prop, with a sensible default of 2 on macOS.
  2. Render at exactly cols*cellW × rows*cellH device pixels so the terminal doesn't resample.
  3. Let uPlot do the scaling. Set the DOM shim's devicePixelRatio before the first import('uplot'): uPlot reads pxRatio once at import, and the shim never fires dppxchange. Then pass CSS-pixel width and height. That replaces the height/40 and width*3 workarounds.
  4. Drop MAX_PIXELS for the PNG path and keep a sane MAX_DIM.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important, schedule soonenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions