{"id":49060593,"url":"https://github.com/ShipItAndPray/pretext-terminal","last_synced_at":"2026-05-06T06:01:36.794Z","repository":{"id":347943197,"uuid":"1195824858","full_name":"ShipItAndPray/pretext-terminal","owner":"ShipItAndPray","description":"Virtualized terminal UI for React with Pretext-aware layout and canvas rendering.","archived":false,"fork":false,"pushed_at":"2026-04-02T06:17:19.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-04T17:14:26.383Z","etag":null,"topics":["pretext","text-layout","typescript","typography"],"latest_commit_sha":null,"homepage":"https://shipitandpray.github.io/pretext-terminal/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShipItAndPray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-30T05:16:17.000Z","updated_at":"2026-04-03T04:32:24.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ShipItAndPray/pretext-terminal","commit_stats":null,"previous_names":["shipitandpray/pretext-terminal"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ShipItAndPray/pretext-terminal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-terminal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-terminal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-terminal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-terminal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShipItAndPray","download_url":"https://codeload.github.com/ShipItAndPray/pretext-terminal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-terminal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32680890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T02:33:58.958Z","status":"ssl_error","status_checked_at":"2026-05-06T02:33:39.611Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pretext","text-layout","typescript","typography"],"created_at":"2026-04-20T02:00:28.099Z","updated_at":"2026-05-06T06:01:36.196Z","avatar_url":"https://github.com/ShipItAndPray.png","language":"TypeScript","funding_links":[],"categories":["Flagship Ecosystem Packages"],"sub_categories":[],"readme":"# @shipitandpray/pretext-terminal\n\nVirtualized terminal UI for React, backed by Pretext-aware monospace layout and canvas rendering.\n\nThis package is designed for log-heavy terminal views where DOM-row terminals become expensive. It keeps terminal lines in a scrollback buffer, parses ANSI styling into spans, virtualizes the visible region, and paints the current window to a canvas.\n\n## Why this package exists\n\nTraditional browser terminals tend to degrade when scrollback gets large because they keep too much DOM around. This package takes a different route:\n\n- store terminal output in a buffer\n- precompute monospace layout assumptions\n- render only the visible window\n- paint text and backgrounds to canvas\n\nThat makes it a better fit for:\n\n- build logs\n- CI output viewers\n- developer tools\n- internal dashboards with long-running process streams\n\n## Features\n\n- `Terminal` React component\n- `TerminalCore` framework-agnostic write/buffer engine\n- ANSI span parser for common SGR color/style sequences\n- line scrollback buffer\n- visible-window virtualizer\n- canvas renderer for foreground, background, underline, and strike styles\n- small helpers for keyboard input, link detection, clipboard, and buffer search\n\n## Install\n\n```bash\nnpm install @shipitandpray/pretext-terminal @chenglou/pretext react\n```\n\n## Demo\n\nLive demo:\n\n- `https://shipitandpray.github.io/pretext-terminal/`\n\nThe demo includes:\n\n- a terminal panel with ANSI-colored sample output\n- a fast synthetic log burst\n- interactive input forwarding\n- a scrollback view large enough to demonstrate virtualization\n\n## Quick start\n\n```tsx\nimport { useRef } from \"react\";\nimport { Terminal, type TerminalHandle } from \"@shipitandpray/pretext-terminal\";\n\nexport function BuildLog() {\n  const terminalRef = useRef\u003cTerminalHandle\u003e(null);\n\n  return (\n    \u003cTerminal\n      ref={terminalRef}\n      width={900}\n      height={520}\n      onData={(data) =\u003e {\n        console.log(\"send to PTY\", data);\n      }}\n      lines={[\n        \"\\u001b[32mready\\u001b[0m server booted\",\n        \"\\u001b[33mwarn\\u001b[0m cache is warm\",\n        \"\\u001b[31merror\\u001b[0m worker exited\"\n      ]}\n    /\u003e\n  );\n}\n```\n\n## API\n\n### `Terminal`\n\nThe main React component.\n\nProps:\n\n- `lines`\n- `onData`\n- `cols`\n- `rows`\n- `font`\n- `lineHeight`\n- `maxScrollback`\n- `theme`\n- `className`\n- `width`\n- `height`\n\n### `TerminalHandle`\n\nImperative methods exposed through `ref`:\n\n- `write(data)`\n- `writeln(data)`\n- `clear()`\n- `scrollToBottom()`\n- `scrollToTop()`\n- `getSelection()`\n- `focus()`\n\n### `TerminalCore`\n\nFramework-agnostic core that owns:\n\n- line buffering\n- ANSI parsing\n- layout assumptions\n- visible line access\n\nUse this if you want the buffer and parser without the React wrapper.\n\n### `parseAnsi(line, theme)`\n\nParses ANSI SGR color/style escape sequences into styled spans. The current implementation covers the most common text styling sequences:\n\n- reset\n- foreground colors\n- background colors\n- bold\n- italic\n- underline\n- strikethrough\n\n### `getVisibleWindow(lineCount, rowHeight, scrollTop, viewportHeight, overscan?)`\n\nReturns the visible start and end line indices for a scroll position.\n\n### `searchBuffer(lines, query)`\n\nFinds case-insensitive matches in scrollback lines.\n\n## Architectural notes\n\nThis package assumes a monospace font and uses that to simplify layout:\n\n- one measured character width\n- one row height\n- predictable columns\n\nPretext still matters because it keeps text measurement grounded in a real font configuration instead of hardcoded guesses. The current implementation uses it to anchor the monospace layout setup while keeping the render loop canvas-first.\n\n## Rendering model\n\nThe rendering path is:\n\n1. parse incoming text into ANSI spans\n2. append parsed lines to scrollback\n3. compute visible range from scroll state\n4. paint only visible rows to canvas\n\nThat means scrolling is mostly a viewport problem rather than a DOM problem.\n\n## PTY / WebSocket integration\n\nThis package does not ship a PTY server. The expected integration is:\n\n- connect your backend PTY or WebSocket stream\n- call `write()` or update `lines`\n- forward keyboard data through `onData`\n\nThat keeps the package browser-focused and easy to embed in existing tooling.\n\n## Local development\n\n```bash\nnpm install\nnpm run check\nnpm run build\nnpm test\n```\n\n## GitHub Pages deployment\n\nThe repo includes a Pages workflow that:\n\n1. installs dependencies\n2. builds the package\n3. publishes a static demo using the built output\n\n## Limitations\n\n- ANSI support is focused on common SGR styling, not every control sequence.\n- The current renderer assumes monospace text.\n- Selection and mouse behavior are intentionally lightweight in this first pass.\n- The demo simulates process output locally rather than connecting to a real PTY server.\n\n## Good fits\n\nUse this package for:\n\n- build log viewers\n- internal CI dashboards\n- server console panes\n- long-running process monitors\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShipItAndPray%2Fpretext-terminal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShipItAndPray%2Fpretext-terminal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShipItAndPray%2Fpretext-terminal/lists"}