CodeTint

Bringing Precision to Your Code: Introducing CodeTint


Welcome to the world of beautiful and precise code! I'm excited to introduce CodeTint, a lightweight and powerful command-line utility built entirely in C. Designed for both speed and accuracy, CodeTint leverages the robust parsing capabilities of Tree-sitter to provide highly detailed and precise syntax highlighting.

Functioning much like the classic `cat` command, CodeTint reads your source files and outputs their content, but with the added benefit of beautiful syntax highlighting. Unlike traditional regex-based highlighting, Tree-sitter builds a full syntax tree, allowing CodeTint to understand the structure of your code deeply. This means more accurate highlighting for functions, variables, keywords, and comments, giving you a clearer and more visually appealing view of your source files.

Key Features

How it Works

CodeTint utilizes Tree-sitter to parse your source code into an abstract syntax tree (AST). It then applies predefined queries (written in Tree-sitter's query language, `.scm`) against this AST to identify different code elements like keywords, strings, comments, and function names. Based on these matches, it applies the appropriate ANSI escape codes or injects HTML `` tags with CSS classes, which are then styled by your chosen theme.

Installation

To get `CodeTint` up and running, follow these steps. For detailed instructions and prerequisites, refer to the project's README.md.

Prerequisites

Build Steps

First, clone the repository and initialize submodules:


git clone https://github.com/Harshit-Dhanwalkar/CodeTint.git
cd CodeTint
git submodule update --init --recursive
        

For the image generation feature, you need to place your desired TrueType Font (`.ttf`) files inside the `modules/Fonts/` directory. For example:


CodeTint/
└── modules/
    └── Fonts/
        ├── JetBrainsMono-2.304/
        │   └── JetBrainsMono-Regular.ttf
        └── ... (other .ttf files)
        

Then, compile the application using the provided `gcc` command:


gcc -Wall -Wextra -g -Imodules -Imodules/stb -I./tree-sitter/lib/include -I./tree-sitter-python/src -I./tree-sitter-c/src -I./tree-sitter-cpp/src/ -I./tree-sitter-javascript/src -I./tree-sitter-html/src -I./tree-sitter-css/src -I./tree-sitter-rust/src -I./tree-sitter-bash/src codetint.c modules/theme.c modules/libcodeimage.c ./tree-sitter/lib/src/lib.c ./tree-sitter-python/src/parser.c ./tree-sitter-python/src/scanner.c ./tree-sitter-c/src/parser.c ./tree-sitter-cpp/src/parser.c ./tree-sitter-cpp/src/scanner.c ./tree-sitter-javascript/src/parser.c ./tree-sitter-javascript/src/scanner.c ./tree-sitter-html/src/parser.c ./tree-sitter-html/src/scanner.c ./tree-sitter-css/src/parser.c ./tree-sitter-css/src/scanner.c ./tree-sitter-rust/src/parser.c ./tree-sitter-rust/src/scanner.c ./tree-sitter-bash/src/parser.c ./tree-sitter-bash/src/scanner.c -lm -o codetint
        

Usage Examples

Your `CodeTint` executable is now ready to use!

Basic Terminal Output:


./codetint your_source_file.c
        

Specifying a Color Theme (e.g., `nord` for a bash script):


./codetint examples/test.sh -c nord
        

Generating Interactive HTML Output (with line numbers for a Javascript file):


./codetint your_source_file.js --html -n -o highlighted_code.html
        

Open the generated `highlighted_code.html` in your web browser to experience the interactive features, including the theme switcher and copy-to-clipboard functionality.

Generating a PNG image with a specific font:


./codetint examples/test1.py --image-out assets/output-python.png --image-font "JetBrainsMono-Regular" --image-fs 18
        

This command will read `examples/test1.py`, render its content using the `JetBrainsMono-Regular` font at 18px size, and save the syntax-highlighted output directly to `assets/output-python.png`.

A Look Under the Hood (C Code Example)

Here's a small C code snippet, which `CodeTint` can highlight with precision:


#include <stdio.h> // Include standard I/O
/**
 * main - Entry point
 * Return: Always 0
 */
int main(void) {
    // Print a greeting
    printf("Hello, CodeTint!\n"); // Function call and string literal
    return 0; // Keyword return
}
        

Running `CodeTint` on this file (e.g., `./codetint -c dracula example.c --html -o example.html`) will produce an HTML file where keywords, comments, strings, and functions are distinctly colored according to the Dracula theme.

Future Vision

CodeTint is under continuous development. Future plans include:

Get Involved!

I welcome contributions and feedback! If you find `CodeTint` useful, encounter issues, or have ideas for new features, please visit the CodeTint GitHub repository.