github.com/dsisnero/ansi
main / published Feb 23, 2026 / repository
Port of golang ansi library
ansi
ansi is a Crystal library for generating and parsing ANSI terminal escape
sequences. It is a Crystal port of x/ansi (Go) and includes helpers for
colors, styles, cursor control, modes, mouse/keyboard protocols, images
(Kitty, iTerm2, Sixel), and sequence parsing/decoding utilities.
Installation
-
Add the dependency to your
shard.yml:dependencies: ansi: github: dsisnero/ansi -
Run
shards install
Usage
require "ansi"
Examples:
# Colors and styles
puts Ansi.sgr(Ansi::AttrBold, Ansi::AttrBlueForegroundColor) + "Hello" + Ansi::ResetStyle
# Cursor movement
print Ansi.cursor_up(2)
print Ansi.cursor_forward(10)
# Clipboard
print Ansi.set_system_clipboard("hello")
# Kitty graphics
payload = "...".to_slice
print Ansi.kitty_graphics(payload)
Development
Run specs:
crystal spec
Contributing
- Fork it (https://github.com/dsisnero/ansi/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- your-name-here - creator and maintainer
API
- Ansi
- UnicodeCharWidth
Provides methods to get fixed width of the unicode character or string.