{"id":17220826,"url":"https://github.com/kojix2/bat-c","last_synced_at":"2026-03-06T20:03:38.995Z","repository":{"id":251467737,"uuid":"837472425","full_name":"kojix2/bat-c","owner":"kojix2","description":"C API for bat","archived":false,"fork":false,"pushed_at":"2026-01-01T08:39:04.000Z","size":353,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-06T02:18:11.050Z","etag":null,"topics":["c","rust","syntax-highlighting"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/kojix2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2024-08-03T04:50:34.000Z","updated_at":"2026-01-01T08:39:07.000Z","dependencies_parsed_at":"2024-12-03T11:42:04.846Z","dependency_job_id":"c110bad4-bfac-4f64-ab82-a052ddc673ca","html_url":"https://github.com/kojix2/bat-c","commit_stats":null,"previous_names":["kojix2/bat-c"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/kojix2/bat-c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbat-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbat-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbat-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbat-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kojix2","download_url":"https://codeload.github.com/kojix2/bat-c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fbat-c/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30195571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["c","rust","syntax-highlighting"],"created_at":"2024-10-15T03:53:20.242Z","updated_at":"2026-03-06T20:03:38.986Z","avatar_url":"https://github.com/kojix2.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bat-c\n\n[![test](https://github.com/kojix2/bat-c/actions/workflows/test.yml/badge.svg)](https://github.com/kojix2/bat-c/actions/workflows/test.yml)\n[![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Fbat-c%2Flines)](https://tokei.kojix2.net/github/kojix2/bat-c)\n\nProvides a C API for [bat](https://github.com/sharkdp/bat), enabling its use from various programming languages via FFI.\n\n![screenshot](screenshot.png)\n\n## Installation\n\nDownload binaries from [GitHub Releases](https://github.com/kojix2/bat-c/releases).\n\nFrom source code:\n\n```sh\ngit clone https://github.com/kojix2/bat-c\ncd bat-c\ncargo build --release\n# target/release/libbat_c.so (Linux), libbat_c.dylib (macOS), bat_c.dll (Windows)\n```\n\n**Note for macOS users:**  \nThe library is built with `rpath = true`, so the `.dylib` uses `@rpath` for loading. If you extract the release archive and use it directly from that directory, it should work without additional setup. If you install the library to a system directory (e.g., `/usr/local/lib`), ensure the directory is in your `@rpath` or set `DYLD_LIBRARY_PATH` accordingly.\n\n## API Reference\n\nSee [`bat.h`](bat.h) for detailed documentation including:\n- Parameter requirements for each `BatInputType`\n- Valid values for `wrapping_mode` (0=NoWrapping, 1=Character) and `paging_mode` (0=Never, 1=Always, 2=QuitIfOneScreen)\n- Memory safety requirements and proper usage of `bat_free_string`\n- Error handling (functions return 0 on success, 1 on error; error details are printed to stderr)\n\n### C API Overview\n\n```c\n/**\n * BatInputType enum to specify the type of input\n */\ntypedef enum BatInputType {\n  BatBytes,\n  BatFile,\n  BatFiles,\n} BatInputType;\n\n/**\n * Struct to hold print options\n */\ntypedef struct BatPrintOptions {\n  size_t tab_width;\n  bool colored_output;\n  bool true_color;\n  bool header;\n  bool line_numbers;\n  bool grid;\n  bool rule;\n  bool show_nonprintable;\n  bool snip;\n  size_t wrapping_mode;\n  bool use_italics;\n  size_t paging_mode;\n  size_t highlight_line;\n} BatPrintOptions;\n\n/**\n * Print with specified options.\n * Returns 0 on success, 1 on error.\n */\nint32_t bat_pretty_print(const char *input,\n                         size_t length,\n                         enum BatInputType input_type,\n                         const char *language,\n                         const char *theme,\n                         struct BatPrintOptions options);\n\n/**\n * Pretty print output to a string.\n * Returns 0 on success, 1 on error.\n */\nint32_t bat_pretty_print_to_string(const char *input,\n                                   size_t length,\n                                   enum BatInputType input_type,\n                                   const char *language,\n                                   const char *theme,\n                                   struct BatPrintOptions options,\n                                   const char **output,\n                                   size_t *output_length);\n\n/**\n * Free the string allocated by `bat_pretty_print_to_string`.\n */\nvoid bat_free_string(const char *s);\n\n/**\n * Return the version of the library\n */\nconst char *bat_c_version(void);\n```\n\n### Usage Example\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \"../bat.h\"\n\nint main()\n{\n    const char *text = \"\u003cspan style=\\\"color: #ff00cc\\\"\u003eHello world!\u003c/span\u003e\\n\";\n    const char *language = \"html\";\n    const char *theme = \"Nord\";\n\n    BatPrintOptions options = {\n        .tab_width = 4,\n        .colored_output = 1,\n        .true_color = 1,\n        .header = 1,\n        .line_numbers = 1,\n        .grid = 1,\n        .rule = 1,\n        .show_nonprintable = 0,\n        .snip = 1,\n        .wrapping_mode = 1,\n        .use_italics = 1,\n        .paging_mode = 0,\n        .highlight_line = 0};\n\n    // Test with bytes input\n    bat_pretty_print(\n        text,\n        strlen(text),\n        BatBytes,\n        language,\n        theme,\n        options);\n\n    // Test with file input\n    const char *file_path = \"test_input.html\";\n    bat_pretty_print(\n        file_path,\n        0,\n        BatFile,\n        language,\n        theme,\n        options);\n\n    // Test with multiple files input\n    const char *file_paths[] = {\"test_input1.html\", \"test_input2.html\"};\n    bat_pretty_print(\n        (const char *)file_paths,\n        2,\n        BatFiles,\n        language,\n        theme,\n        options);\n\n    return 0;\n}\n```\n\n## Multi-Language Examples\n\nExamples demonstrating how to use bat-c from various programming languages via FFI:\n\n- **[C](examples/C/)** - Direct usage with Makefile\n- **[Python](examples/Python/)** - Using ctypes\n- **[Go](examples/Go/)** - Using cgo with dynamic/static linking\n- **[Ruby](examples/Ruby/)** - Using ffi gem\n- **[Julia](examples/Julia/)** - Using ccall\n- **[D](examples/D/)** - Using extern(C) with dmd/ldc2\n- **[Zig](examples/Zig/)** - Using @cImport with build.zig\n- **[Nim](examples/Nim/)** - Using importc pragma\n- **[V](examples/V/)** - Using V's C interop\n- **[TypeScript/Node.js](examples/TypeScript/)** - Using Node-API (N-API)\n\nEach example directory contains:\n- `basic` - Simple example highlighting HTML code\n- `self_print` - Example that syntax-highlights its own source file\n- `README.md` - Build and run instructions specific to that language\n\nAll examples require building the Rust library first:\n```sh\ncargo build --release\n```\n\n## Development\n\n### Running Tests\n\nTo run tests written in Rust:\n\n```sh\ncargo test\n```\n\nTo run tests in C:\n\n```sh\ncd test \u0026\u0026 ./test.sh\n```\n\n### Creating Header Files\n\n```sh\ncargo install --force cbindgen\ncbindgen --config cbindgen.toml --crate bat-c --output bat.h\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fbat-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkojix2%2Fbat-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fbat-c/lists"}