All Projects → reorx → Python Terminal Color

reorx / Python Terminal Color

Licence: mit
Drop-in single file library for printing color in terminal

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Python Terminal Color

Gradient String
🌈 Beautiful color gradients in terminal output
Stars: ✭ 476 (+706.78%)
Mutual labels:  terminal, color
Pixterm
Draw images in your ANSI terminal with true color
Stars: ✭ 782 (+1225.42%)
Mutual labels:  terminal, color
Vivid
A themeable LS_COLORS generator with a rich filetype datebase
Stars: ✭ 535 (+806.78%)
Mutual labels:  terminal, color
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: ✭ 53 (-10.17%)
Mutual labels:  terminal, color
Rang
A Minimal, Header only Modern c++ library for terminal goodies 💄✨
Stars: ✭ 1,080 (+1730.51%)
Mutual labels:  terminal, color
Nord Emacs
An arctic, north-bluish clean and elegant Emacs theme.
Stars: ✭ 379 (+542.37%)
Mutual labels:  terminal, color
Imgcat
It's like cat, but for images.
Stars: ✭ 577 (+877.97%)
Mutual labels:  terminal, color
Nord Gnome Terminal
An arctic, north-bluish clean and elegant GNOME Terminal color theme.
Stars: ✭ 258 (+337.29%)
Mutual labels:  terminal, color
Nord Guake
An arctic, north-bluish clean and elegant Guake color theme.
Stars: ✭ 20 (-66.1%)
Mutual labels:  terminal, color
Closestx11color
Find the closest xterm-256 colors (between 0 and 255) to an arbitrary HTML hexa color (e.g. #ABCDEF)
Stars: ✭ 13 (-77.97%)
Mutual labels:  terminal, color
Colorls
A Ruby gem that beautifies the terminal's ls command, with color and font-awesome icons. 🎉
Stars: ✭ 3,896 (+6503.39%)
Mutual labels:  terminal, color
Crossterm
Cross platform terminal library rust
Stars: ✭ 1,023 (+1633.9%)
Mutual labels:  terminal, color
Hues
Colored terminal text made easy for Python and happiness.
Stars: ✭ 345 (+484.75%)
Mutual labels:  terminal, color
Mordant
Full-featured text styling for Kotlin command-line applications
Stars: ✭ 382 (+547.46%)
Mutual labels:  terminal, color
Chalk
🖍 Terminal string styling done right
Stars: ✭ 17,566 (+29672.88%)
Mutual labels:  terminal, color
Nord Tmux
An arctic, north-bluish clean and elegant tmux color theme.
Stars: ✭ 567 (+861.02%)
Mutual labels:  terminal, color
Nord Alacritty
An arctic, north-bluish clean and elegant Alacritty color scheme.
Stars: ✭ 238 (+303.39%)
Mutual labels:  terminal, color
Colorizeswift
Terminal string styling for Swift.
Stars: ✭ 253 (+328.81%)
Mutual labels:  terminal, color
Term
Unix terminal drain and formatter for slog-rs
Stars: ✭ 17 (-71.19%)
Mutual labels:  terminal, color
Termite Color Switcher
termite color switcher
Stars: ✭ 28 (-52.54%)
Mutual labels:  terminal, color

Python Terminal Color

.. image:: screenshot.png

Introduction

  1. This is a drop-in library for print colorized output in terminal.
  2. It has no pypi package, which means you can't install it through pip.
  3. It is recommended to be used as a submodule of your own project, so that no dependency will be involved.
  4. color.py is Python 3 only and recommended to choose; color_compat.py is Python 2/3 compatible, only use it if you still struggle in the Python 2 morass.

Usage

Copy the color.py file to your project, then:

.. code:: python

from yourproject import color

# 8 bit color
print(color.red('red') + color.green('green') + color.blue('blue'))
print(color.bold(color.yellow('bold yellow')) + color.underline(color.cyan('underline cyan')))
print(color.magenta_hl('magenta highlight'))

# xterm 256 color
print(color.bg256('A9D5DE', color.fg256('276F86', 'Info!')))
print(color.bg256('E0B4B4', color.fg256('912D2B', 'Warning!')))
print(color.hl256('10a3a3', 'Teal'))

Note:

  1. Every color function receives and returns string, so that the result could be used with any other strings, in any string formatting situation.

  2. If you pass a str type string, the color function will return a str. If you pass a bytes type string, the color function will return a bytes.

  3. Color functions could be composed together, like put red into bold, or put bg256 into fg256. xxx_hl and hl256 are mostly used independently.

API

function <color_function>(s)


Decorate string with specified color.

``color_function`` is one of below function names:

========  ============  ===========
 Colors    Background    Highlight
========  ============  ===========
black     black_bg      black_hl
red       red_bg        red_hl
green     green_bg      green_hl
yellow    yellow_bg     yellow_hl
blue      blue_bg       blue_hl
magenta   magenta_bg    magenta_hl
cyan      cyan_bg       cyan_hl
white     white_bg      white_hl
========  ============  ===========

A color function with ``_bg`` suffix means it will set color as background.
A color function with ``_hl`` suffix means it will set color as background,
and change the foreground as well to make the word standout.

Parameters:

:param str s: The input string
:return: The decorated string
:rtype: string
:raises ValueError: if the message_body exceeds 160 characters

function ``<style_function>(s)``

Decorate string with specified style.

style_function is one of below function names:

  • bold
  • italic
  • underline
  • strike
  • blink

Arguments and return are the same as color_function.

function <256_color_function>(hexrgb, s)


Decorate string with specified hex rgb color

``256_color_function`` is one of below function names:

- fg256: will set color as foreground.
- bg256: will set color as background.
- hl256: will highlight input with the color.

Parameters:

:param str hexrgb: The hex rgb color string, accept length 3 and 6. eg: ``555``, ``912D2B``
:param str s: The input string
:return: The decorated string
:rtype: string
:raises ValueError: If the input string's length not equal to 3 or 6.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].