Skip to main content

Koloro - colorful terminal text in Python

Project description

K o l o r o

CI status PyPI version PyPI - Downloads

Koloro - colorful terminal text in Python

Koloro preview

Usage

Install with pip:

pip install koloro
import koloro

print(koloro.red(f"Error: something was wrong in {koloro.cyan('main.py')}"))

The following environment variables can be used to disable color output globally:

  • Disable settings:

    • NO_COLOR (assigning something to NO_COLOR disables color output regardless of the value)
    • TERM=dumb
  • Enable settings:

    • FORCE_COLOR (assigning something to FORCE_COLOR enables color output regardless of the value)

Moreover, the enabled variable can also be used to toggle color output on and off:

import koloro

# color output on
koloro.enabled = True
print(koloro.cyan("foo"))  # -> "\u001b[36mfoo\u001b[39m"

# color output off
koloro.enabled = False
print(koloro.cyan("foo"))  # -> "foo"

Stripping ANSI codes function is also provided:

import koloro

print(koloro.cyan("foo"))  # -> "\u001b[36mfoo\u001b[39m"
print(koloro.strip_ansi(koloro.cyan("foo")))  # -> "foo"

There is also functions for ANSI 256 colors output:

import koloro

# code number 12 from https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
print(koloro.ansi256(12)('foo'))  # -> "\u001b[38;5;12mfoo\u001b[0m"
import koloro

# code number 12 from https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
print(koloro.ansi256Bg(12)(koloro.black('foo')))  # -> "\u001b[48;5;12mfoo\u001b[0m"

API Reference

Below functions require one argument txt.

Modifiers

  • reset
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite

Bright colors

  • grey
  • brightRed
  • brightGreen
  • brightYellow
  • brightBlue
  • brightMagenta
  • brightCyan
  • brightWhite

Bright background colors

  • bgGrey
  • bgBrightRed
  • bgBrightGreen
  • bgBrightYellow
  • bgBrightBlue
  • bgBrightMagenta
  • bgBrightCyan
  • bgBrightWhite

ANSI 256 colors

  • ansi256

    • Arguments:

      • n (int) - color code from ANSI 256
    • Returns:

      • a function who argument is the text to display color output
  • ansi256Bg

    • Arguments:

      • n (int) - color code from ANSI 256
    • Returns:

      • a function who argument is the text to display color output
  • strip_ansi

    • Arguments:

      • string (str) - ANSI colored string
    • Returns:

      • a string which no ANSI codes

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

koloro-0.1.4-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page