A tiny Python wrapper that enhances the print() syntax by enabling text coloring on the screen. (Use with Colorama)
Hello there! This project is made in a little free time. Since it can be useful, but I think the syntax still complex and I want to rewrite this project
For who are using this wrapper will not be affected anything, but I will not update anymore! So if you are by chance see this project, you can install but not recommended
This project is read-only FOREVER
I wish I could have more free time, but now I can't. Sorry!
NOTE 1: Bạn muốn đọc file README bằng tiếng Việt à? Nhấn vào đây!
NOTE 2: All the comments in the source code still not translated completely, it may have some errors.
You don't understand something? Just ask me in Issues, and I will try to read and answer all 😄
Thanks
To install this package via PyPi, type like this command below to the Terminal or Command Prompt:
pip install PrintWithColor
For those of you who are wondering why I don't put the $ character in front of the command as others do in other projects, here's why.
Because forgetting to DELETE the extra $ character while pasting the command will result in the command FAILING!. This command may also be used on Windows, however on Linux, you should replace pip with pip3 (if you use pip, maybe Linux will call Python 2 instead Python 3!)
This is the basic usage of PrintWithColor
WARNING! DO NOT IMPORT PRINTWITHCOLOR.PRINTWITHCOLORCORE! (ALTHOUGH YOUR IDE SHOW IT!)
from PrintWithColor import print as print
print('Hello, I am a green line!', f = 'green', b= 'black')
print('Or a line with a cyan background', f = 'black', b = 'cyan')
Argument | Description | DefaultValue |
---|---|---|
textfrominput | The content you want to display on the screen, allows you to enter many arguments | Any |
sep | A separate sign between the items in textfrominput argument (if there is only one argument in textfrominput, it will not appear anywhere) | ' ' |
end | Ending character, when there is only one argument or when textfrominput has reached its final argument, the ending character appears. | '\n' |
file | Where should the text be output? The default in Python is sys.stderr or your screen. If the file argument is a writable file, Python will automatically write to the file provided in the file argument instead of writing to the screen. If that file cannot be written, an exception will be raised [1] |
None |
flush | Should the buffer be cleaned up once the results are printed? | False |
Argument | Description | Default |
---|---|---|
textfrominput | The content you want to display on the screen, allows you to enter many arguments | Any |
sep | A separate sign between the arguments (if there is only one argument in textfrominput, it will not appear anywhere) | ' ' |
end | Ending character, when there is only one argument or when textfrominput has reached its final argument, the ending character appears. | '\n' |
file | Where should the text appear? This wrapper will use the Colorama library's proxy object by default. If the file argument is a writeable file, PrintWithColor will write the output to that file, just like the original print() syntax. PrintWithColor will skip the file provided in it and display the text on the screen if it is not writeable (or read-only). You should also be aware that in order to use Colorama's proxy object, this argument will skip all objects other than a writeable file! (Because this wrapper is cross-platform, I should use Colorma's proxy object to avoid any bugs/issues that may happen!) |
None |
flush | Should the buffer be cleaned up once the results are printed? | False |
f | Foreground color [2] [3] | WHITE |
b | Background color [2] [3] | BLACK |
s | Style of the foreground colour [2] [4] | NORMAL |
NOTE FOR PRINT() SYNTAX BETWEEN PYTHON AND PRINTWITHCOLOR
- If the file argument is a read-only file. It will throw an exception in Python, but PrintWithColor will automatically ignore that argument and print the output directly to the screen.
- You can write the colour in uppercase or lowercase as well
- Acceptable color ranges are ['WHITE', 'RED', 'GREEN', 'YELLOW', 'BLUE', 'MAGENTA', 'CYAN', 'BLACK']
- Acceptable color styles are ['NORMAL', 'DIM', 'BRIGHT']
WARNING! Windows will NOT correctly display dark (dim) colors. So, in most cases, you won't notice a change if you put a when you leave text with dark color between text with normal one.
(Don't blame me or the author of Colorama, this is because Windows doesn't support ANSI 'dim text' 😢)
For more infomation: Please look down to the last line of colorama's description: https://github.com/tartley/colorama#description
WARNING!: If any of these settings are invalid, they will be reset to their DEFAULT values!
How to change configuration? using print.change_settings() syntax
Effect: Not reset color after every print() syntax is performed
Default value: False (boolean)
Acceptable value: True, False (boolean)
print.change_settings(1, True)
# or
print.change_settings('DoNotResetColor', True)
# will return the same results!
# When using
print('Line 1', f='black', b='green')
print('Line 2 must be formatted in the same color as line 1!')
Effect: Change the default foreground color (When you're done with the print() syntax and the variable DoNotResetColor = False, the following print() syntax will use the color you specified!)
Default value: WHITE (string)
Acceptable value: WHITE, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, BLACK
print.change_settings(2, 'GREEN')
# or
print.change_settings('DefaultForegroundColor', 'GREEN')
# will return the same results!
# When using
print('Even without the f argument, this line must be green!')
Effect: Change the default background color (When you're done with the print() syntax and the variable DoNotResetColor = False, the following print() syntax will use the color you specified!)
Default value: BLACK (string)
Acceptable value: DIM, NORMAL, BRIGHT
print.change_settings(3, 'GREEN')
# or
print.change_settings('DefaultBackgroundColor', 'GREEN')
# will return the same results!
# When using
print('This line will have nice green background, although I don\'t use b argument')
Effect: Change the default style of foreground color (When you're done with the print() syntax and the variable DoNotResetColor = False, the following print() syntax will use the style you specified!)
Default value: NORMAL (string)
print.change_settings(4, 'NORMAL')
# or
print.change_settings('DefaultStyle', 'NORMAL')
# Example
print.change_settings('DefaultStyle', 'NORMAL')
print.change_settings('DoNotResetColor', 'True')
print('Line 1 will have a normal-green color', f='green')
print('But this line will have a bright color'), s='bright')
Effect: Clear all PrintWithColor's settings!
NO ARGUMENT & NO WARNING & NO OUTPUT!
print.clear_settings()
Questions, problem: don't hestitate ask me on Issues
Contact me? Right here