{"id":13524515,"url":"https://github.com/8LWXpg/typst-ansi-render","last_synced_at":"2025-04-01T02:31:53.085Z","repository":{"id":169660922,"uuid":"645642253","full_name":"8LWXpg/typst-ansi-render","owner":"8LWXpg","description":"provides a simple way to render text with ANSI escape sequences in typst","archived":false,"fork":false,"pushed_at":"2024-04-14T03:27:38.000Z","size":3404,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-21T12:53:05.284Z","etag":null,"topics":["ansi-colors","typst","typst-package"],"latest_commit_sha":null,"homepage":"","language":"Typst","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/8LWXpg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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}},"created_at":"2023-05-26T05:42:13.000Z","updated_at":"2024-06-04T13:57:59.013Z","dependencies_parsed_at":null,"dependency_job_id":"f76052fe-3862-4d7f-99bc-48d826d07267","html_url":"https://github.com/8LWXpg/typst-ansi-render","commit_stats":null,"previous_names":["8lwxpg/typst-ansi_render","8lwxpg/typst-ansi-render"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8LWXpg%2Ftypst-ansi-render","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8LWXpg%2Ftypst-ansi-render/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8LWXpg%2Ftypst-ansi-render/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8LWXpg%2Ftypst-ansi-render/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/8LWXpg","download_url":"https://codeload.github.com/8LWXpg/typst-ansi-render/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222693039,"owners_count":17024034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ansi-colors","typst","typst-package"],"created_at":"2024-08-01T06:01:10.844Z","updated_at":"2025-04-01T02:31:53.077Z","avatar_url":"https://github.com/8LWXpg.png","language":"Typst","funding_links":[],"categories":["Templates \u0026 Libraries"],"sub_categories":["Formatting"],"readme":"# ANSI Escape Sequence Renderer\r\n\r\n\u003ca href=\"https://github.com/8LWXpg/typst-ansi-render/tags\" style=\"text-decoration: none;\"\u003e\r\n  \u003cimg alt=\"GitHub manifest version (path)\" src=\"https://img.shields.io/github/v/tag/8LWXpg/typst-ansi-render\"\u003e\r\n\u003c/a\u003e\r\n\u003ca href=\"https://github.com/8LWXpg/typst-ansi-render\" style=\"text-decoration: none;\"\u003e\r\n  \u003cimg src=\"https://img.shields.io/github/stars/8LWXpg/typst-ansi-render?style=flat\" alt=\"GitHub Repo stars\"\u003e\r\n\u003c/a\u003e\r\n\u003ca href=\"https://github.com/8LWXpg/typst-ansi-render/blob/master/LICENSE\" style=\"text-decoration: none;\"\u003e\r\n  \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/8LWXpg/typst-ansi-render\"\u003e\r\n\u003c/a\u003e\r\n\u003ca href=\"https://github.com/typst/packages/tree/main/packages/preview/ansi-render\" style=\"text-decoration: none;\"\u003e\r\n  \u003cimg alt=\"typst package\" src=\"https://img.shields.io/badge/typst-package-239dad\"\u003e\r\n\u003c/a\u003e\r\n\r\nThis script provides a simple way to render text with ANSI escape sequences. Package `ansi-render` provides a function `ansi-render`, and a dictionary of themes `terminal-themes`.\r\n\r\ncontribution is welcomed!\r\n\r\n## Usage\r\n\r\n```typst\r\n#import \"@preview/ansi-render:0.8.0\": *\r\n\r\n#ansi-render(\r\n  string,\r\n  font:           string or none,\r\n  size:           length,\r\n  width:          auto or relative length,\r\n  height:         auto or relative length,\r\n  breakable:      boolean,\r\n  radius:         relative length or dictionary,\r\n  inset:          relative length or dictionary,\r\n  outset:         relative length or dictionary,\r\n  spacing:        relative length or fraction,\r\n  above:          relative length or fraction,\r\n  below:          relative length or fraction,\r\n  clip:           boolean,\r\n  bold-is-bright: boolean,\r\n  theme:          terminal-themes.theme,\r\n)\r\n```\r\n\r\n### Parameters\r\n\r\n- `string` - string with ANSI escape sequences\r\n- `font` - font name or none, default is `Cascadia Code`, set to `none` to use the same font as `raw`\r\n- `size` - font size, default is `1em`\r\n- `bold-is-bright` - boolean, whether bold text is rendered with bright colors, default is `false`\r\n- `theme` - theme, default is `vscode-light`\r\n- parameters from [`block`](https://typst.app/docs/reference/layout/block/) function with the same default value, only affects outmost block layout:\r\n  - `width`\r\n  - `height`\r\n  - `breakable`\r\n  - `radius`\r\n  - `inset`\r\n  - `outset`\r\n  - `spacing`\r\n  - `above`\r\n  - `below`\r\n  - `clip`\r\n\r\n## Themes\r\n\r\nsee [themes](https://github.com/8LWXpg/typst-ansi-render/blob/master/test/themes.pdf)\r\n\r\n## Demo\r\n\r\nsee [demo.typ](https://github.com/8LWXpg/typst-ansi-render/blob/master/test/demo.typ) [demo.pdf](https://github.com/8LWXpg/typst-ansi-render/blob/master/test/demo.pdf)\r\n\r\n```typst\r\n#ansi-render(\r\n\"\\u{1b}[38;2;255;0;0mThis text is red.\\u{1b}[0m\r\n\\u{1b}[48;2;0;255;0mThis background is green.\\u{1b}[0m\r\n\\u{1b}[38;2;255;255;255m\\u{1b}[48;2;0;0;255mThis text is white on a blue background.\\u{1b}[0m\r\n\\u{1b}[1mThis text is bold.\\u{1b}[0m\r\n\\u{1b}[4mThis text is underlined.\\u{1b}[0m\r\n\\u{1b}[38;2;255;165;0m\\u{1b}[48;2;255;255;0mThis text is orange on a yellow background.\\u{1b}[0m\",\r\ninset: 5pt, radius: 3pt,\r\ntheme: terminal-themes.vscode\r\n)\r\n```\r\n\r\n![1.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/1.png?raw=true)\r\n\r\n```typst\r\n#ansi-render(\r\n\"\\u{1b}[38;5;196mRed text\\u{1b}[0m\r\n\\u{1b}[48;5;27mBlue background\\u{1b}[0m\r\n\\u{1b}[38;5;226;48;5;18mYellow text on blue background\\u{1b}[0m\r\n\\u{1b}[7mInverted text\\u{1b}[0m\r\n\\u{1b}[38;5;208;48;5;237mOrange text on gray background\\u{1b}[0m\r\n\\u{1b}[38;5;39;48;5;208mBlue text on orange background\\u{1b}[0m\r\n\\u{1b}[38;5;255;48;5;0mWhite text on black background\\u{1b}[0m\",\r\ninset: 5pt, radius: 3pt,\r\ntheme: terminal-themes.vscode\r\n)\r\n```\r\n\r\n![2.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/2.png?raw=true)\r\n\r\n```typst\r\n#ansi-render(\r\n\"\\u{1b}[31;1mHello \\u{1b}[7mWorld\\u{1b}[0m\r\n\r\n\\u{1b}[53;4;36mOver  and \\u{1b}[35m Under!\r\n\\u{1b}[7;90mreverse\\u{1b}[101m and \\u{1b}[94;27mreverse\",\r\ninset: 5pt, radius: 3pt,\r\ntheme: terminal-themes.vscode\r\n)\r\n```\r\n\r\n![3.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/3.png?raw=true)\r\n\r\n```typst\r\n// uses the font that supports ligatures\r\n#ansi-render(read(\"./test/test.txt\"), inset: 5pt, radius: 3pt, font: \"Cascadia Code\", theme: terminal-themes.putty)\r\n```\r\n\r\n![4.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/4.png?raw=true)\r\n\r\n## Capturing ANSI output\r\n\r\n### Output to File\r\n\r\nThe most straight forward way is writing to a file then read that in Typst.\r\n\r\n```bash\r\ncommand \u003e out.txt\r\n```\r\n\r\n### Other Method\r\n\r\nIf writing to a file doesn't work, that means the program will detect the output and trim ANSI sequence accordingly, which means we need a pty interface to execute the script, the following should work in Linux:\r\n\r\n```bash\r\nscript \"command\" out.txt\r\nexit\r\n```\r\n\r\n## About Default Font\r\n\r\nTypst's default font for `raw` is `Dejavu Sans Mono`, but it has [incorrect top-edge](https://github.com/typst/typst/issues/2231), so the default is set to `Cascadia Code`, which is included in web editor.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8LWXpg%2Ftypst-ansi-render","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F8LWXpg%2Ftypst-ansi-render","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8LWXpg%2Ftypst-ansi-render/lists"}