### Full Carbon Now CLI Example with Multiple Options Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command demonstrates a comprehensive usage of carbon-now-cli, specifying start and end lines, a custom save path and filename, and enabling interactive mode for further customization before saving the image. ```bash carbon-now _unfold.js --start 3 --end 6 --save-to ~/Desktop --save-as example-23 --interactive ``` -------------------------------- ### Install xclip utility on Debian/Ubuntu Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md Instructions for installing the `xclip` utility on Debian-based Linux distributions using the apt package manager. `xclip` is required for the `--to-clipboard` functionality of carbon-now-cli on Linux. ```bash sudo apt-get install xclip ``` -------------------------------- ### PromptModule API Usage (TypeScript) Source: https://context7.com/mixn/carbon-now-cli/llms.txt Example of how to use the PromptModule API in TypeScript to initialize the CLI and access parsed command-line flags, input content, and interactive mode answers. ```typescript import PromptModule from './src/modules/prompt.module.js'; // Create prompt instance const Prompt = await PromptModule.create(); // Access parsed CLI flags const flags = Prompt.getFlags; console.log(flags.start); // Starting line number console.log(flags.end); // Ending line number console.log(flags.interactive); // Boolean: interactive mode console.log(flags.preset); // Preset name to use // Get input file path const file = Prompt.getFile; console.log(file); // "mycode.js" // Get raw input content const input = Prompt.getInput; console.log(input); // File contents or stdin/clipboard data // Get interactive mode answers (if --interactive was used) const answers = Prompt.getAnswers; console.log(answers.theme); // Selected theme console.log(answers.fontFamily); // Selected font ``` -------------------------------- ### Complete Programmatic Workflow Example in TypeScript Source: https://context7.com/mixn/carbon-now-cli/llms.txt This TypeScript snippet demonstrates a full programmatic workflow for generating code images using Carbon Now CLI. It initializes various modules, configures settings based on file type and presets, processes input code, constructs the Carbon URL with specified parameters, and then renders and downloads the image. Dependencies include 'query-string'. Input is handled via a prompt module, and output is saved to disk. ```typescript import PromptModule from './src/modules/prompt.module.js'; import PresetHandlerModule from './src/modules/preset-handler.module.js'; import FileHandlerModule from './src/modules/file-handler.module.js'; import DownloadModule from './src/modules/download.module.js'; import RendererModule from './src/modules/renderer.module.js'; import queryString from 'query-string'; // Initialize modules const Prompt = await PromptModule.create(); const file = Prompt.getFile; const flags = Prompt.getFlags; const input = Prompt.getInput; const FileHandler = new FileHandlerModule(file); const PresetHandler = new PresetHandlerModule(); const Download = new DownloadModule(file); // Configure settings PresetHandler.mergeSettings({ language: FileHandler.getMimeType, titleBar: FileHandler.getFileName, }); if (flags.preset !== 'latest-preset') { const preset = await PresetHandler.getPreset(flags.preset); PresetHandler.mergeSettings(preset); } // Process input const processedCode = await FileHandler.process( input, flags.start, flags.end ); const encodedContent = encodeURIComponent(processedCode); // Build Carbon URL const settings = PresetHandler.getSettings; const carbonUrl = `https://carbon.now.sh/?${queryString.stringify({ code: encodedContent, theme: settings.theme, backgroundColor: settings.backgroundColor, fontFamily: settings.fontFamily, fontSize: settings.fontSize, lineNumbers: settings.lineNumbers, exportSize: settings.exportSize })}`; // Render and download Download.setFlags = flags; Download.setImgType = settings.type; const Renderer = await RendererModule.create( flags.engine, flags.disableHeadless, settings.type ); await Renderer.download( carbonUrl, Download.getSaveDirectory, Download.getDownloadedAsFileName ); await FileHandler.rename( Download.getDownloadedAsPath, Download.getSavedAsPath ); console.log(`Image saved to: ${Download.getSavedAsPath}`); ``` -------------------------------- ### Preset Configuration File Structure (JSON) Source: https://context7.com/mixn/carbon-now-cli/llms.txt Example JSON structure for defining custom presets, including themes, background colors, window styles, fonts, and custom color overrides for specific elements. ```json { "presentation": { "theme": "seti", "backgroundColor": "#ADB7C1", "windowTheme": "none", "windowControls": true, "fontFamily": "Hack", "fontSize": "18px", "lineNumbers": false, "firstLineNumber": 1, "selectedLines": "*", "dropShadow": false, "dropShadowOffsetY": "20px", "dropShadowBlurRadius": "68px", "widthAdjustment": true, "width": "20000px", "lineHeight": "133%", "paddingVertical": "48px", "paddingHorizontal": "32px", "squaredImage": false, "watermark": false, "exportSize": "2x", "type": "png" }, "hacker": { "backgroundColor": "rgba(0, 255, 0, 1)", "windowTheme": "bw", "fontFamily": "Anonymous Pro", "fontSize": "18px", "exportSize": "2x", "type": "png", "custom": { "background": "rgba(0, 0, 0, 1)", "text": "rgba(0, 255, 0, 1)", "variable": "rgba(0, 255, 0, 1)", "keyword": "rgba(0, 255, 0, 1)", "string": "rgba(0, 255, 0, 1)", "comment": "rgba(0, 255, 0, 1)" } } } ``` -------------------------------- ### Launch Interactive Mode for Carbon Now CLI Customization Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command starts the carbon-now-cli in interactive mode, allowing the user to customize various aspects of the generated image, including theme, font family, padding, and more, before outputting the final image. ```bash carbon-now _unfold.js --interactive ``` -------------------------------- ### Copy Image to Clipboard using Carbon Now CLI Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command generates an image from the specified file and copies it directly to the system clipboard instead of saving it to disk. On Linux, this functionality requires the `xclip` utility to be installed. ```bash carbon-now _unfold.js --to-clipboard ``` -------------------------------- ### Generate Image for Specific Lines with Carbon Now CLI Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command generates an image from a JavaScript file, specifically capturing lines 3 through 6. It will produce an error if the start line number is greater than the end line number. ```bash carbon-now _unfold.js --start 3 --end 6 ``` -------------------------------- ### Process Files with FileHandlerModule Source: https://context7.com/mixn/carbon-now-cli/llms.txt Handles file content processing and metadata extraction. Initialize with a file path, process specific line ranges, get the MIME type for syntax highlighting, retrieve the base filename, and rename files. Dependencies include the FileHandlerModule. ```typescript import FileHandlerModule from './src/modules/file-handler.module.js'; // Initialize with file path const FileHandler = new FileHandlerModule('src/index.js'); // Process input with line selection const processedCode = await FileHandler.process( input, startLine = 5, endLine = 15 ); console.log(processedCode); // Returns lines 5-15 // Get MIME type for syntax highlighting const mimeType = FileHandler.getMimeType; console.log(mimeType); // "javascript" or "auto" if unknown // Get base filename const fileName = FileHandler.getFileName; console.log(fileName); // "index.js" // Rename file await FileHandler.rename( '/tmp/carbon-abc123.png', '/home/user/Desktop/final-image.png' ); ``` -------------------------------- ### JavaScript Code Example for 'unfold' function Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This JavaScript snippet defines a recursive function `unfold` that processes a seed value using a provided function `f`. It accumulates results until `f` returns null or undefined. This is a functional programming pattern. ```javascript // 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, []) }; ``` -------------------------------- ### Preset Management for Reusable Configurations (Bash) Source: https://context7.com/mixn/carbon-now-cli/llms.txt Covers creating, saving, and reusing configuration presets for consistent code image styling. Includes options for interactive preset creation and overriding settings. ```bash # Create preset interactively carbon-now mycode.js --interactive # During prompt, save preset with name: "presentation" # Preset saved to ~/.carbon-now.json # Use saved preset carbon-now mycode.js --preset presentation # Override specific settings for one run carbon-now mycode.js --preset presentation --settings '{"theme": "nord", "fontSize": "20px"}' # Use local config file (read-only, for team sharing) carbon-now mycode.js --config ./team-config.json --preset dark ``` -------------------------------- ### Provide Input to Carbon Now CLI via stdin Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md Demonstrates how to pipe content into the carbon-now-cli tool using standard input (`stdin`). This allows generating images from content copied from the clipboard (`pbpaste`) or directly from echoed strings. ```bash pbpaste | carbon-now echo '

Hi

' | carbon-now ``` -------------------------------- ### Apply Local Configuration with a Preset Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command uses the carbon-now-cli tool to apply settings from a local configuration file named `local-config.json` and applies the 'dark' preset. Local configurations are read-only and do not update the `latest-preset` setting. ```bash carbon-now _unfold.js --config local-config.json --preset dark ``` -------------------------------- ### Input Sources for Code Image Generation (Bash) Source: https://context7.com/mixn/carbon-now-cli/llms.txt Demonstrates how to pipe code from standard input (stdin), clipboard, or directly using flags. Also shows how to specify output file names and locations. ```bash # From stdin using pipe echo "console.log('Hello World');" | carbon-now # From clipboard pbpaste | carbon-now # Or using the flag carbon-now --from-clipboard # Multiple files with custom output location carbon-now src/index.js --save-to ~/Desktop --save-as my-code # Result: Saves to ~/Desktop/my-code.png ``` -------------------------------- ### Preview Image in Browser with Carbon Now CLI Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command generates an image for lines 3 to 6 of a file and opens the result directly in the default web browser instead of saving it to disk. It also enables interactive mode for customization. ```bash carbon-now _unfold.js --start 3 --end 6 --interactive --open-in-browser ``` -------------------------------- ### Manage Presets with PresetHandlerModule Source: https://context7.com/mixn/carbon-now-cli/llms.txt Allows management of preset configurations and settings. Initialize with default or custom paths, load saved presets, merge new settings, save presets to config files, and retrieve current settings. Dependencies include the PresetHandlerModule itself. ```typescript import PresetHandlerModule from './src/modules/preset-handler.module.js'; // Initialize with default or custom config path const PresetHandler = new PresetHandlerModule(); // Or with custom config: new PresetHandlerModule('./my-config.json'); // Load a saved preset const presetSettings = await PresetHandler.getPreset('presentation'); console.log(presetSettings.theme); // "seti" console.log(presetSettings.fontSize); // "18px" // Merge settings (combines with existing) PresetHandler.mergeSettings({ language: 'javascript', titleBar: 'myfile.js', theme: 'nord' }); // Save preset to config file await PresetHandler.savePreset('my-preset', { theme: 'nord', backgroundColor: '#2E3440', fontSize: '16px', lineNumbers: true }); // Get current settings const currentSettings = PresetHandler.getSettings; console.log(currentSettings.theme); // Current theme console.log(currentSettings.fontSize); // Current font size ``` -------------------------------- ### Create and Save a Preset Configuration (TypeScript) Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This TypeScript object represents a saved preset configuration for the Carbon Now CLI. Presets are stored in `~/.carbon-now.json` and define various visual aspects of the generated code snippet images. The `latest-preset` key is dynamic, while named presets like `presentation` persist. ```typescript { "latest-preset": { // Equal to `presentation` below }, "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, "width": "20000px", "lineHeight": "140%", "paddingVertical": "35px", "paddingHorizontal": "35px", "squaredImage": false, "watermark": false, "exportSize": "2x", "type": "png" } } ``` -------------------------------- ### Manage Downloads with DownloadModule Source: https://context7.com/mixn/carbon-now-cli/llms.txt Manages download paths and file naming conventions. Initialize with a filename, configure save locations, filenames, and image types. Retrieves the save directory (expanding '~'), original filename without extension, the final save path, and the temporary download path. Dependencies include the DownloadModule. ```typescript import DownloadModule from './src/modules/download.module.js'; // Initialize with file path const Download = new DownloadModule('mycode.js'); // Configure download settings Download.setFlags = { saveTo: '~/Desktop', saveAs: 'beautiful-code', toClipboard: false }; Download.setImgType = 'png'; // Get save directory (expands ~ to home directory) const saveDir = Download.getSaveDirectory; console.log(saveDir); // "/Users/username/Desktop" // Get original filename without extension const originalName = Download.getOriginalFileName; console.log(originalName); // "mycode" // Get final save path const savePath = Download.getSavedAsPath; console.log(savePath); // "/Users/username/Desktop/beautiful-code.png" // Get temporary download path (before renaming) const tempPath = Download.getDownloadedAsPath; console.log(tempPath); // "/tmp/carbon-xyz789.png" ``` -------------------------------- ### Generate Image from Clipboard Content with Carbon Now CLI Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command instructs carbon-now-cli to take its input directly from the system clipboard, generating an image from the content currently copied. ```bash carbon-now --from-clipboard ``` -------------------------------- ### Generate Image with Default Carbon Now CLI Settings Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command generates a PNG image from the specified JavaScript file using the default settings of the carbon-now-cli tool. The output image is saved in the current working directory. ```bash carbon-now _unfold.js ``` -------------------------------- ### Generate Code Image from File (Bash) Source: https://context7.com/mixn/carbon-now-cli/llms.txt Basic command-line usage for generating a code image from a specified file. Supports line selection, interactive mode, preset usage, clipboard output, and browser preview. ```bash # Generate image from a JavaScript file with default settings carbon-now mycode.js # Result: Creates mycode-.png in current directory # Generate image with line selection carbon-now mycode.js --start 10 --end 25 # Generate interactive mode with full customization carbon-now mycode.js --interactive # Use a saved preset carbon-now mycode.js --preset presentation # Copy to clipboard instead of saving carbon-now mycode.js --to-clipboard # Open in browser for manual adjustment carbon-now mycode.js --open-in-browser ``` -------------------------------- ### Carbon CLI Preset Interface Definition (TypeScript) Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This TypeScript interface defines the structure and available options for a Carbon CLI preset. It outlines properties for background color, drop shadows, export size, fonts, line numbers, padding, themes, and more. Some properties are automatically detected and not persisted. ```typescript interface CarbonCLIPresetInterface { backgroundColor: string; dropShadow: boolean; dropShadowBlurRadius: string; dropShadowOffsetY: string; exportSize: '1x' | '2x' | '4x'; firstLineNumber: number; fontFamily: CarbonFontFamilyType; fontSize: string; lineHeight: string; lineNumbers: boolean; paddingHorizontal: string; paddingVertical: string; selectedLines: string; // All: "*"; Lines 3-6: "3,4,5,6", etc. squaredImage: boolean; theme: CarbonThemeType; type: 'png' | 'svg'; watermark: boolean; widthAdjustment: boolean; windowControls: boolean; windowTheme: 'none' | 'sharp' | 'bw'; custom?: CarbonThemeHighlightsInterface; width?: string; // Below are detected automatically, and not persisted as keys language?: string; titleBar?: string; } ``` -------------------------------- ### Override Carbon Now CLI Settings with JSON Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command generates an image using the 'presentation' preset but overrides specific settings like the theme to 'nord' and the title bar to 'custom-title.js' using an inline JSON string. ```bash carbon-now _unfold.js --preset presentation --settings '{"theme": "nord", "titleBar": "custom-title.js"}' ``` -------------------------------- ### Command to Generate Image with Custom Theme Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md This command utilizes the carbon-now-cli tool to generate an image from a JavaScript file, applying a preset named 'hacker' which includes custom theme colors defined in the configuration. ```bash carbon-now _unfold.js --preset hacker ``` -------------------------------- ### Render Code Images with RendererModule Source: https://context7.com/mixn/carbon-now-cli/llms.txt Utilizes Playwright for browser automation to render code images. Create a renderer instance specifying the engine, headless mode, and output type. Optionally set custom theme colors. Downloads images from Carbon URLs to a specified directory with a given filename. Dependencies include RendererModule and Playwright. ```typescript import RendererModule from './src/modules/renderer.module.js'; // Create renderer with engine and options const Renderer = await RendererModule.create( 'chromium', // Engine: 'chromium', 'firefox', or 'webkit' false, // disableHeadless: false for headless mode 'png' // Output type: 'png' or 'svg' ); // Set custom theme colors (optional) await Renderer.setCustomTheme({ background: 'rgba(0, 0, 0, 1)', text: 'rgba(0, 255, 0, 1)', variable: 'rgba(0, 255, 0, 1)', keyword: 'rgba(255, 255, 0, 1)', string: 'rgba(0, 255, 255, 1)', comment: 'rgba(128, 128, 128, 1)' }, 'my-custom-theme'); // Download image from Carbon URL const carbonUrl = 'https://carbon.now.sh/?code=console.log("hello")&theme=seti'; await Renderer.download( carbonUrl, '/Users/username/Desktop', // Save directory 'my-code' // Filename without extension ); // Result: Saves to /Users/username/Desktop/my-code.png // Browser automatically closes after download ``` -------------------------------- ### Define Custom Theme Colors for Carbon Now CLI Source: https://github.com/mixn/carbon-now-cli/blob/master/readme.md Allows users to define custom theme colors for styling code snippets. This feature requires a `custom` key within a preset configuration, specifying colors for various syntax elements. The colors are applied via localStorage in Playwright instances. ```typescript 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; } { "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)" } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.