LinuxCommandLibrary

silicon

Generate stylish terminal code snippets

TLDR

Generate an image from a specific source file

$ silicon [path/to/source_file] --output [path/to/output_image]
copy

Generate an image from a source file with a specific programming language syntax highlighting (e.g. rust, py, js, etc.)
$ silicon [path/to/source_file] --output [path/to/output_image] --language [language|extension]
copy

Generate an image from stdin
$ [command] | silicon --output [path/to/output_image]
copy

SYNOPSIS

silicon [OPTIONS] [FILE]
silicon [OPTIONS] --from-clipboard
(If FILE is omitted and --from-clipboard is not used, input is read from standard input.)

PARAMETERS

-o, --output
    Specify the output file path for the generated image. Defaults to output.png.

-t, --theme
    Set the syntax highlighting theme. Use silicon --list-themes to view available options.

-f, --font
    Define the font family and size (e.g., "Fira Code=18"). Multiple fonts can be specified for fallbacks.

-l, --language
    Manually specify the programming language (e.g., rs for Rust, py for Python). Auto-detected if not specified.

--line-numbers
    Display line numbers alongside the code in the output image.

--no-round-corner
    Disable the default rounded corners for the code block.

--scale
    Scale the output image by the given factor (e.g., 2 for 2x resolution).

--background
    Set a custom background color for the image (e.g., #282C34 or a CSS color name like red).

--from-clipboard
    Read the source code directly from the system clipboard instead of a file or stdin.

--to-clipboard
    Copy the generated image to the system clipboard instead of saving it to a file.

DESCRIPTION

silicon is a versatile command-line tool, written in Rust, designed to generate aesthetically pleasing images from source code files. It enables developers and content creators to easily transform code snippets into high-quality visual formats suitable for presentations, social media, documentation, or blog posts. Users can extensively customize the output image, including syntax highlighting themes, font families and sizes, line numbers, and background colors. It supports automatic language detection based on file extensions and allows manual specification. silicon prioritizes ease of use and aims to provide a clean, professional appearance for code, making it an efficient choice for showcasing programming snippets directly from the terminal.

CAVEATS

Clipboard operations with silicon require a functioning clipboard utility (e.g., xclip or wl-copy on Linux) and typically a graphical environment. The availability of specific fonts and themes depends on their installation and configuration on the host system. For very large source files, image generation time may increase.

EXAMPLE USAGE

To generate an image from a Rust file with a specific theme and font:
silicon main.rs -o rust_code.png --theme "OneHalfDark" --font "Fira Code=16"

To read code from standard input and copy the output image to clipboard:
cat my_script.py | silicon --language py --line-numbers --to-clipboard

To generate from clipboard and save to a specific file with a custom background:
silicon --from-clipboard -o clipboard_code.png --background "#282C34"

THEMES AND FONTS

silicon supports a variety of syntax highlighting themes, which can dramatically change the appearance of your code. You can list all available themes using the command:
silicon --list-themes

Fonts can be specified by their family name and size. Multiple font families can be listed, separated by commas, for fallback purposes (e.g., "Fira Code,Noto Sans Mono=16"). Ensure desired fonts are installed on your system for them to be used by silicon.

HISTORY

silicon is a relatively modern command-line utility, implemented in Rust, which is known for its performance and memory safety. It emerged as an open-source alternative to web-based code snippet image generators like Carbon, aiming to provide a fast and efficient native solution for developers. Its development has focused on ease of use, broad customization options, and integration into development workflows directly from the terminal, quickly gaining traction within the developer community.

SEE ALSO

carbon-now-cli, highlight(1), bat(1)

Copied to clipboard