Convert Figma logo to code with AI

mixn logocarbon-now-cli

🎨 Beautiful images of your code — from right inside your terminal.

5,752
117
5,752
12

Top Related Projects

34,532

:black_heart: Create and share beautiful images of your source code

:clapper: Colorful animations in terminal output

21,891

🖍 Terminal string styling done right

📄 CLI that generates beautiful README.md files

Quick Overview

The carbon-now-cli is a command-line interface (CLI) tool that allows users to create beautiful images of their code snippets. It integrates with the Carbon website, a popular code-to-image generator, and provides a seamless way to capture and share code snippets.

Pros

  • Ease of Use: The CLI tool is straightforward to use, with a simple command-line interface that makes it easy to generate code images.
  • Customization: Users can customize the appearance of the code images, including the syntax highlighting, background color, and font.
  • Integration with Carbon: The tool seamlessly integrates with the Carbon website, allowing users to quickly and easily create code images.
  • Cross-platform Compatibility: The CLI tool is available for multiple platforms, including Windows, macOS, and Linux.

Cons

  • Dependency on Carbon: The tool is dependent on the Carbon website, which means that if the Carbon service is unavailable or changes, the tool may not function as expected.
  • Limited Functionality: The tool is focused on generating code images and does not provide additional features beyond that, which may limit its usefulness for some users.
  • Potential Privacy Concerns: The tool requires users to upload their code snippets to the Carbon website, which may raise privacy concerns for some users.
  • Lack of Offline Functionality: The tool requires an internet connection to generate code images, which may be a limitation for users in areas with poor internet connectivity.

Getting Started

To get started with carbon-now-cli, follow these steps:

  1. Install the tool using npm:
npm install -g carbon-now-cli
  1. Run the tool with the carbon-now command, passing in the file path of the code you want to capture:
carbon-now path/to/your/code.js
  1. The tool will open a browser window and display the generated code image. You can then save the image or share it with others.

  2. You can customize the appearance of the code image by passing in additional options, such as the theme, background color, and font:

carbon-now path/to/your/code.js --theme seti --bg "rgba(171, 184, 195, 0.4)" --font "Hack"

Competitor Comparisons

34,532

:black_heart: Create and share beautiful images of your source code

Pros of Carbon

  • Web-based interface for easy access and sharing
  • More customization options for image styling
  • Supports multiple languages and themes out-of-the-box

Cons of Carbon

  • Requires internet connection to use
  • Less suitable for batch processing or automation
  • May have slower performance for large code snippets

Code Comparison

Carbon (React component):

export default function Carbon() {
  return (
    <div className="carbon-container">
      <Editor />
      <Controls />
      <ExportButton />
    </div>
  )
}

carbon-now-cli (Node.js CLI):

#!/usr/bin/env node
const meow = require('meow')
const carbonNowCli = require('.')

const cli = meow(`
  Usage
    $ carbon-now <file>
    $ carbon-now <file> -l <language>
`)

carbonNowCli(cli.input[0], cli.flags)

The Carbon project is a web-based application built with React, offering a user-friendly interface for creating code screenshots. It provides more visual customization options but requires an internet connection.

carbon-now-cli is a command-line tool that allows for quick code image generation from the terminal. It's more suitable for automation and batch processing but has fewer styling options compared to the web-based Carbon.

Both projects aim to create beautiful code images, but they cater to different use cases and preferences.

:clapper: Colorful animations in terminal output

Pros of chalk-animation

  • Focuses on creating animated text in the terminal, offering a variety of animation styles
  • Lightweight and easy to integrate into existing Node.js projects
  • Provides a simple API for creating and controlling animations

Cons of chalk-animation

  • Limited to text animations, while carbon-now-cli offers image generation capabilities
  • May not be suitable for projects requiring static code snippets or images
  • Less versatile in terms of output formats and sharing options

Code Comparison

chalk-animation:

const chalkAnimation = require('chalk-animation');
const rainbow = chalkAnimation.rainbow('Hello, animated world!');
setTimeout(() => {
    rainbow.stop();
}, 2000);

carbon-now-cli:

carbon-now file.js -l /tmp -t oceanic-dark

Summary

chalk-animation is ideal for adding dynamic, colorful text animations to terminal applications, while carbon-now-cli excels in generating static, shareable code snippets as images. The choice between the two depends on whether you need animated terminal output or visually appealing code screenshots for documentation or sharing purposes.

21,891

🖍 Terminal string styling done right

Pros of chalk

  • Lightweight and focused on terminal string styling
  • Highly performant with minimal dependencies
  • Widely adopted and well-maintained

Cons of chalk

  • Limited to terminal output styling
  • Doesn't provide image generation capabilities
  • Requires manual implementation for complex formatting

Code comparison

carbon-now-cli:

const Carbon = require('carbon-now-cli');

Carbon('console.log("Hello, World!")', {
  theme: 'seti',
  backgroundColor: '#ADB7C1'
}).then(console.log);

chalk:

const chalk = require('chalk');

console.log(chalk.blue.bold('Hello') + ' World' + chalk.red('!'));

Key differences

  • carbon-now-cli focuses on generating beautiful code images
  • chalk specializes in styling terminal output
  • carbon-now-cli offers more visual customization options
  • chalk provides simpler and more direct string manipulation
  • carbon-now-cli integrates with the Carbon web service
  • chalk operates entirely locally without external dependencies

Both tools serve different purposes: carbon-now-cli for creating visually appealing code snippets, and chalk for enhancing terminal output. The choice between them depends on whether you need image generation or terminal styling capabilities.

📄 CLI that generates beautiful README.md files

Pros of readme-md-generator

  • Specifically designed for generating README files, providing a more focused and tailored solution
  • Interactive CLI prompts guide users through the README creation process
  • Supports multiple languages and includes badges for various services

Cons of readme-md-generator

  • Limited to README generation, while carbon-now-cli offers broader code snippet sharing capabilities
  • May require more manual input compared to carbon-now-cli's automatic code parsing
  • Less emphasis on visual aesthetics compared to carbon-now-cli's image output

Code Comparison

readme-md-generator:

const generateReadme = require('readme-md-generator');

generateReadme({
  projectName: 'My Project',
  projectDescription: 'A cool project'
});

carbon-now-cli:

const carbonNow = require('carbon-now-cli');

carbonNow('./myCode.js', {
  backgroundColor: '#1A1A1A',
  theme: 'seti'
});

While both tools are command-line utilities, they serve different purposes. readme-md-generator focuses on creating comprehensive README files for projects, while carbon-now-cli specializes in generating visually appealing code snippet images. The choice between the two depends on whether you need to create project documentation or share code visually.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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

NPM DownloadsLast 30 Days