You can now print styled TEXT to console/terminal without much of a hassel
Project description
ColorBurst - Stylish Output
ColorBurst is a python module that provide method to print stylish text onto console without any setups. For example, you can print colored text or text with colored background or different styled text like bold, underlined, etc or with all these property with specified color and style for each
Table of Contents
Installation
You can install this package using pip
or directly from the github
Installing with pip
pip install ChromaticColorBurst
Installing Directly from GitHub
pip install git+https://github.com/sachin-acharya-projects/ColorBurst.git@master
Or you can even download wheel file from dist folder and install it using
pip install wheel-file-name.whl
Methods
This package provide three classes which are Colors, Decorations and ColorBurst
Colors
This is a namespace class that contains valid values for color and background parameter for ColorBurst.colorize method
Colors.RED # This equivalent to string 'RED'
Decorations
This class contains valid values for decoration parameter for ColorBurst.colorize method
Decorations.BOLD # This equivalent to string 'BOLD'
TextProperty
This is a dataclass that can contain values for different property for text like color, background and decoration Usages
# To access value
TextProperty.color # returns default color value i.e. None if none assigned before
# To change value
TextPropery(color = 'RED').color # returns 'RED'
There are three data kind it holds
color of type Colors
background of type Colors
and decoration of type Decorations
ColorBurst
This is the main class that can be used to print styled text onto console(Terminals). This class provides following three methods
-
init(color: Colors = None, background: Colors = None, decoration: Decorations = None, autoreset = False)
This method is used to set or unset different parameter which are color, background and/or decoration as well as autoreset. This method can be used to preserve value for above parameter so they can be used later without having to pass paramter to colorize method explicitly ExampleColorBurst().init( color = Colors.RED, background = Colors.CYAN, decoration = Decorations.DOUBLY_UNDERLINE, autoreset = True )
After calling init method like so, you can now simply call
ColorBurst().colorize("Hello", "World")
and it will print RED text with CYAN background with double underline. You can override these property for only one line by passing parameter explicitly or you can change these property for any next uses by re-usinginit
method.""" The code below will print YELLOW text with CYAN as background and DOUBLE UNDERLINE as Text Style CYAN as background and DOUBLE UNDERLINE as Text Style was stored in previous init method calls """ ColorBurst.colorize("Hello", "World", color=Colors.YELLOW)
Last parameter for this method, autoreset, if set to True, the color sequence will be terminated after line-break otherwise it will remains as is unless overriden or closing of terminal
c = ColorBurst() """ The line below will print text with RED color but the foreground color will be kept RED even after the program is terminated. This can be override by using another color (New color will persist instead of RED) or closing the terminal. """ c.colorize("Hello", "World", color = 'RED') # color = Colors.RED c.init(autoreset = True) """ The line below will print text will CYAN color and terminated the coloring sequence. That means this CYAN color will only be available for current line/row (outputted row). """ c.colorize("Hello", "There", color = 'CYAN') # Colors.CYAN
Parameters
- color
This parameter, typeColors
represent foreground color. (Default:None
) - background
This parameter, typeColors
represent background color. (Default:None
) - decoration
This parameter, typeDecorations
represent text style/decoration. (Default:None
) - autoreset
This parameter, typeBoolean
represent condition to autoreset after line break or not. (Default:False
)
- color
-
colorize(*args, color: Colors = None, background: Colors = None, decoration: Decorations = None, separator = None, end = None)
This method can be used to print stylish text onto screen.ColorBurst().colorize( "Hello", "World", color = Colors.RED, background = Colors.CYAN, decoration = Decorations.BOLD, separator = '-', end = '\n' )
Above code will print bold 'Hello-World\n' onto screen with color RED and background CYAN. Parameters
- args (Type:
Tuple
)
These are the positional arguments which will be printed out onto screen. (Default:''
) - color (Type:
Colors
)
Same as color parameter forinit
method. (Default: Terminals' default) - background (Type:
Colors
)
Same as background forinit
method. (Default: Terminals' default) - decoration (Type:
Decorations
)
Same as decoration parameter forinit
method. (Default:Decorations.NORMAL
) - separator (Type:
String
)
This parameter represent separating character for each data in args parameter. (similar tosep
parameter ofprint
statement). (Default:' '
) - end (Type:
String
)
This parameter represent what to append at the end of the line. (Default:\n
)
- args (Type:
-
RESET
This method is used to reset any text formatting done. This is used whenautoreset
is set toFalse
and need to terminate coloring sequence. Example The code below will print text will RED color and this foreground color will be persistent as autoreset is set to Falsec = ColorBurst() c.colorize('Text', color = 'RED')
Now if we use RESET method right after printing text, color sequence will be terminated and foreground color will be reverted to default
c = ColorBurst() c.colorize('Text', color = 'RED') c.RESET # Omit parenthesis
This method is used to revert any formatting done to defaults.
-
coloredInput
This method is equivalent to input method but with colorfull prompt and/or input text Example Here is an example on how you can use this methodc = ColorBurst() c.coloredInput( prompt = "What is your name? ", promptProperty = c.getProperty(color = Colors.RED), # color = 'RED' textProperty = TextPropery(color='YELLOW'), # color = Colors.YELLOW text_style = True )
The code above will prompt user with "What is your name? " in RED color and user can now write his name is YELLOW color. The way value are passed to parameter
promptProperty
andtextProperty
, you can use either way for any of them. If user-input is to be styled (textProperty to text effect), text_style must be set to True. Parameters- prompt (str)
Question or Text to display as Input Prompt - promptProperty (Dict['color', 'background', 'decoration'] or TextProperty], optional)
Property (color, background and decoration) of prompt text. Defaults to TextProperty. - textProperty (Dict['color', 'background', 'decoration'] or TextProperty, optional)
Property (color, background, and decoration) of user-input texts. Defaults to TextProperty. - text_style (bool, optional)
Set True you you want user-input to be colorfull too. Defaults to False. - type_ (Callable, optional)
What type you want your user-input to be such as int, float or str (default). Defaults to None.
- prompt (str)
-
getProperty
This method is a wrapper of the value for parameterpromptProperty
andtextProperty
ofcoloredInput
method. You can use this method in a alternative to TextProperty dataclass.
Parameters- color (Type:
Colors
)
Same as color parameter forinit
method. (Default: Terminals' default) - background (Type:
Colors
)
Same as background forinit
method. (Default: Terminals' default) - decoration (Type:
Decorations
)
Same as decoration parameter forinit
method. (Default:Decorations.NORMAL
)
Returns TextProperty
- color (Type:
Code
# Importing required modules
from ColorBurst import ColorBurst, Colors, Decorations
# Initializing ColorBurst
color_print = ColorBurst()
# Printing Hello World in RED with GREEN background and ITALIC as style onto Terminal
color_print.colorize("Hello", "World", color=Colors.RED, background=Colors.GREEN, decoration=Decorations.ITALIC)
# RESETTING above text style
color_print.RESET
# Enabling AUTORESET
color_print.init(autoreset=True)
# RAPID BLINKING YELLOW colored Hello World on to Console
color_print.colorize("Hello", "World", color=Colors.YELLOW, decoration=Decorations.RAPID_BLINK)
# To take the colorfull input from users
color_print.coloredInput("What is your name? ", promptProperty = color_print.getProperty(color = Colors.RED), textProperty = TextProperty(color = 'YELLOW'), text_style = True)
# Note: in above code, you can either use getProperty method from ColorBurst class or TextPropery dataclass for passing parameter to textPrompt and promptProperty and also text_style should be true inorder to textProperty take effects
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ChromaticColorBurst-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9d6a977439c6bcfb82eb6f164a0c280fe2c9dab684d7d2076e1d8bf952c0c9c |
|
MD5 | 060ec07f0c60489f9541ae1e06373e4b |
|
BLAKE2b-256 | 4f69104f434ab0489c6b1c22648aeba61127222142f0114f05b9a07eb3c52579 |
Hashes for ChromaticColorBurst-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cb3207ea9066dd0c03cecfbe25b8165ccb4cfbbb2565a4d536340dce096f3c6 |
|
MD5 | 824e0906d2050e41511309c25e82fa26 |
|
BLAKE2b-256 | 3c27a66aaf4ba20a06353413c92a16695991da816d95c361cd3db8f9bde3dcce |