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
File details
Details for the file ChromaticColorBurst-1.0.3.tar.gz
.
File metadata
- Download URL: ChromaticColorBurst-1.0.3.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1324c9f605a08d8ff46d8a13b221daf563c60b8e29ab5eb0423e14c3dd7be56 |
|
MD5 | 93c8296417ee8a93606f4442e0450f07 |
|
BLAKE2b-256 | 49637550ace3e2a01210c5e456ffc5e4f30efb6c0973dcbe43d6d4c5cefdbb89 |
File details
Details for the file ChromaticColorBurst-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: ChromaticColorBurst-1.0.3-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 253a5e46e6df870c7989e50d7cc9fe719b323eb2307744191ce8425a1ade3a4f |
|
MD5 | 21ddf5de36cdbf7e14375a73de712521 |
|
BLAKE2b-256 | 0f2aed2b76bc2b9bcd516cd49f896ea647873f10f16f683469190104c6f32359 |