Skip to main content

colour_filter module and colour-filter command - colour parts of lines

colour-filter command

The colour-filter command reads lines from its input, colours parts of the line and prints the result on its output.

For example colour the output of a build script. Colour Info: in green and all of the line that starts Error: in red.

   $ ./build.sh 2>&1 | colour-filter '^Info:' green 'Error:.*' red

colour_filter module

ColourFilter class

  • __init__()

    Create instance of ColourFilter.

  • enableDebug( enable=True )

    Turn on the debug output to help understand why patterns are not matching as expected.

  • define( pattern, colour )

    When the regular express pattern is found in a line of input colour it as colour on the output.

    colour is either the string name of a list colour name seperated by ':' or ';'. E.g. 'red' or 'red;bg-white'

    The builtin foreground colour names are:

      bold, black, brown, green, yellow, blue,
      magenta, cyan, gray, red, lightred, lightgreen,
      lightyellow, lightblue, lightmagenta, lightcyan
      ans white.
    

    The builtin background colour names are:

      bg-black, bg-brown, bg-green, bg-yellow,
      bg-blue, bg-magenta, bg-cyan, bg-gray
      and bg-white.
    
  • filterLines( input_file, output_file, line_buffered )

    Read lines from input_file until end-of-file. Replace all matching patterns with their defined colour. Write each converted line to output_file and if line_buffered is True call flush() on the output_file.

Example that colours lines of build.log

    from colour_filter import ColourFilter

    f = ColourFilter()
    f.define( 'Info:', 'green' )
    f.define( 'Error:', 'red;bg-white' )

    with open( 'build.log' ) as input_file:
        f.filterLines( input_file, sys.stdout, line_buffered=False )

Download files

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

Source Distribution

colour-filter-1.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

colour_filter-1.1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file colour-filter-1.1.2.tar.gz.

File metadata

  • Download URL: colour-filter-1.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for colour-filter-1.1.2.tar.gz
Algorithm Hash digest
SHA256 95883247b4ff394feace505f0d8734ac7d1393285e154282a7ba81d67300c143
MD5 3b243046125587876bb41f5319448724
BLAKE2b-256 12ecea67c99baa04572993ca53b3ae24f8f3d8fa16cc0e060096c929c8e19bd3

See more details on using hashes here.

File details

Details for the file colour_filter-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: colour_filter-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for colour_filter-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2744883532b4499c8d46703a4fefcf0d4ea7135ddab5148004dacf4fce7281ec
MD5 700a53d8e6f2e804022499d2e4a4c1de
BLAKE2b-256 3ef87c488f69d9184ff1bc1ffd9b42398fe0f592d524a2b7c7e2b4b91916b84d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 files

1.1.1

1 file

1.1.0

1 file

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page