Git Product home page Git Product logo

colorstring's Introduction

            ██████╗ ██████╗ ██╗      ██████╗ ██████╗ ███████╗████████╗██████╗ ██╗███╗   ██╗ ██████╗ 
           ██╔════╝██╔═══██╗██║     ██╔═══██╗██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██║████╗  ██║██╔════╝ 
           ██║     ██║   ██║██║     ██║   ██║██████╔╝███████╗   ██║   ██████╔╝██║██╔██╗ ██║██║  ███╗
           ██║     ██║   ██║██║     ██║   ██║██╔══██╗╚════██║   ██║   ██╔══██╗██║██║╚██╗██║██║   ██║
           ╚██████╗╚██████╔╝███████╗╚██████╔╝██║  ██║███████║   ██║   ██║  ██║██║██║ ╚████║╚██████╔╝
            ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚══════╝   ╚═╝   ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝ ╚═════╝         

Installing

With the project's current state, there is no need to set up the project using any special procedures, using pip etc. Simply cloning the repository and including the colorstring.py module will get you started with printing colored text.

Prerequisites

  • Python 3.6 or later
  • Terminal with ANSI colors support

Get the source

Clone the repository over HTTPS using the GitHub link:

git clone <repository-url>

Note that the project does not have any dependencies or submodules.

Usage

To print colored text to a terminal, you can use the cs function.

from colorstring import cs, UnsafeRepeaterException

try:
    print(cs('^1*3Hello ^5world'))
except UnsafeRepeaterException as error:
    pass  # Use error.count for debugging purposes

From the example above, note that it is possible for the cs function to throw an UnsafeRepeaterException in the event that an out-of-bounds repeater was provided.

TODO

  • Add support for background colors
  • Add support for non-color IDs (e.g. reset foreground with ^.)
  • Provide a way to dynamically change the id-to-color mapper that can throw exceptions
  • Write a specification draft for a future syntax
  • Provide more debug information when an UnsafeRepeaterException is thrown

Author

colorstring's People

Contributors

maktm avatar mkirossamsung avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.