Skip to main content

couleur - ANSI terminal tool for python, colored shell and other handy fancy features

Couleur is a handy tool to play around with ANSI features in a unix terminal

https://img.shields.io/pypi/dm/couleur https://img.shields.io/codecov/c/github/gabrielfalcao/couleur https://img.shields.io/github/workflow/status/gabrielfalcao/couleur/python-3.6?label=python%203.6 https://img.shields.io/github/workflow/status/gabrielfalcao/couleur/python-3.7?label=python%203.7 https://img.shields.io/readthedocs/couleur https://img.shields.io/github/license/gabrielfalcao/couleur?label=Github%20License https://img.shields.io/pypi/v/couleur https://img.shields.io/pypi/l/couleur?label=PyPi%20License https://img.shields.io/pypi/format/couleur https://img.shields.io/pypi/status/couleur https://img.shields.io/pypi/pyversions/couleur https://img.shields.io/pypi/implementation/couleur https://img.shields.io/snyk/vulnerabilities/github/gabrielfalcao/couleur https://img.shields.io/github/v/tag/gabrielfalcao/couleur

installing

user@machine:~$ sudo pip install git+git://github.com/gabrielfalcao/couleur.git

features

  • Single python file

  • 100% tested

  • comes with syntax sugar

nutshell

file-like objects filter

stdout filter

stdout filter

further

import sys, couleur

couleur.proxy(sys.stdout).enable()
print "#{bold}#{blue}#{on:black}This is#{normal} a test"
couleur.proxy(sys.stdout).ignore()

print "#{green}#{on:black}This is#{normal} a test"
couleur.proxy(sys.stdout).disable()

dynamic methods

couleur has a syntax sugar that is semantically nice:

print
import couleur
sh = couleur.Shell(indent=4)

sh.bold_black_on_white('Nice highlight\n')
# prints '\033[47m\033[1m\033[30mNice highlight\033[0m'

sh.indent()
# will increase a internal indentation factor in couleur.Shell instance

sh.red('Just red\n')
# prints indented as well '    \033[32mJust Green\033[0m\n'

sh.dedent()

# will decrease that indentation factor (above)

# syntax sugar
sh.green_and_normal_and_blue('this will be printed in green| and |this in blue\n')
# see: '\033[32mthis will be printed in green\033[0m and \033[34mthis in blue\033[0m'

couleur can overwrite output, so that you can make things like printing progress bars, show percentage and so on:

import time
import couleur

shell = couleur.Shell(linebreak=True, bold=True)

for num in range(101):
    if num == 0:
        print

    shell.yellow_and_red("Downloading file: |%d%%" % num, replace=True)
    time.sleep(0.02)

shell.white_and_green("Downloading file: |DONE!", replace=True)

Writing to other streams

Simply pass the output as first argument of the Shell

import couleur

with open('output.log', 'w') as output:
    shell = couleur.Shell(output, linebreak=True, bold=True)
    shell.white_and_green("done with | Some task")

furthermore

With couleur you can mix modifiers and colors.

Available modifiers:

  • reset - resets from the current point to the end

  • bold - make text bold

  • blink - it may blink the text or make it slighly lighten, depending on the terminal

  • italic - make text italic

  • underline - add underline on text

  • inverse - invert colors

  • strikethrough - draws a line through the text

  • up - does the same than passing replace=True to the output function: carriage return and one line up

Available colors:

  • normal

  • black

  • red

  • green

  • yellow

  • blue

  • magenta

  • cyan

  • white

Example chaining modifiers:

import couleur

shell = couleur.Shell(linebreak=True)
shell.bold_italic_underline_green_on_black_and_italic_black_on_white("WOO| HOO")

free software

To contribute back with this project, all you need to do is write code, and test code that proofs its functionallity

cloning and running tests

You will need to install nose.

And run:

user@machine:~/Projects$ git clone git://github.com/gabrielfalcao/couleur.git
user@machine:~/Projects$ cd couleur
user@machine:~/Projects/couleur$ make tests

nomenclature

“couleur” stands for “color” in French, I like french, hence the name

Licensing

Copyright (c) 2010-2020 Gabriel Falcão
Licensed under LGPLv3
https://opensource.org/licenses/lgpl-3.0.html

Bitdeli Badge

Metadata

Release files for couleur 0.7.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for couleur 0.7.4
File Size Uploaded
couleur-0.7.4.tar.gz 6.9 kB Details

Release files / couleur-0.7.4.tar.gz

Download URL couleur-0.7.4.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1e96a5972ecd5f88716fe4e4df63d31e85f57d3ff6c02a07e93a226a663961ba
BLAKE2b-256 checksum
How to use checksums
8ac36aa454c63e55b28172c379aac286bb09a9dcc23c485518b37838c2f85781
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.7.4 This release

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

0.2

1 release file

0.1.2

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page