{"id":13621321,"url":"https://github.com/wader/ansisvg","last_synced_at":"2025-09-14T23:17:08.730Z","repository":{"id":57633174,"uuid":"411973374","full_name":"wader/ansisvg","owner":"wader","description":"Convert ANSI to SVG","archived":false,"fork":false,"pushed_at":"2024-12-18T08:42:37.000Z","size":3675,"stargazers_count":104,"open_issues_count":5,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-08T11:57:05.227Z","etag":null,"topics":["ansi","golang","svg"],"latest_commit_sha":null,"homepage":"","language":"Go","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/wader.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2021-09-30T07:54:20.000Z","updated_at":"2025-08-17T20:16:48.000Z","dependencies_parsed_at":"2023-12-14T10:40:21.628Z","dependency_job_id":"9289307e-d7da-41cf-8b24-9952b3640291","html_url":"https://github.com/wader/ansisvg","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/wader/ansisvg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wader%2Fansisvg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wader%2Fansisvg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wader%2Fansisvg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wader%2Fansisvg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wader","download_url":"https://codeload.github.com/wader/ansisvg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wader%2Fansisvg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275180244,"owners_count":25419075,"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","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ansi","golang","svg"],"created_at":"2024-08-01T21:01:04.730Z","updated_at":"2025-09-14T23:17:08.708Z","avatar_url":"https://github.com/wader.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# ansisvg\n\nConvert [ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code) to [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics).\n\nPipe output from a program thru `ansisvg` and it will output a SVG file on stdout.\n\nCan be used to produce nice looking example output for presentations, markdown files etc. Note that it\ndoes not support programs that do cursor movements like ncurses programs etc.\n\n```sh\n./colortest | ansisvg \u003e colortest.svg\n ```\nProduces [colortest.svg](cli/testdata/colortest.svg):\n\n![ansisvg output for colortest](cli/testdata/colortest.svg)\n\n```\n$ ansisvg -h\nansisvg - Convert ANSI to SVG\nUsage: ansisvg [FLAGS]\n\nExample usage:\n  program | ansisvg \u003e file.svg\n\n--charboxsize WxH   Character box size (use pixel units instead of font units)\n--colorscheme NAME  Color scheme\n--fontfile PATH     Font file to use and embed\n--fontname NAME     Font name\n--fontref URL       External font URL to use\n--fontsize NUMBER   Font size\n--grid              Grid mode (sets position for each character)\n--help, -h          Show help\n--listcolorschemes  List color schemes\n--marginsize WxH    Margin size (in either pixel or font units)\n--transparent       Transparent background\n--version, -v       Show version\n--width, -w NUMBER  Terminal width (auto if not set)\n```\n\nColor themes are the ones from https://github.com/mbadolato/iTerm2-Color-Schemes\n\n## Install\n\nPre-built binaries for Linux, macOS and Windows can be downloaded from [releases](https://github.com/wader/ansisvg/releases).\n\n### macOS\n\nFor macOS you might have to allow to run the binary in security preferences. Alternatively run the below command:\n\n```sh\nxattr -d com.apple.quarantine ansisvg \u0026\u0026 spctl --add ansisvg\n```\n\n## Build\n\nTo build you will need at least go 1.18 or later.\n\nInstall latest master and copy it to `/usr/local/bin`:\n```sh\ngo install github.com/wader/ansisvg@master\ncp $(go env GOPATH)/bin/ansisvg /usr/local/bin\n```\n\nBuild from cloned repo:\n```\ngo build -o ansisvg .\n```\n\n## Fonts\n\n`ansisvg` can either use system-installed fonts (`-fontname`), link to a webfont on a HTTP server (`-fontref`) or embed a webfont from the local filesystem (`-fontfile`).\n\n### Compatibility issues\n\n* Embedded and/or linked fonts might not be supported by some SVG viewers. At time of writing this is [not supported by Inkscape](https://gitlab.com/inkscape/inbox/-/issues/301).\n\n* For SVGs that are intended to be included in websites via `\u003cimg\u003e`, the only way to make a custom font work is [embedding it in the SVG](https://vecta.io/blog/how-to-use-fonts-in-svg).\n\n### Variations of custom fonts (regular/bold/italic)\n\n* System wide fonts (`-fontname`) get correctly rendered with variations, but when using external fonts with `-fontref` or `-fontfile` the SVG viewer knows only the regular variant and will try to render italic/bold text 'extrapolated' from it which may look different than the actual font variation. To use the actual bold/italic font variants, different woff2 files have to be used for the respective text styles which needs additional CSS code (currently not supported by `ansisvg`).\n\n* Bold style 'extrapolated' from the regular font may even break monospace alignment. Use `-grid` option to mitigate that.\n\n## Font-relative vs. pixel coordinates\n\nBy default, `ansisvg` uses font-relative `ch`/`em` coordinates. This should make SVG dimensions and line/character spacing consistent with font family/size. When SVG dimensions and/or text coordinates are off, it is possible to force explicit pixel units for coordinates by specifying `-charboxsize` in X/Y pixel units, e.g. `8x16`.\n\n* Inkscape currently [cannot deal with SVG size expressed in font-relative units](https://gitlab.com/inkscape/inkscape/-/issues/4737), a quick workaround is Ctrl-Shift-R (resize page to content).\n\n* Some SVG processing tools like [asciidoctor](https://docs.asciidoctor.org/pdf-converter/latest/image-paths-and-formats/#image-formats) require the presence of the `viewBox` attribute. Use `-charboxsize` option to enable this attribute (it only works with pixel dimensions).\n\n## Margin size\n\nWith `--marginsize` a margin can be defined, so there is a bit of empty space (or \"border\") around the image. Default is zero margin size, i.e. the terminal characters are touching the edge of the image.\n`--marginsize` is interpreted as X/Y in the currently selected units, i.e. `ch`/`em` by default, and `px` if `--charboxsize` is used.\n\n## Consolidated text vs. grid mode\n\nBy default, `ansisvg` consolidates text to `\u003ctspan\u003e` chunks, leaving the X positioning of characters to the SVG renderer. This usually works well for monospace fonts. However if not all glyphs involved are monospace (e.g. when exotic characters are used, making the SVG renderer fall back to a different font for those characters) then the alignment will be off; this can be worked around with `-grid` mode which will make `ansisvg` put each character to explicit positions, making the SVG bigger and less readable but ensuring proper positioning/alignment for all characters.\n\n## Tricks\n\n### ANSI to PDF or PNG\n\n```\n... | ansisvg | inkscape --pipe --export-type=pdf -o file.pdf\n... | ansisvg | inkscape --pipe --export-type=png -o file.png\n```\n\n\n### Use `bat` to produce source code highlighting\n\n```\nbat --color=always -p main.go | ansisvg\n```\n\n### Use `script` to run with a pty\n\n```\nscript -q /dev/null \u003ccommand\u003e | ansisvg\n```\n\n### ffmpeg\n\n```\nTERM=a AV_LOG_FORCE_COLOR=1 ffmpeg ... 2\u003e\u00261 | ansisvg\n```\n\n### jq\n```\njq -C | ansisvg\n```\n\n### Make screenshots from a terminal\n\n#### tmux\n\n```\n# \u003cprefix\u003e-H: Create a SVG screenshot of the current pane\nbind H capture-pane -e \\; run \"tmux save-buffer - | $HOME/go/bin/ansisvg \u003e $HOME/Pictures/tmux-$(date +%F_%T).svg\"; delete-buffer\n```\n\n#### kitty\n\n```\n# F3: Create a SVG screenshot of the current selection\nmap f3 combine : copy_ansi_to_clipboard : launch sh -c 'kitty +kitten clipboard -g | $HOME/go/bin/ansisvg \u003e $HOME/Pictures/kitty-$(date +%F_%T).svg'\n```\n\n## Development and release build\n\nRun all tests and write new test output:\n```\ngo test ./... -update\n```\n\nManual release build with version can be done with:\n```\ngo build -ldflags \"-X main.version=1.2.3\" -o ansisvg .\n```\n\nVisual inspect test output in browser:\n```\nfor i in cli/testdata/*.svg; do echo \"$i\u003cbr\u003e\u003cimg src=\\\"$i\\\"/\u003e\u003cbr\u003e\" ; done  \u003e all.html\nopen all.html\n```\n\nUsing [ffcat](https://github.com/wader/ffcat):\n```\nfor i in cli/testdata/*.ansi; do echo $i ; cat $i | go run . | ffcat ; done\n```\n\n## Thanks\n\n- Patrick Huesmann [@patrislav1](https://github.com/patrislav1) for better ANSI support and lots SVG output improvements.\n\n## Licenses and thanks\n\nColor themes from\nhttps://github.com/mbadolato/iTerm2-Color-Schemes,\nlicense https://github.com/mbadolato/iTerm2-Color-Schemes/blob/master/LICENSE\n\nUses colortest from https://github.com/pablopunk/colortest and terminal-colors from https://github.com/eikenb/terminal-colors.\n\n UbuntuMonoNerdFontMono-Regular.woff2 from https://github.com/ryanoasis/nerd-fonts license https://github.com/ryanoasis/nerd-fonts/blob/master/LICENSE\n\n## TODO and ideas\n- Underline overlaps a bit, sometimes causing weird blending\n- Handle vertical tab and form feed (normalize into spaces?)\n- Handle overdrawing\n- More CSI, keep track of cursor?\n- PNG output (embed nice fonts?)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwader%2Fansisvg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwader%2Fansisvg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwader%2Fansisvg/lists"}