Wombat is a Crystal binding for the well-known bat syntax highlighting library. bat is a cat(1) clone with wings, popular among developers for its syntax highlighting capabilities. With Wombat, you can utilize bat's syntax highlighting functionality directly within your Crystal applications.
- bat: A well-known
cat(1)clone with syntax highlighting capabilities. - bat-c: A C wrapper for the
batlibrary.
-
Add the dependency to your
shard.yml:dependencies: wombat: github: kojix2/wombat
-
Install the dependencies:
shards install
During installation, a postinstall script will automatically download the latest version of the bat-c static library into the src/ext directory.
Version Managementß
- Wombat always uses the latest release of
bat-cfrom bat-c releases. - Check the installed version:
Wombat.bat_c_version - Update to the latest version:
crystal run scripts/download_bat_c_static_library.cr
Retrieve and output a syntax highlighted string:
require "wombat"
highlighted = Wombat.pretty_string(%{puts "hello world"})
puts highlightedOutput the contents of a file with syntax highlighting. bat will automatically invoke less:
require "wombat"
Wombat.pretty_print_file("/path/to/your_file.cr")Handle potential errors when processing files:
require "wombat"
begin
Wombat.pretty_print_file("/path/to/file.cr")
rescue ex : Wombat::Error
puts "Error: #{ex.message}"
endFor more details, refer to the API Documentation.
Sustainable development is important. If you encounter any issues or have suggestions for improvement, please contribute!
Your contributions are always welcome! Feel free to raise issues, submit pull requests, or suggest new features.


