• Stars
    star
    3,024
  • Rank 14,926 (Top 0.3 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 5 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create beautiful image of your source code.

Silicon

Crates.io Documentation CI License

Silicon is an alternative to Carbon implemented in Rust.

It can render your source code into a beautiful image.

Why Silicon

Carbon is a wonderful tool to create a beautiful image of your source code.

But it is a web application, which brings the following disadvantages:

  • Cannot work without Internet & browser.
  • Doesn't work well with shell. (Although there is carbon-now-cli, its experience is not very good, especially when the network is not so good.)

However, Silicon doesn't have these problems. It's is implemented in Rust and can work without browser & Internet.

Silicon can render your source code on the fly while carbon-now-cli takes several seconds on it.

Disadvantages

It's not as beautiful as Carbon...

Install

Cargo

cargo install silicon

NOTE: harfbuzz feature is enabled by default. If you are using Windows, I suggest you disable it to get it build easier.

AUR

Silicon is available in the official repository:

pacman -S silicon

Homebrew

You can install Silicon using Homebrew:

brew install silicon

Dependencies

Ubuntu

sudo apt install expat
sudo apt install libxml2-dev
sudo apt install pkg-config libasound2-dev libssl-dev cmake libfreetype6-dev libexpat1-dev libxcb-composite0-dev libharfbuzz-dev

Fedora

sudo dnf install \
  cmake \
  expat-devel fontconfig-devel libxcb-devel \
  freetype-devel libxml2-devel \
  harfbuzz

Arch Linux

sudo pacman -S --needed pkgconf freetype2 fontconfig libxcb xclip harfbuzz

Examples

Read code from file

silicon main.rs -o main.png 

Read code from clipboard, and copy the result image to clipboard

silicon --from-clipboard -l rs --to-clipboard

Specify a fallback font list and their size

silicon -o main.png -l bash -f 'Hack; SimSun=31; code2000' <<EOF
echo Hello
echo 你好
echo ∠( ᐛ 」∠)_
EOF

Highlight specified line

silicon main.rs -o main.png --highlight-lines '1; 3-4'

Custom the image

silicon ./target/test.rs -o test.png \
    --shadow-color '#555' --background '#fff' \
    --shadow-blur-radius 30 --no-window-controls

Transparent background

The color can be #RGB[A] or #RRGGBB[AA]

silicon ./target/test.rs -o test.png --background '#fff0'

Show window title

silicon ./target/test.rs -o test.png --window-title "target/test.rs"

see silicon --help for detail

Adding new syntaxes / themes

Silicon reads syntax-definition and theme cache from user's cache directory.

The steps to add new syntaxes / themes is as same as bat: sharkdp/bat#adding-new-syntaxes--language-definitions. Just replace bat cache --build to silicon --build-cache.

Configuration file

You can write some common args to silicon --config-file.

Example:

# enable shadow
--shadow-color '#555'
--background '#fff'
--shadow-blur-radius 30
--no-window-controls

Related projects

More Repositories

1

fzf-tab

Replace zsh's default completion selection menu with fzf!
Shell
3,003
star
2

MirageTankGo

幻影坦克(特指点开后不一样的图片)快速发车工具
Python
140
star
3

LeetCode-Rust

听说刷题建 repo 是立 flag 一般的行为?
Rust
85
star
4

dotfiles

my dotfiles
Shell
67
star
5

Rust-toys

一堆写着练手的小玩意儿, 考虑到Rust的龟速编译, 还是放在一起比较省事
Rust
18
star
6

aur-build

Build AUR packages with GitHub Actions
Shell
15
star
7

leetcode_prelude

Some useful macros and definition for exercising in leetcode
Rust
13
star
8

ppool

一个爬虫 IP 代理池
Rust
11
star
9

CAPIx

使CMD能够高速调用API
C++
11
star
10

p7zip

a custom 7z, which can use three keys instead of password to extract zip file.
C++
10
star
11

gencomp

Generate zsh completion functions from manpage or `--help`
Python
10
star
12

NT4_CMD

从OpenNT提取的NT4_CMD_x86源码及其编译环境
C
10
star
13

cdda-itembrowser

CDDA 物品浏览器
PHP
8
star
14

telegraph-rs

telegraph API binding in Rust
Rust
7
star
15

Use-PosixPipeline

The POSIX version of Use-RawPipeline
C#
7
star
16

10_0_0_55_login

BIT 10.0.0.55 的登入与登出的Python实现
Python
7
star
17

Crypko.Spider

(目前是)一次性的Crypko小爬虫
Python
5
star
18

zsh-sqlite

A zsh module for manipulating sqlite database
C
4
star
19

facenote_thirdparty_app

为掌阅系统安装第三方 app
Python
4
star
20

crc32fix

fix png's length or height according to its crc32 checksum
Rust
4
star
21

ren3

Do file renaming using regular expressions. 使用正则表达式重命名文件.
Rust
3
star
22

funcall

Rust
3
star
23

GCD-1

综合性批处理游戏开发第三方
C
3
star
24

Aloxaf.github.io

my blog
HTML
2
star
25

cdda-wiki-bot

Python
2
star
26

GCD

GCD的dll版
C
2
star
27

IMGSolve

基于Python的可扩展的图片隐写分析工具
Python
2
star