Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.4 KB
Raw Blame
import { createColors } from 'picocolors'

export type ColorScheme = {
  bold: (s: string) => string
  dim: (s: string) => string
  cyan: (s: string) => string
  green: (s: string) => string
  yellow: (s: string) => string
  magenta: (s: string) => string
  successIcon: () => string
  warningIcon: () => string
  failureIcon: () => string
}

const identity = (s: string): string => s

export function colorScheme(enabled: boolean): ColorScheme {
  if (!enabled) {
    return {
      bold: identity,
      dim: identity,
      cyan: identity,
      green: identity,
      yellow: identity,
      magenta: identity,
      successIcon: () => '✓',
      warningIcon: () => '!',
      failureIcon: () => '✗',
    }
  }
  // createColors(true) forces ANSI output regardless of TTY/env so this module
  // never reads the environment itself; callers decide enablement via colorEnabled.
  const pc = createColors(true)
  return {
    bold: (s) => pc.bold(s),
    dim: (s) => pc.dim(s),
    cyan: (s) => pc.cyan(s),
    green: (s) => pc.green(s),
    yellow: (s) => pc.yellow(s),
    magenta: (s) => pc.magenta(s),
    successIcon: () => pc.green('✓'),
    warningIcon: () => pc.yellow('!'),
    failureIcon: () => pc.red('✗'),
  }
}

export const NO_COLOR_ENV = 'NO_COLOR'

export function colorEnabled(isTTY: boolean, env: NodeJS.ProcessEnv): boolean {
  return isTTY && env[NO_COLOR_ENV] === undefined
}