
CodeSnap is a pure Rust tool for generate beautiful code snapshots, it directly use graphic engine to generate snapshots, which means the entire process is just matter of computation and rendering, without need for network or something like browser-based rendering solution.
Generally, you can directly use CLI tool provide by CodeSnap to generate code snapshots you want. Or CodeSnap also provide a library for you to integrate it into your own project, so you can generate code snapshots in your own way (See Related projects for more information).
CodeSnap provide two ways to use it, you can use it as a CLI tool or as a library in your own project.
For CLI tool, you can install it for different platforms:
Arch Linux
CodeSnap is available in the extra repository:
pacman -S codesnap
Nix/NixOS
CodeSnap is available in the nixpkgs:
nix-env -i codesnap
Cargo
cargo install codesnap-cli
Or install via precompiled binary:
cargo binstall codesnap-cli
Homebrew
brew install codesnap
Use codesnap command to generate code snapshot:
# Run codesnap to generate code snapshot by providing code file
codesnap -f ./code_snippet.hs -o "./output.png"
# Run codesnap --help to see more information
codesnap -h
For library, add CodeSnap in your project using Cargo
cargo add codesnap
Use CodeSnap builder to generate code snapshot:
let code_content = Content::Code(
CodeBuilder::from_t
.content(r#"print "Hello, World!""#)
.language("python")
.build()?,
);
let snapshot = CodeSnap::from_default_theme()
.content(code_content)
.build()?
.create_snapshot()?;
// Copy the snapshot data to the clipboard
snapshot.raw_data()?.copy()
All examples can be found in examples.
Codesnap can receive a JSON config as input, the config can be used to customize the snapshot, such as theme, background, watermark, etc.
If you are using Library, you can mount config to CodeSnap builder:
CodeSnap::from_config("Your config")?;
Or if you are using CLI tool, CodeSnap will generate a default config file for you under ~/.config/CodeSnap, you can modify the config file to customize the snapshot:
// Both "CaskaydiaCove Nerd Font" and "Pacifico" is pre-installed in CodeSnap, you can use them out of the box
{
"theme": "candy",
"window": {
"mac_window_bar": true,
"shadow": {
"radius": 20,
"color": "#00000040"
},
"margin": {
"x": 82,
"y": 82
},
"border": {
"width": 1,
"color": "#ffffff30"
},
"title_config": {
"color": "#ffffff",
"font_family": "Pacifico"
},
"radius": 12
},
"code_config": {
"font_family": "CaskaydiaCove Nerd Font",
"breadcrumbs": {
"enable": false,
"separator": "/",
"color": "#80848b",
"font_family": "CaskaydiaCove Nerd Font"
}
},
"watermark": {
"content": "CodeSnap",
"font_family": "Pacifico",
"color": "#ffffff"
},
"background": {
"start": {
"x": 0,
"y": 0
},
"end": {
"x": "max",
"y": 0
},
"stops": [
{
"position": 0,
"color": "#6bcba5"
},
{
"position": 1,
"color": "#caf4c2"
}
]
}
}
All configuration items can be found in config.rs
Copy screenshots directly into the clipboard is cool, however, it doesn't work well on wl-clipboard, because the wl-clipboard can't paste the content which come from exited processes. As Hyprland document say:
When we copy something on Wayland (using wl-clipboard) and close the application we copied from, the copied data disappears from the clipboard and we cannot paste it anymore. So to fix this problem we can use a program called as wl-clip-persist which will preserve the data in the clipboard after the application is closed.
If you are using CodeSnap on wl-clipboard, you can refer wl-clip-persist, it reads all the clipboard data into memory and then overwrites the clipboard with the data from our memory to persist copied data.
MIT.
$ claude mcp add codesnap \
-- python -m otcore.mcp_server <graph>