Code Monkey home page Code Monkey logo

carbon-now-cli's Introduction

Carbon CLI

🎨 Beautiful images of your code β€” from right inside your terminal.

Build Status Code style Featured in awesome-nodejs Twitter Stargazers Maintenance Requirements MIT license

Table of Contents

Description

carbon.now.sh is an excellent tool that lets you generate beautiful images of your source code through an intuitive UI while allowing you to customize aspects like fonts, themes, window controls, and & more.

carbon-now-cli gives 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. ⚑️ 😎

Basic example

Features

Installation

pnpm

pnpm i -g carbon-now-cli

npm

npm i -g carbon-now-cli

yarn

yarn global add carbon-now-cli

npx

npx carbon-now-cli <file>

Requirements

Requirements

Usage

Beautiful images of your code β€” from right inside your terminal.

Usage
  $ carbon-now <file>
  $ pbpaste | carbon-now
  $ carbon-now --from-clipboard

Options
  -s, --start          Starting line of input
  -e, --end            Ending line of input
  -i, --interactive    Interactive mode
  -p, --preset         Apply an existing preset
  --save-to            Image save location, default: cwd
  --save-as            Image name, default: original-hash.{png|svg}
  --from-clipboard     Read input from clipboard instead of file
  --to-clipboard       Copy image to clipboard
  --open-in-browser    Open in browser instead of saving
  --config             Use a different, local config (read-only)
  --disable-headless   Run Playwright in headful mode
  --engine             Use different rendering engine, default: `chromium`
                       Options: `chromium`, `firefox`, `webkit`
  --skip-display       Don’t display the image in the terminal

Examples
  See: https://github.com/mixn/carbon-now-cli#examples

Examples

Assuming you have a file unfold.js with 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.

Basic

carbon-now unfold.js

Takes the entire source of unfold.js, uses Carbon’s default settings, and saves as .png into your cwd.

Result:

Basic example

Fully customized

carbon-now unfold.js --interactive

Launches an interactive mode, prompting questions, allowing you to customize every aspect of Carbon, like syntax theme, font-family, padding, window controls, etc.

Given this input…

Example 2, Input

…the result will look like so 😍:

Example 2, Output

If you’re unsure what each question, e.g., β€œMake squared image?” refers to, simply confirm by hitting Enter β€” it will default to a sensible, nice-looking thing.

If needed, you can always check the default settings.

Note: carbon-now will be smart enough to re-use your last used settings instead of the default ones. πŸ€“

Selective

carbon-now unfold.js --start 3 --end 6

Reads and creates an image based on lines 3 to 6 instead of the entire file. Will throw an error if -s > -e.

Selective processing can of course be combined with interactive mode, as with any other option. 😊

Result:

Example 3

Copying to clipboard

Copying to Clipboard

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 --to-clipboard flag is for.

carbon-now unfold.js --to-clipboard

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.

Linux

xclip is required. You can install it via

sudo apt-get install xclip

Windows & macOS

It just works. β„’

Input Sources

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 create a file for it first.

In addition to files, carbon-now-cli therefore also accepts input coming from stdin or the clipboard.

stdin

pbpaste | carbon-now
echo '<h1>Hi</h1>' | carbon-now

Clipboard

carbon-now --from-clipboard

Full Example

For demonstration purposes, here is an example using most options.

carbon-now unfold.js --start 3 --end 6 --save-to ~/Desktop --save-as example-23 --interactive

This saves a beautiful image of lines 3 to 6 to ~/Desktop/example-23.png, after accepting custom wishes via interactive mode.

If you’re unsure how exactly the image will turn out, you can always use --open-in-browser.

carbon-now unfold.js --start 3 --end 6 --interactive --open-in-browser

This will open the image in the browser for final touches, instead of saving it immediately. 😌

Presets

Creating a preset

However you use the carbon-now command, a ~/.carbon-now.json file will be created for you. This is where all your presets and the settings of the last interactive run will live.

When running carbon-now with -i, you’ll be asked the following two questions last:

Presets 1

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.json will look like so:

{
  "latest-preset": {
    "theme": "base16-light",
    "backgroundColor": "white",
    "windowTheme": "none",
    "windowControls": true,
    "fontFamily": "Space Mono",
    "fontSize": "18px",
    "lineNumbers": false,
    "firstLineNumber": 1,
    "selectedLines": "*",
    "dropShadow": false,
    "dropShadowOffsetY": "20px",
    "dropShadowBlurRadius": "68px",
    "widthAdjustment": true,
    "lineHeight": "140%",
    "paddingVertical": "35px",
    "paddingHorizontal": "35px",
    "squaredImage": false,
    "watermark": false,
    "exportSize": "2x",
    "type": "png"
  },
  "presentation": {
    "theme": "base16-light",
    "backgroundColor": "white",
    "windowTheme": "none",
    "windowControls": true,
    "fontFamily": "Space Mono",
    "fontSize": "18px",
    "lineNumbers": false,
    "firstLineNumber": 1,
    "selectedLines": "*",
    "dropShadow": false,
    "dropShadowOffsetY": "20px",
    "dropShadowBlurRadius": "68px",
    "widthAdjustment": true,
    "lineHeight": "140%",
    "paddingVertical": "35px",
    "paddingHorizontal": "35px",
    "squaredImage": false,
    "watermark": false,
    "exportSize": "2x",
    "type": "png"
  }
}

latest-preset will be overwritten after each interactive run. presentation is meant to stay until you eventually decide to delete it manually.

Using a saved preset

Re-using presets is as easy and straight-forward as:

carbon-now unfold.js -p <name-of-preset>

If a given preset or ~/.carbon-now.json doesn’t exist, carbon-now-cli will fall back to the default settings.

Taken the presentation preset we have created above, all we have to do is:

carbon-now unfold.js -p presentation

Result:

Presets 1

Re-using the last used settings

It just works. β„’

Any time you use -i, carbon-now-cli will automatically re-use those settings for its next run.

So you can carbon-now <file> -i and carbon-now <file> from there on β€” the output will always look as pretty as the one where you’ve used -i. 😊

Custom theme colors

From v2.0 onwards, carbon-now-cli supports the ability to define custom theme colors, i.e., what color e.g., variables, operators, attributes, etc. should have, allowing you to have complete control over how things look to the smallest detail.

Therefore, you have to provide a key called custom inside one of your presets that complies to the following type:

interface CarbonThemeHighlightsInterface {
  background?: string;
  text?: string;
  variable?: string;
  variable2?: string;
  variable3?: string;
  attribute?: string;
  definition?: string;
  keyword?: string;
  operator?: string;
  property?: string;
  number?: string;
  string?: string;
  comment?: string;
  meta?: string;
  tag?: string;
}

Here’s an example ~/.carbon-now.json config that has one preset hacker, which makes use of custom theme colors:

{
  "hacker": {
    "backgroundColor": "rgba(0, 255, 0, 1)",
    "windowTheme": "bw",
    "windowControls": true,
    "fontFamily": "Anonymous Pro",
    "fontSize": "18px",
    "lineNumbers": false,
    "firstLineNumber": 1,
    "dropShadow": false,
    "selectedLines": "*",
    "dropShadowOffsetY": "20px",
    "dropShadowBlurRadius": "68px",
    "widthAdjustment": true,
    "lineHeight": "133%",
    "paddingVertical": "30px",
    "paddingHorizontal": "30px",
    "squaredImage": false,
    "watermark": false,
    "exportSize": "2x",
    "type": "png",
    "custom": {
      "background": "rgba(0, 0, 0, 1)",
      "text": "rgba(0, 255, 0, 1)",
      "variable": "rgba(0, 255, 0, 1)",
      "variable2": "rgba(0, 255, 0, 1)",
      "attribute": "rgba(0, 255, 0, 1)",
      "definition": "rgba(0, 255, 0, 1)",
      "keyword": "rgba(0, 255, 0, 1)",
      "operator": "rgba(0, 255, 0, 1)",
      "property": "rgba(0, 255, 0, 1)",
      "number": "rgba(0, 255, 0, 1)",
      "string": "rgba(0, 255, 0, 1)",
      "comment": "rgba(0, 255, 0, 1)",
      "meta": "rgba(0, 255, 0, 1)",
      "tag": "rgba(0, 255, 0, 1)"
    }
  }
}
carbon-now unfold.js -p hacker

Result:

Presets 3

Limitations

Please note that custom theme colors won’t be applied with --open-in-browser because they aren’t query string parameters but instead communicated to Carbon via localStorage, which is solely set inside the Playwright instance.

Local configs

It is possible to use local configuration files via the --config flag.

This is convenient if you’re using carbon-now-cli via 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.json in the sense that they behave in a read-only manner, hence:

  1. local-config.json won’t be created if it doesn’t exist
  2. latest-preset will not be written to local-config.json

License

MIT Β© MiloΕ‘ Sutanovac

carbon-now-cli's People

Contributors

bokub avatar dependabot[bot] avatar mathiasbynens avatar mauricedb avatar mido3ds avatar mixn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

carbon-now-cli's Issues

command not found: carbon-now

➜ snippets carbon-now
zsh: command not found: carbon-now

I installed using

➜  ~ yarn global add carbon-now-cli
yarn global v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
      - carbon-now
Done in 1.67s.

But when I try to run it, it show command no found. Where does carbon-now is install? I'm installed it under centos 7

Can't install carbon-now-cli

Her, I'm running MacOS latest version 10.13.6, and node 10.9, it throws the error :

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/10.9.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'i',
1 verbose cli   '-g',
1 verbose cli   'carbon-now-cli' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 11a4111ff23b4434
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 200 https://registry.npmjs.org/carbon-now-cli 16ms (from cache)
8 silly pacote tag manifest for carbon-now-cli@latest fetched in 27ms
9 timing stage:loadCurrentTree Completed in 179ms
10 silly install loadIdealTree
11 silly install cloneCurrentTreeToIdealTree
12 timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
13 silly install loadShrinkwrap
14 timing stage:loadIdealTree:loadShrinkwrap Completed in 2ms
15 silly install loadAllDepsIntoIdealTree
16 silly resolveWithNewModule [email protected] checking installable status
17 http fetch GET 200 https://registry.npmjs.org/file-exists 27ms (from cache)
18 http fetch GET 200 https://registry.npmjs.org/jsonfile 25ms (from cache)
19 http fetch GET 200 https://registry.npmjs.org/file-extension 29ms (from cache)
20 http fetch GET 200 https://registry.npmjs.org/listr 25ms (from cache)
21 http fetch GET 200 https://registry.npmjs.org/del 30ms (from cache)
22 http fetch GET 200 https://registry.npmjs.org/meow 26ms (from cache)
23 http fetch GET 200 https://registry.npmjs.org/globby 30ms (from cache)
24 http fetch GET 200 https://registry.npmjs.org/chalk 34ms (from cache)
25 silly pacote range manifest for file-exists@^5.0.1 fetched in 33ms
26 silly resolveWithNewModule [email protected] checking installable status
27 silly pacote range manifest for jsonfile@^4.0.0 fetched in 33ms
28 silly resolveWithNewModule [email protected] checking installable status
29 silly pacote range manifest for file-extension@^4.0.5 fetched in 36ms
30 silly resolveWithNewModule [email protected] checking installable status
31 silly pacote range manifest for listr@^0.14.1 fetched in 33ms
32 silly resolveWithNewModule [email protected] checking installable status
33 silly pacote range manifest for del@^3.0.0 fetched in 39ms
34 silly resolveWithNewModule [email protected] checking installable status
35 silly pacote range manifest for meow@^5.0.0 fetched in 34ms
36 silly resolveWithNewModule [email protected] checking installable status
37 silly pacote range manifest for globby@^8.0.1 fetched in 40ms
38 silly resolveWithNewModule [email protected] checking installable status
39 http fetch GET 200 https://registry.npmjs.org/lodash 38ms (from cache)
40 silly pacote range manifest for chalk@^2.4.1 fetched in 46ms
41 silly resolveWithNewModule [email protected] checking installable status
42 http fetch GET 200 https://registry.npmjs.org/inquirer 46ms (from cache)
43 silly pacote range manifest for lodash@^4.17.10 fetched in 45ms
44 silly resolveWithNewModule [email protected] checking installable status
45 http fetch GET 200 https://registry.npmjs.org/opn 13ms (from cache)
46 silly pacote range manifest for inquirer@^6.0.0 fetched in 51ms
47 silly resolveWithNewModule [email protected] checking installable status
48 http fetch GET 200 https://registry.npmjs.org/terminal-image 14ms (from cache)
49 http fetch GET 200 https://registry.npmjs.org/query-string 15ms (from cache)
50 http fetch GET 200 https://registry.npmjs.org/nanoid 18ms (from cache)
51 silly pacote range manifest for opn@^5.3.0 fetched in 18ms
52 silly resolveWithNewModule [email protected] checking installable status
53 silly pacote range manifest for terminal-image@^0.1.1 fetched in 16ms
54 silly resolveWithNewModule [email protected] checking installable status
55 silly pacote range manifest for query-string@^6.1.0 fetched in 17ms
56 silly resolveWithNewModule [email protected] checking installable status
57 silly pacote range manifest for nanoid@^1.1.0 fetched in 21ms
58 silly resolveWithNewModule [email protected] checking installable status
59 http fetch GET 200 https://registry.npmjs.org/puppeteer 19ms (from cache)
60 silly fetchPackageMetaData error for puppeteer@^1.5.0 Unexpected end of JSON input while parsing near '...er","version":"1.3.0-'
61 timing stage:rollbackFailedOptional Completed in 1ms
62 timing stage:runTopLevelLifecycles Completed in 258ms
63 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...er","version":"1.3.0-'
63 verbose stack     at JSON.parse (<anonymous>)
63 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
63 verbose stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
63 verbose stack     at process._tickCallback (internal/process/next_tick.js:68:7)
64 verbose cwd /Users/neilrichter
65 verbose Darwin 17.7.0
66 verbose argv "/usr/local/Cellar/node/10.9.0/bin/node" "/usr/local/bin/npm" "i" "-g" "carbon-now-cli"
67 verbose node v10.9.0
68 verbose npm  v6.2.0
69 error Unexpected end of JSON input while parsing near '...er","version":"1.3.0-'
70 verbose exit [ 1, true ]

Support for older node/npm versions.

screen shot 2018-07-11 at 8 21 09 am

I think the above is due to my outdated node/npm version. I'm not willing to upgrade the node/npm version for some time now due to my involvement in some legacy projects.

Compatibility information should be mentioned in the README. Also, It would be good if you can add support for lower node/npm versions.

not creating file

With command carbon-now sample.js or piping from stdin


const compose = (...fns) => res => fns.reduce((accum, next) => next(accum), res)

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, [])
}

I get this output

  βœ” Processing sample.js
  βœ” Preparing connection
  ↓ Opening in browser [skipped]
  βœ– Fetching beautiful image
    β†’ ENOENT: no such file or directory, rename '/tmp/sample/carbon.png' -> '/tmp/sample/sample-bba1332a4e.png'
    Copying image to clipboard

  Error: Sending code to https://carbon.now.sh went wrong.

  This is mostly due to:

  – Insensical input like `--start 10 --end 2`
  – Carbon being down or taking too long to respond
  – Your internet connection not working or being too slow

  Additional info:

  Error: ENOENT: no such file or directory, rename '/tmp/sample/carbon.png' -> '/tmp/sample/sample-bba1332a4e.png'

The browser did open, and the image was created. It closed by itself and left this error without creating any files.
Kernel: 5.3.0-51-generic x86_64 bits: 64 Desktop: Gnome 3.34.3 Distro: Ubuntu 19.10 (Eoan Ermine)

Error: Sending code to https://carbon.now.sh went wrong.

Hi,

Fresh install, OSX High Sierra (10.13.5), firewall turned off (or on, doesn't matter).

time carbon-now config/app.php
 βœ” Processing config/app.php
 βœ” Preparing connection
 ↓ Opening in browser [skipped]
 βœ– Fetching beautiful image
   β†’ net::ERR_CONNECTION_CLOSED at https://carbon.now.sh/?bg=none&code=%253C%253Fphp%250A%250Areturn%2520%255B%250A%250A%2520%2520%2520%2520%252F%2A%250A%2520%2520%2520%2520%257C--------------------------------------------------------------------------%250A%2520%2520%252…

  Error: Sending code to https://carbon.now.sh went wrong.

  This is mostly due to:

  – Insensical input like `--start 10 --end 2`
  – Carbon being down or taking too long to respond
  – Your internet connection not working or being too slow

real	0m1.828s
user	0m1.538s
sys	0m0.493s

Using a start and end index with a different number of digits can fail

Using the --start and --end can fail the check that the end line is larger than the start line because the comparison is done using strings instead of the numerical value.

Example:

carbon-now ./index.js --start 2 --end 10

Expected behavior?
This to work just fine.

Observed behavior?

 Γ— Processing ./index.ts
   Preparing connection
   Opening in browser
   Fetching beautiful image

  Error: Sending code to https://carbon.now.sh went wrong.

  This is mostly due to:

  – Insensical input like `--start 10 --end 2`
  – Carbon being down or taking too long to respond
  – Your internet connection not working or being too slow

  Additional info:

  TypeError: Cannot read property 'message' of undefined

Cannot output to different mount

Rename fails if the output directory is not on the same hard drive as the current working directory. Here, /tmp/ is mounted to a different location as CWD:

carbon-now -h /tmp/tmp-31437-GSsSEGSH3nB0/code.js38fb969f-f483-496f-9b6c-5044718d76cc -t 38fb969f-f483-496f-9b6c-5044718d76cc

And it fails with:

5|web-file-uploader  | { [Error: EXDEV: cross-device link not permitted, rename '6b0c2b9e-842c-411f-a1b0-bed36024fc8f.png' -> '/tmp/tmp-31437-GSsSEGSH3nB0/code.js6b0c2b9e-842c-411f-a1b0-bed36024fc8f.png']
5|web-file-uploader  |   errno: -18,
5|web-file-uploader  |   code: 'EXDEV',
5|web-file-uploader  |   syscall: 'rename',
5|web-file-uploader  |   path: '6b0c2b9e-842c-411f-a1b0-bed36024fc8f.png',
5|web-file-uploader  |   dest:
5|web-file-uploader  |    '/tmp/tmp-31437-GSsSEGSH3nB0/code.js6b0c2b9e-842c-411f-a1b0-bed36024fc8f.png' }

macOS "Error: Chromium revision is not downloaded"

Installed with sudo npm i -g carbon-now-cli

╰─ carbon-now --from-clipboard                                
  βœ” Processing stdin
  βœ” Preparing connection
  ↓ Opening in browser [skipped]
  βœ– Fetching beautiful image
    β†’ Chromium revision is not downloaded. Run "npm install" or "yarn install"
    Copying image to clipboard

  Error: Sending code to https://carbon.now.sh went wrong.

  This is mostly due to:

  – Insensical input like `--start 10 --end 2`
  – Carbon being down or taking too long to respond
  – Your internet connection not working or being too slow

  Additional info:

  Error: Chromium revision is not downloaded. Run "npm install" or "yarn install"

However, Chromium had already been installed with npm:

╰─ npm show chromium      

[email protected] | MIT | deps: 8 | versions: 23
Chromium binaries for Node.js projects
https://github.com/dtolstyi/node-chromium#readme

keywords: chromium, chrome, browser

dist
.tarball: https://registry.npmjs.org/chromium/-/chromium-3.0.2.tgz
.shasum: c98163deee5f79c49a34db667622490a61b94736
.integrity: sha512-jxkcLjAYc4Oa72UaVnk60k6qGbbsxsqK4Z6GpvW3mhw8GmUX4Udr4vTs3Z91UtxJmbw7mKPvovE7INkqBlVdvg==
.unpackedSize: 23.2 kB

dependencies:
cachedir: ^2.3.0    debug: ^4.1.0       extract-zip: ^1.7.0 got: ^11.5.1        progress: ^2.0.3    rimraf: ^2.7.1      tmp: 0.0.33         tunnel: ^0.0.6      

maintainers:
- dtolstyi <[email protected]>

dist-tags:
latest: 3.0.2  

published a week ago by dtolstyi <[email protected]>

Bad folder handling on Windows

When you run the following command:

carbon-now -h C:\Users\USER1\AppData\Local\Temp\tmp-21636fth6rhRO9IAw\M3EDyV9G2G.txt -t C:\Users\USER\AppData\Local\Temp\tmp-21636fth6rhRO9IAw\M3EDyV9G2G.txt

It doesn't understand the absolute path:

Error: ENOENT: no such file or directory, rename 'C:\Users\USER\Documents\Github\femto-apps\web-file-uploader\carbon.png' -> 'C:\Users\USER\Documents\Github\femto-apps\web-file-uploader\C:\Users\USER\AppData\Local\Temp\tmp-21636fth6rhRO9IAw\M3EDyV9G2G.txt.png'

Record the terminal

It would be awesome if this could support taking a screenshot from the terminal text, just like Asciinema, but static.

Option to choose output image name

Is it possible for the user to define the output image's name ? It seems to me that successive usage of the tool ends up overwriting the previous carbon.png instead of creating a new carbon(1).png.

Picture is not coming up Square

I don't know if there is a line limit on the code that after passing that limit the square is disable.

Here is my preset:

"blue": {
    "t": "seti",
    "bg": "#4A90E2",
    "wt": "sharp",
    "wc": true,
    "fm": "Droid Sans Mono",
    "fs": "14",
    "ln": false,
    "ds": true,
    "dsyoff": "20px",
    "dsblur": "68px",
    "wa": false,
    "lh": "133%",
    "pv": "30px",
    "ph": "30px",
    "si": true,
    "wm": false,
    "es": "4x",
    "type": "png",
    "paddingVertical": "56px",
    "paddingHorizontal": "56px",
    "backgroundImage": null,
    "backgroundImageSelection": null,
    "backgroundMode": "color",
    "backgroundColor": "F5A623",
    "dropShadow": true,
    "dropShadowOffsetY": "20px",
    "dropShadowBlurRadius": "68px",
    "theme": "material",
    "windowTheme": "none",
    "language": "auto",
    "fontFamily": "Fira Code",
    "fontSize": "14px",
    "lineHeight": "152%",
    "windowControls": true,
    "widthAdjustment": true,
    "lineNumbers": false,
    "firstLineNumber": 1,
    "exportSize": "2x",
    "watermark": false,
    "squaredImage": true,
    "hiddenCharacters": false,
    "loading": false,
    "icon": "/static/presets/7.png",
    "isVisible": true
  }

Generate images recursively from a directory

Sometimes it is needed to create images from a folder of sources, like an examples folder.
It'll be faster to allow directory path as input, and reuse the same browser session to create images from all the source files in the directory.

wdyt?

Allow configuring "theme colors" in presets

The Carbon CLI is really awesome and I love that it's possible to store and reuse a configuration as preset. One thing I'd love to add to the config though is the actual "theme colors" (i.e. what color e.g. variables, operators, keywords, comments, ...).

Basically these options from the Carbon web UI:

Screenshot 2019-03-26 at 10 39 45

Why opening the browser? Can't we render it locally?

Just found this amazing project, but find odd that it has to open the browser in order to render the image and then download it. Isn't it possible to run it locally? Faster rendering, no internet connection needed, and no dependancy to an external service.

I'm sure the code from carbon-now can be reused somehow. Not a web-dev myself, but happy to help if anyone wants to team up.

Allow ability to specify language

Hi team, I notice in the settings, that you cannot manually specify the language.

	// setting this manually will be ignored
	l: 'auto',

Which is frustrating, because if you are trying to extract code snippets from a markdown file, or a Jupyter notebook, or any file which doesnt have the right extension, you do not get the correct formatting. It would be great if we could specify this manually, instead of my current solution (which is to ignore the ability to take snippets, write my own code that does the snippeting and saving to a temporary file before deleting said file). I get why you may not want it in the preset or config (because that should be language agnostic), but having it as a command line argument when invoking would be great! If its already there and Ive simply missed it when reading the docs, I apologise :)

Generated Image cannot be found.

I used the following to generate the image:
carbon-now test.html

The following error resulted:

D:\test>carbon-now test.html
 √ Processing test.html
 √ Preparing connection
 ↓ Opening in browser [skipped]
 √ Fetching beautiful image

  Done!

  The file can be found here: D:\test/carbon.png 😌

  Error: Sending code to https://carbon.now.sh went wrong.

  This is mostly due to:

  – Insensical input like `--start 10 --end 2`
  – Carbon being down or taking too long to respond
  – Your internet connection not working or being too slow

The generated Image isn't available in the given path.

Incompatible with Carbon 3.6.0

Version 3.6.0 of Carbon and its UI changes introduced breaking changes to carbon-now-cli (again), due to selectors/the structure changing. This will be patched asap.

Just a question really

What font is that with the cool 'f'? The one in the example that starts like const unfold =

Allow reusing the settings of last interactive run

Great project! πŸ‘

It would be awesome to interactively run until you have a style that you like (if you don't already have one by using carbon.now.sh) and then be able to consistently reuse these settings with an additional commandline flag (that can not be combined with interactive mode).

e.g.

  • run -i first, pick your fonts, themes etc
  • run -c (cached) later, reusing the latest -i settings.

Language in config not working

The language config is not working using:

{
	"default":
	{
		"t": "one-dark",
		"l": "sh",
		"bg": "none",
		"wt": "none",
		"wc": true,
		"fm": "Hack",
		"fs": "16px",
		"ln": false,
		"ds": true,
		"dsyoff": "0",
		"dsblur": "0",
		"wa": false,
		"pv": "10px",
		"ph": "10px",
		"si": false,
		"wm": false,
		"es": "1x",
		"type": "svg"
	}
}

BTW: Never shorten keys, variables and stuff. You turned that config into a guessing game.

--headless stopped working

--headless times out in Fetching beautiful image step. This is due to Carbon removing #container-bg. Instead, .export-container needs to be used now. A test should also catch future failing --headless usage, since @dawnlabs could potentially change this again at any time.

Error when running any command.

Hi,

I am getting the following error when I try to run any command, including --help

jfernand  ~   carbon-now --help
/Users/jfernand/.nvm/versions/node/v8.0.0/lib/node_modules/carbon-now-cli/cli.js:82
			...settings,
			^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

I am running MacOS High Sierra 10.13.6 and node/npm v8.0.0

Chromium crashes before image can be saved

Error: Sending code to https://carbon.now.sh went wrong.
This is mostly due to:

  – Insensical input like `--start 10 --end 2`
  – Carbon being down or taking too long to respond
  – Your internet connection not working or being too slow

on MacOS, installed via npm.

Using custom theme

Hi,

there are many themes like dracula, base16-dark, etc... defined in carbon-now-sh, but I also can define a custom theme there.

Is it possible to use a custom theme with carbon-now-cli?

Kind regards,
Rokko

Image not downloaded correctly

Error: Sending code to https://carbon.now.sh went wrong.

This is mostly due to:

– Insensical input like --start 10 --end 2
– Carbon being down or taking too long to respond
– Your internet connection not working or being too slow

Feature request: Flag to specify a preset file

This CLI is very ... uhm ... special. None of the obvious flags do exist πŸ™ˆ

cat my-preset.json

{
    "t": "monokai",
    "bg": "#ADB7C1",
    "wt": "sharp",
    "wc": true,
    "fm": "Hack",
    "fs": "18px",
    "ln": false,
    "ds": true,
    "dsyoff": "20px",
    "dsblur": "68px",
    "wa": true,
    "lh": "133%",
    "pv": "16",
    "ph": "24",
    "si": false,
    "wm": false,
    "es": "2x",
    "type": "png"
}
carbon-now --preset-path=./my-preset.json test.js

Copy to clipboard

I use most of my Carbon images on Twitter to illustrate some code snippet. Would be useful if this tool could just put the image in the clipboard instead of writing to disk. For example, if I use the a --copy flag.

Carbon closes connection unexpectedly resulting in net::ERR_CONNECTION_CLOSED error

Hi,

I was trying to process a bash scripts file and the carbon-now-cli always shows that

Error: Sending code to https://carbon.now.sh went wrong

I uploaded my script here, and please try the following command on it.

First, carbon-now colortest, does't work.

There are 75 lines in the file, and changing the the -e option to a value smaller than or equal to 61, it will work.

Then, without modifying the -e, try changing the values for -s option, I find that the CLI would stop working if -s is greater than or equal to 5.

The correspondent code blocks that I suspect to be the cause of the bug are:

Line 4 to line 6:

colortest_usage () {
    echo -e "Usage: colortest [[-v|--verbose] | [-a|--all] | [-h|--help]]\n\nPrint out colors available in this terminal emulator. The default output is a short list of colors. If -v or --verbose is specified, a table containing all combination of background and foreground colors is displayed. Alternatively, if -a or -all is specified, then both short list and the detailed table would be displayed.\n\nNote that there should be no argument to this programme.\n  -v, --verbose\t displays a table with detailed table of combinations of colors.\n  -a, --all    \t displays both brief and detailed results.\n  -h, --help   \t displays this help."
}

And line 62 to line 71:

  while [[ "$#" > 0 ]]; do
    case "$1" in
      -h|--help) colortest_usage;;
      -v|--verbose) colortest_long;;
      -a|--all) colortest_short; colortest_long;;
      --) colortest_short;;
      *) echo "$0: Error(1): This function doesn't accept any argument." >&2 | logger; colortest_usage;unset -f colortest_usage colortest_short colortest_long; option; return 1;;
    esac
    shift
  done

It seems that as long as I'm not asking carbon-now-cli to process both code blocks, then it works fine.

Please take a look.
Thanks

Pretty cool but does not work well in Windows 10

Thanks for this great plugin for carbon. However, there are some problems with my own computer.

  1. carbon-now always complains those:
  √ Processing async_method.rb
  √ Preparing connection
  ↓ Opening in browser [skipped]
  Γ— Fetching beautiful image
    β†’ ENOENT: no such file or directory, rename 'D:\DemoPorojects\async\examples\carbon.png' -> 'D:\DemoPorojects\ a…
    Copying image to clipboard

  Error: Sending code to https://carbon.now.sh went wrong.

  This is mostly due to:

  – Insensical input like `--start 10 --end 2`
  – Carbon being down or taking too long to respond
  – Your internet connection not working or being too slow

It seems that we can not set the timeout value by input parameters. So I try to change headless-visit.js, set timeout from 2000 to 20000. It doesn't work.
2. Just like #28, if I use switch -o, chrome will not be opened then.

Is anything wrong with my env? Thanks!

Can't not install it

$ npm i -g carbon-now-cli
npm WARN deprecated [email protected]: cross-spawn no longer requires a build toolchain, use it instead
/usr/local/bin/carbon-now -> /usr/local/lib/node_modules/carbon-now-cli/cli.js

[email protected] install /usr/local/lib/node_modules/carbon-now-cli/node_modules/puppeteer
node install.js

ERROR: Failed to download Chromium r662092! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: connect ETIMEDOUT 64.233.162.83:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
-- ASYNC --
at BrowserFetcher. (/usr/local/lib/node_modules/carbon-now-cli/node_modules/puppeteer/lib/helper.js:110:27)
at Object. (/usr/local/lib/node_modules/carbon-now-cli/node_modules/puppeteer/install.js:64:16)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
address: '64.233.162.83',
port: 443 }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/horance/.npm/_logs/2019-06-01T02_21_43_394Z-debug.log

SVG fails with headless mode

Unfortunately, SVG dowloading / renaming fails with headless mode.

  βœ– Fetching beautiful image
    β†’ ENOENT: no such file or directory, rename '...' -> '...'
    Copying image to clipboard

  Error: Sending code to https://carbon.now.sh went wrong.

Enable piping

It would be cool if we could copy some code, then run pbpaste | carbon-now to make an image of the clipboard contents.

Typescript can't render color

Please check this code.

https://carbon.now.sh/?bg=rgba(0,0,0,0)&t=duotone-dark&wt=none&l=typescript&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=48px&ph=32px&ln=false&fm=Hack&fs=13px&lh=133%25&si=false&code=class%2520OlapTable%2520extends%2520TableCtrl%2520%257B%250A%2520%2520constructor(public%2520config%253A%2520any)%2520%257B%250A%2520%2520%2520%2520super(config)%253B%250A%2520%2520%257D%250A%250A%2520%2520%252F**%250A%2520%2520%2520*%2520%25E8%25BF%2599%25E4%25B8%25AA%25E6%2596%25B9%25E6%25B3%2595%25E5%258F%25AA%25E6%2598%25AF%25E5%258D%258F%25E5%258A%25A9%25E5%258F%2591%25E5%25B0%2584%25E8%25B0%2583%25E7%2594%25A8dataBack%250A%2520%2520%2520*%252F%250A%2520%2520public%2520resHandle(res)%2520%257B%250A%2520%2520%2520%2520%252F%252F%2520sql%252Folap%2520%25E8%258E%25B7%25E5%258F%2596%25E5%259B%259E%25E6%259D%25A5%25E7%259A%2584%25E6%2595%25B0%25E6%258D%25AE%25E6%25A0%25BC%25E5%25BC%258F%25E4%25B8%258D%25E4%25B8%2580%25E6%25A0%25B7%250A%2520%2520%2520%2520if%2520(this.config.mode)%2520%257B%250A%2520%2520%2520%2520%2520%2520this.data%2520%253D%2520res.data.data%253B%250A%2520%2520%2520%2520%257D%2520else%2520%257B%250A%2520%2520%2520%2520%2520%2520this.data%2520%253D%2520res.data%253B%250A%2520%2520%2520%2520%257D%250A%2520%2520%2520%2520this.pageObj.total%2520%253D%2520res.total%253B%250A%2520%2520%2520%2520this.config.dataBack(res.data)%253B%250A%250A%2520%2520%2520%2520this.calculateExtend()%253B%250A%2520%2520%257D%250A%250A%2520%2520public%2520errHandle(res)%2520%257B%250A%2520%2520%2520%2520return%2520this.config.errBack(res)%253B%250A%2520%2520%257D%250A%250A%2520%2520%252F%252F%2520%25E5%25A4%2584%25E7%2590%2586table%25E5%258D%2595%25E5%2585%2583%25E6%25A0%25BC%25E6%2598%25BE%25E7%25A4%25BA%25E6%2597%25B6%25E9%259C%2580%25E8%25A6%2581%252C%2520%25E5%258D%2583%25E5%2588%2586%25E4%25BD%258D%25E5%2595%25A5%25E7%259A%2584%25E5%2586%2585%25E5%25AE%25B9%250A%2520%2520public%2520renderCell(text%253A%2520string%252C%2520keyname%253A%2520string)%2520%257B%250A%2520%2520%2520%2520return%2520handleCellText(text%252C%2520findSourceData(keyname%252C%2520queryConfig%252C%2520%27theIndex%27))%253B%250A%2520%2520%257D%250A%257D&es=2x&wm=false

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.