python3-colorsysplus

2016-03-31 14:33 UTC
  • Xyne

Metadata

Description:

An extension of the standard colorsys module with support for CMYK, terminal colors, ANSI and more.

Latest Version:

2015.12

Architecture:

  • any

Dependencies:

  • python3

Arch Repositories:

  • [xyne-any]
  • [xyne-i686]
  • [xyne-x86_64]

AUR Page:

python3-colorsysplus

Arch Forum Thread:

151196

Tags:

About

Colorsysplus is a extension of the standard colorsys module. It provides RGB conversion functions for

  • hexadecimal color codes
  • CMYK
  • terminal and ANSI colors (ANSI to RGB is incomplete)
  • Xonotic color codes
  • visible wavelengths (only wavelength to RGB is supported)

The module is a receptacle for color conversion functions that I frequently found myself copying or rewriting. I will continue to add to it and improve it. If you have suggestions of what to include, please let me know.

Usage

The source code is reasonably documented and straight-forward. The default main routine provides a simple example of converting HSV values to the nearest ANSI escape codes.

Additional Modules

ColorizedText

The package also includes the ColorizedText module that provides a class of the same name for working with colorized text. Text is stored as a list of chunks with associated RGB values that can be easily manipulated in an output-agnostic way.

The class includes methods for converting to and from the following formats:

  • HTML
  • BBCode
  • ANSI1
  • Xonotic

It also includes some convenience functions for applying gradients of different types.

Utilities

ctconv

A command line pipe converter that can convert colorized text between different types. This can be useful for posting colorized command-line output online, for example. See the help message below.

Acknowledgement

The code for retrieving RGB values for ANSI escape codes in the running terminal was adapted from code posted by Lux Perpetua on the Arch Linux forum

Screenshots

The example output of the module when run as a script.

screenshot 

ctconv Help Message

$ ctconv --help

usage: ctconv [-h] {ansi,bbcode,html,xon} {ansi,bbcode,html,xon}

Convert colored text from on format to another. This read from STDIN and
writes to STDOUT.

positional arguments:
  {ansi,bbcode,html,xon}
                        Input type.
  {ansi,bbcode,html,xon}
                        Output type.

optional arguments:
  -h, --help            show this help message and exit

CHANGELOG

2015-12-23

  • Merged ANSI functions from XCGF module.
  • Reworked ANSI SGR parsing.
  • Simplified color projection code for standard 256 terminal colors.
  • Changed terminal and ANSI color functions.
  • Added rgb_to_ansi and ansi_to_rgb.
  • Miscellaneous other changes (sorry).
  • Added ctconv.

2012-10-22

  • Added ColorizedText module.

  1. Only some ANSI escapes are currently recognized when attempting to parse an ANSI string. This functionality is provided by colorsys and improving it is on my TODO list.

Contact
echo xyne.archlinux.ca | sed 's/\./@/'
Feeds
Blog News
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0