{"id":17417,"library":"cli-styles","title":"CLI Styles","description":"cli-styles is a lightweight utility library designed to standardize the visual appearance of command-line interface (CLI) applications, particularly in relation to user prompts. Instead of being a prompt solution itself, it provides a consistent set of styles for user input (e.g., default, password, invisible), status indicators (question, success, error marks), and prompt delimiters (e.g., '›'). This enables different prompt libraries to adopt a uniform look and feel. The package is currently at version 1.0.0, released in February 2020, and does not appear to be under active development, maintaining a stable API. It is frequently used in conjunction with `prompt-skeleton` and a suite of dedicated prompt libraries like `text-prompt` and `select-prompt` to ensure visual coherence across an application's CLI interactions. Its primary differentiator is its focus on providing reusable styling primitives rather than a full-fledged prompt system.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/derhuerst/cli-styles","tags":["javascript","cli","terminal","prompt","style","consistent"],"install":[{"cmd":"npm install cli-styles","lang":"bash","label":"npm"},{"cmd":"yarn add cli-styles","lang":"bash","label":"yarn"},{"cmd":"pnpm add cli-styles","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides color and styling capabilities for terminal output.","package":"chalk","optional":false},{"reason":"Offers ANSI escape codes for cursor manipulation, particularly for 'invisible' input styles.","package":"ansi-escapes","optional":false}],"imports":[{"note":"The package is CommonJS-first and exports a single default object. While bundlers like Webpack or Rollup might allow this syntax, direct Node.js ESM usage often requires careful configuration or a dynamic import for older CJS modules. Named imports will result in `undefined`.","wrong":"import { input, indicator, delimiter } from 'cli-styles'","symbol":"cliStyles","correct":"import cliStyles from 'cli-styles'"},{"note":"This is the primary and most reliable way to import 'cli-styles' in Node.js environments, given its CommonJS module format.","symbol":"cliStyles (CommonJS)","correct":"const cliStyles = require('cli-styles')"},{"note":"The 'input' property is an object containing various input style functions (e.g., 'default', 'password'). You must access the specific style function, not call 'input' directly.","wrong":"cliStyles.input('Your input')","symbol":"input.default","correct":"cliStyles.input.default('Your input')"}],"quickstart":{"code":"import cliStyles from 'cli-styles';\nimport readline from 'readline';\n\nconst rl = readline.createInterface({\n  input: process.stdin,\n  output: process.stdout\n});\n\nasync function runPrompt() {\n  // Using the question indicator and delimiter\n  process.stdout.write(cliStyles.indicator.question + ' ' + cliStyles.delimiter + ' ');\n\n  // Using default input style\n  const question = cliStyles.input.default('What is your name? ');\n  rl.question(question, (name) => {\n    if (name.length > 0) {\n      process.stdout.write(cliStyles.indicator.success + ' ' + cliStyles.delimiter + ' ');\n      console.log(cliStyles.input.default(`Hello, ${name}!`));\n    } else {\n      process.stdout.write(cliStyles.indicator.error + ' ' + cliStyles.delimiter + ' ');\n      console.log(cliStyles.input.default('Name cannot be empty.'));\n    }\n    rl.close();\n  });\n}\n\nrunPrompt();\n","lang":"javascript","description":"Demonstrates how to import 'cli-styles' and apply its input styles, status indicators, and delimiters to a basic readline prompt to achieve a consistent look."},"warnings":[{"fix":"Use `import cliStyles from 'cli-styles'` for ESM, which will import the default export, then access properties like `cliStyles.input`. For CommonJS, use `const cliStyles = require('cli-styles')`.","message":"cli-styles is a CommonJS module and does not natively support named ESM imports. Attempting `import { input } from 'cli-styles'` will fail or result in `undefined` values in pure ESM environments.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider evaluating alternative, actively maintained libraries for new projects if future compatibility or features are critical. For existing projects, be mindful of potential issues with newer Node.js versions or terminal emulation that may not be addressed.","message":"The package is not actively maintained since its last update in February 2020. While stable at 1.0.0, users should be aware that new features, bug fixes, or updates for compatibility with newer Node.js versions or terminal features are unlikely.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always access the specific style function or string, e.g., `cliStyles.input.default('text')` or `cliStyles.indicator.success`. Integrate these outputs with a proper prompt library like `prompt-skeleton` or Node.js's `readline` module.","message":"cli-styles is not a prompt library itself; it provides styling primitives for existing prompt implementations. Directly calling `cliStyles.input` or `cliStyles.indicator` will not render a prompt or text, as these are objects containing styling functions or pre-styled strings.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Inspect your `package-lock.json` for `cli-styles`'s `chalk` dependency. If conflicts arise, consider using `npm dedupe` or manually resolving dependency trees. For new projects, evaluate alternatives that use up-to-date dependencies.","message":"The package depends on older versions of `chalk` (implicitly via its `package.json` at the time of 1.0.0 release). This might lead to dependency conflicts if your project uses a much newer `chalk` version, or it might not leverage the latest color capabilities or performance improvements.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"For ESM, use `import cliStyles from 'cli-styles';` to import the default export. For CommonJS, ensure your file is `.cjs` or `\"type\": \"commonjs\"` is specified, or simply use the default Node.js behavior.","cause":"Attempting to use `require('cli-styles')` in an ECMAScript Module (ESM) context (e.g., in a `.mjs` file or a module with `\"type\": \"module\"` in `package.json`).","error":"ReferenceError: require is not defined"},{"fix":"Ensure `cliStyles` is imported correctly (e.g., `const cliStyles = require('cli-styles')` or `import cliStyles from 'cli-styles'`). The `input.default` property is a function provided by `chalk`, so verify `chalk` is also correctly resolved within `cli-styles`.","cause":"This error is unlikely to occur unless `cliStyles` itself is not correctly imported or is `undefined`. More commonly, `cliStyles.input` might be treated as a function if `cliStyles` isn't properly destructured or imported as a default.","error":"TypeError: cliStyles.input.default is not a function"},{"fix":"Import the entire default export: `import cliStyles from 'cli-styles'`. Then access its properties: `cliStyles.input.default(...)`.","cause":"This error often happens if you've attempted named destructuring like `import { input } from 'cli-styles'` in an ESM context. Since `cli-styles` only has a default export, `input` would be `undefined`.","error":"TypeError: Cannot read properties of undefined (reading 'default') at Object.input"}],"ecosystem":"npm","meta_description":null}