🎨 Beautiful images of your code — from right inside your terminal.
🎨 Beautiful images of your code — from right inside your terminal.
carbon.now.sh by @dawn_labs is a wonderful tool that lets you generate beautiful images of your source code through an intuitive UI, while letting you customize aspects like fonts, themes, window controls and much more.
carbon-now-cligives you the full power of Carbon — right at your fingertips, inside the terminal.
Generate beautiful images from a source file, or sections of a source file, by running a single command.
Want to customize everything before generating the image? Run it in ⚡️ interactive mode ⚡️. 😎
--interactive
--startand
--end
--copy(cross-OS 😱)
stdinor clipboard content as input
.pngor
.svg— just like Carbon
2x,
4xor
1xresolutions — just like Carbon
$ npm i -g carbon-now-cli
$ yarn global add carbon-now-cli
$ npx carbon-now-cli
$ carbon-now --helpBeautiful images of your code — from right inside your terminal.
Usage $ carbon-now $ pbpaste | carbon-now $ carbon-now --from-clipboard
Options -s, --start Starting line of -e, --end Ending line of -i, --interactive Interactive mode -l, --location Image save location, default: cwd -t, --target Image name, default: original-hash.{png|svg} -o, --open Open in browser instead of saving -c, --copy Copy image to clipboard -p, --preset Use a saved preset -h, --headless Use only non-experimental Puppeteer features --config Use a different, local config (read-only) --from-clipboard Read input from clipboard instead of file
Examples See: https://github.com/mixn/carbon-now-cli#examples
Assuming you have a file
unfold.jswith this content
// Example from https://carbon.now.sh/ const unfold = (f, seed) => { const go = (f, seed, acc) => { const res = f(seed) return res ? go(f, res[1], acc.concat([res[0]])) : acc } return go(f, seed, []) };
and you’d like to make a beautiful image out of it. You could approach this in several ways.
$ carbon-now unfold.js
Takes the entire source of
unfold.js, uses Carbon’s default settings and saves as
.pnginto your
cwd.
Result:
Note:
carbon-nowwill be smart enough to reuse your last used settings, instead of the default ones. 🤓
$ carbon-now unfold.js -i
Launches an interactive mode, prompting questions, allowing you to customize every aspect of Carbon, like syntax theme, font-family, padding, drop-shadow, etc.
Given this input…
…the result will look like so 😍:
If you’re not sure what each question, e.g. “Make squared image?”, refers to, just confirm by hitting Enter — it will default to a sensible, nice-looking thing.
If needed, you can always check the default settings.
$ carbon-now unfold.js -s 3 -e 6
Reads and creates an image based on lines
3to
6, instead of the entire file. Will throw an error if
-s>
-e.
Selective mode can of course be combined with interactive mode, just with like any other option. 😊
Result:
Note:
carbon-nowwill be smart enough to reuse your last used settings, instead of the default ones. 🤓
It is sometimes desired to just put the image in the clipboard, so that it can be instantly pasted into other apps (like Keynote 💻 or Twitter 🐦). This is what the
--copy/
-cflag is for.
$ carbon-now unfold.js -c
will copy the image to clipboard instead of downloading it to a given directory.
Please be aware that this requires some binaries to be present on certain OS.
xclipis required. You can install it via
sudo apt-get install xclip
NirCmdis required. It can be installed via
choco install nircmd
Also make sure the
nircmdcommand is globally accessible/inside your Windows directory.
You’ll sometimes find yourself in a situation where you’d like to create an image based on a piece of code, but don’t want to be creating a file for it first.
In addition to files,
carbon-now-clitherefore also accepts input coming from
stdinor the clipboard.
stdin
$ pbpaste | carbon-now $ echo 'Hi
' | carbon-now
$ carbon-now --from-clipboard
For demonstration purposes, here is an example using all options.
$ carbon-now unfold.js -s 3 -e 6 -l ~/Desktop -t example-23 -i
This saves a beautiful image of lines
3to
6to
~/Desktop/example-23.png, after accepting custom wishes via interactive mode.
If you’re not sure how exactly the image will turn out, you can always use
-oor
--open.
$ carbon-now unfold.js -s 3 -e 6 -i -o
This will open the image in the browser for final touches, instead of saving it immediately. 😌
The most requested feature after
carbon-now-cli’s initial release has been the support for reusable settings, to not having to go through the entire process of answering all questions in interactive mode each time.
Presets are officially included as of
v1.1.0of
carbon-now-cli. 🎉
However you use the
carbon-nowcommand, a
~/.carbon-now.jsonfile will be created for you. This is where all your presets and the settings of the last interactive run will live.
When running
carbon-nowwith
-i, you’ll be asked the following two questions last:
Answering with yes and naming the preset (in this case
presentation) will result in the preset being saved to
~/.carbon-now.json. In this particular case,
~/.carbon-now.jsonwill look like so:
{ "latest-preset": { "t": "base16-light", "bg": "none", "wt": "none", "wc": true, "fm": "Inconsolata", "fs": "18px", "ln": true, "ds": true, "dsyoff": "3px", "dsblur": "5px", "wa": true, "pv": "15px", "ph": "15px", "si": false, "wm": false, "es": "2x", "type": "png" }, "presentation": { "t": "base16-light", "bg": "none", "wt": "none", "wc": true, "fm": "Inconsolata", "fs": "18px", "ln": true, "ds": true, "dsyoff": "3px", "dsblur": "5px", "wa": true, "pv": "15px", "ph": "15px", "si": false, "wm": false, "es": "2x", "type": "png" } }
latest-presetwill be overwritten after each interactive run.
presentationis meant to stay until you eventually decide to delete it manually.
Reusing presets is as easy and straight-forward as:
carbon-now unfold.js -p
If a given preset or
~/.carbon-now.jsondoesn’t exist,
carbon-now-cliwill fall back to the default settings.
Taken the
presentationpreset we have created above, this is all we have to do:
carbon-now unfold.js -p presentation
Result:
It just works! ™ 🎉
Any time you use
-i,
carbon-now-cliwill automatically reuse those settings for its next run.
So you can
carbon-now -iand
carbon-nowfrom there on — the output will always look as pretty as the one where you’ve used
-i. 😊
It is possible to use local configuration files via the
--configflag.
This is convenient if you’re using
carbon-now-clivia a script and would like to share presets among the users of your project.
carbon-now unfold.js --config local-config.json -p dark
Local configs differ from
~/.carbon-now.jsonin the sense that they behave in a read-only manner, hence:
local-config.jsonwon’t be created if it doesn’t exist
latest-presetwill not be written to
local-config.json
MIT © Miloš Sutanovac