Usage
print()
, but more!
Import Termspark's print and take advantage of all its features, colors, highlights, styles, hyperlinks and more ...
from termspark import print
print(" Termspark ", "white", "blue", "italic")
print(" [@termspark](https://github.com/faissaloux/termspark) ", "black", "white", "italic, bold")
You can choose from ["left", "center", "right"]
to specify where to print by passing it as position parameter:
print(" Termspark ", position="center")
.
You can enable the Full Width using full_width parameter:
print(" Termspark ", highlight="blue", full_width=True)
.
You can fill the empty space by a character using print(separator=)
.
from termspark import print
print(" TERMSPARK ", "white", "green", position="center", separator="_")
input()
input with colors, highlights, styles, and hyperlinks.
With input(position=)
you can specify position where to put your input text ["left", "center", "right"]
.
With input(full_width=)
you can enable full width True | False
.
from termspark import input
name = input(" What's your name? ", "white", "blue", "italic", "center", True)
Input Type
You can specify the input type by passing it to the type=
parameter.
For a calculation example, to pass the input value into a calculation you don't need to convert it to int
anymore, you just need to set it from type
argument 🥳 .
from termspark import input
birthyear = input(" Your year birth? ", "white", "blue", type=int)
print(f"Your age is: {2023 - birthyear}")
Input Callback
the input()
supports callback too.
If you need to pass the input value into some function before returning the result, you need to pass it into the callback=
argument.
from termspark import input
def age_calc(birthyear, currentyear=2023):
return currentyear - birthyear
age = input(" Your year birth? ", "white", "blue", type=int, callback=age_calc)
print(f"Your age is: {age}")
You can use separator in input(separator=)
too.
from termspark import input
name = input(" What's your name?", "white", "blue", position="left", separator=".")
line()
To print empty line use line()
, you can leave it empty or fill it with a repeated character, you can specify its color too.
from termspark import line
line(".", "blue")
line(highlight="green")
line()
line("-")
More control
from termspark import TermSpark
TermSpark().print_right('RIGHT').spark()
TermSpark().spark_right('RIGHT').spark()
TermSpark().print_left('LEFT').spark()
TermSpark().spark_left('LEFT').spark()
TermSpark().print_center('CENTER').spark()
TermSpark().spark_center('CENTER').spark()
TermSpark().line('.').spark()
TermSpark().print_left('LEFT').print_right('RIGHT').set_separator('.').spark()
TermSpark().print_left('LEFT').print_center('CENTER').print_right('RIGHT').set_separator('.').spark()
TermSpark().spark_left('LEFT').spark_center('CENTER').spark_right('RIGHT').set_separator('.').spark()
[!NOTE] Separator can contain only one character.
You can also paint your content
text color
from termspark import TermSpark
TermSpark().print_right('RIGHT', 'blue').spark()
TermSpark().print_left('LEFT', 'light red').spark()
TermSpark().print_center('CENTER', 'light_green').spark()
background color
from termspark import TermSpark
TermSpark().print_right('RIGHT', None, 'light_magenta').spark()
TermSpark().print_left('LEFT', 'red', 'white').spark()
TermSpark().print_center('CENTER', 'white', 'light blue').spark()
You can use different styles on same position
from termspark import TermSpark
TermSpark().spark_left([' * ', 'gray', 'white'], [' Info ', 'white', 'blue']).spark()
TermSpark().spark_center([' * ', 'gray', 'white'], [' Warning ', 'white', 'yellow']).spark()
TermSpark().spark_right([' * ', 'gray', 'white'], [' Error ', 'white', 'red']).spark()
You know you can use them all together 😉
Lines are too long to write a termspark line! 😑
from termspark import TermSpark
TermSpark().spark_left([' * ', 'gray', 'white'], [' Info ', 'white', 'blue']).spark_center([' * ', 'gray', 'white'], [' Warning ', 'white', 'yellow']).spark_right([' * ', 'gray', 'white'], [' Error ', 'white', 'red']).spark()
You can separate them by calling each function in a line 🤤
from termspark import TermSpark
termspark = TermSpark()
termspark.spark_left([' * ', 'gray', 'white'], [' Info ', 'white', 'blue'])
termspark.spark_center([' * ', 'gray', 'white'], [' Warning ', 'white', 'yellow'])
termspark.spark_right([' * ', 'gray', 'white'], [' Error ', 'white', 'red'])
termspark.spark()
Still too long 🙄 Got you 🤩
from termspark import TermSpark
termspark = TermSpark()
termspark.spark_left([' * ', 'gray', 'white'])
termspark.spark_left(' Info ', 'white', 'blue')
termspark.spark_center([' * ', 'gray', 'white'])
termspark.spark_center([' Warning ', 'white', 'yellow'])
termspark.spark_right(' * ', 'gray', 'white')
termspark.spark_right([' Error ', 'white', 'red'])
termspark.spark()
Raw
You can print raw version which is colors-code-free so you can print clean text into files for example.
from termspark import TermSpark
raw = TermSpark().print_left('LEFT').print_right('RIGHT').set_separator('.').raw()
Force Width
You can customize width instead of the default full terminal width.
from termspark import TermSpark
TermSpark().set_width(40).print_left("LEFT", "red").print_right("RIGHT", "blue").spark()
Set content max width
You can specify max width of content depending on position using max_[position](max_characters)
.
from termspark import TermSpark
termspark = TermSpark()
termspark.spark_left(["LEFT", "red"])
termspark.spark_right(["RIGHT", "blue"])
termspark.max_left(2)
termspark.max_right(3)
termspark.spark()
[!WARNING]
max_[position]()
is only supported by sparkers.
Full width
You can enable full width by using full_width()
.
from termspark import TermSpark
termspark = TermSpark()
termspark.spark_center(['Thanks for using Termspark!', 'white', 'green'])
termspark.full_width()
termspark.spark()
[!WARNING]
full_width()
can only be used with one position.
Separator
You can add color and highlight to separator too using set_separator(content, color, highlight)
.
termspark = TermSpark()
termspark.spark_left([' Author ', 'green'])
termspark.spark_right([' Faissal Wahabali ', 'green'])
termspark.set_separator('.', 'green')
termspark.spark()
Line
You can add highlight a line by using line(highlight=highlight)
.
termspark = TermSpark()
termspark.line(highlight='green')
termspark.spark()
RGB
from termspark import print, line
# String RGB
print(" RGB! ", color="255,255,255", highlight="36,114,200")
line(highlight="36,114,200")
# Tuple RGB
print(" Tuple RGB! ", color=(255, 255, 255), highlight=(36, 114, 200))
line(highlight=(36,114,200))
HEX
from termspark import print, line
print(" HEX! ", color="#FFF", highlight="#2472C8")
line(highlight="#2472C8")
Style
You can style your text by passing it to print() style parameter
or to spark([]) fourth list element
.
Supported styles: - bold - dim - italic - overline - underline - curly underline - dotted underline - dashed underline - double underline - strike through - blink - reverse - hidden
[!NOTE] You can mix styles by separating them by commas.
termspark = TermSpark()
termspark.print_center(' Termspark ', 'green', style='underline, overline, italic')
termspark.full_width()
termspark.spark()
Hyperlinks
You can insert hyperlink using Markdown [TEXT](LINK)
.
termspark = TermSpark()
termspark.spark_left([" Author ", "green"])
termspark.spark_right([" [@faissaloux](https://github.com/faissaloux) ", "green"])
termspark.set_separator(".", "green")
termspark.spark()
Supported colors
Color | Name | HEX |
---|---|---|
black | #000000 | |
maroon | #800000 | |
green | #008000 | |
olive | #808000 | |
navy | #000080 | |
purple | #800080 | |
teal | #008080 | |
silver | #C0C0C0 | |
gray | #808080 | |
grey | #808080 | |
red | #FF0000 | |
lime | #00FF00 | |
yellow | #FFFF00 | |
blue | #0000FF | |
fuchsia | #FF00FF | |
aqua | #00FFFF | |
white | #FFFFFF | |
navy blue | #00005F | |
dark blue | #000087 | |
dark blue 2 | #0000AF | |
dark blue 1 | #0000D7 | |
dark green | #005F00 | |
blue stone | #005F5F | |
orient | #005F87 | |
endeavour | #005FAF | |
science blue | #005FD7 | |
blue ribbon | #005FFF | |
japanese laurel | #008700 | |
deep sea | #00875F | |
turquoise | #008787 | |
deep cerulean | #0087AF | |
lochmara | #0087D7 | |
azure radiance | #0087FF | |
islamic green | #00AF00 | |
spring green | #00AF5F | |
dark cyan | #00AF87 | |
light sea green | #00AFAF | |
cerulean | #00AFD7 | |
blue bolt | #00AFFF | |
electric green | #00D700 | |
malachite | #00D75F | |
caribbean green | #00D787 | |
cyan 1 | #00D7AF | |
dark turquoise | #00D7D7 | |
vivid sky blue | #00D7FF | |
electric green 1 | #00FF00 | |
guppie green | #00FF5F | |
spring green 1 | #00FF87 | |
medium spring green | #00FFAF | |
sea green | #00FFD7 | |
cyan | #00FFFF | |
rosewood | #5F0000 | |
pompadour | #5F005F | |
pigment indigo | #5F0087 | |
purple 3 | #5F00AF | |
electic violet | #5F00D7 | |
blue violet | #5F00FF | |
verdun green | #5F5F00 | |
scorpion | #5F5F5F | |
comet | #5F5F87 | |
scampi | #5F5FAF | |
indigo | #5F5FD7 | |
cornflower blue 1 | #5F5FFF | |
limeade | #5F8700 | |
glade green | #5F875F | |
juniper | #5F8787 | |
hippie blue | #5F87AF | |
havelock blue | #5F87D7 | |
cornflower blue | #5F87FF | |
limea | #5FAF00 | |
fern | #5FAF5F | |
silver tree | #5FAF87 | |
tradewind | #5FAFAF | |
shakespeare | #5FAFD7 | |
malibu | #5FAFFF | |
bright green | #5FD700 | |
pale green | #5FD75F | |
pastel green | #5FD787 | |
downy | #5FD7AF | |
viking | #5FD7D7 | |
steel blue | #5FD7FF | |
chartreuse | #5FFF00 | |
screaming green | #5FFF5F | |
sea green 1 | #5FFF87 | |
aquamarine 1 | #5FFFAF | |
aquamarine 2 | #5FFFD7 | |
aquamarine | #5FFFFF | |
dark red | #870000 | |
fresh eggplant | #87005F | |
dark magenta | #870087 | |
purple 2 | #8700AF | |
electric violet | #8700D7 | |
purple 1 | #8700FF | |
brown | #875F00 | |
copper rose | #875F5F | |
strike master | #875F87 | |
deluge | #875FAF | |
medium purple | #875FD7 | |
heliotrope | #875FFF | |
olive 1 | #878700 | |
clay creek | #87875F | |
gray 1 | #878787 | |
grey 1 | #878787 | |
wild blue yonder | #8787AF | |
chetwode blue | #8787D7 | |
light slate blue | #8787FF | |
limeade 1 | #87AF00 | |
chelsea cucumber | #87AF5F | |
bay leaf | #87AF87 | |
gulf stream | #87AFAF | |
polo blue | #87AFD7 | |
malibu 1 | #87AFFF | |
pistachio | #87D700 | |
dark olive green | #87D75F | |
feijoa | #87D787 | |
vista blue | #87D7AF | |
bermuda | #87D7D7 | |
anakiwa | #87D7FF | |
chartreuse 1 | #87FF00 | |
light green | #87FF5F | |
mint green | #87FF87 | |
pale green 1 | #87FFAF | |
aqua marine | #87FFD7 | |
anakiwa 1 | #87FFFF | |
bright red | #AF0000 | |
flirt | #AF005F | |
medium violet red | #AF0087 | |
magenta 1 | #AF00AF | |
dark violet | #AF00D7 | |
purple 4 | #AF00FF | |
rose of sharon | #AF5F00 | |
indian red | #AF5F5F | |
tapestry | #AF5F87 | |
fuchsia pink | #AF5FAF | |
medium purple 1 | #AF5FD7 | |
heliotrope 1 | #AF5FFF | |
pirate gold | #AF8700 | |
muesli | #AF875F | |
pharlap | #AF8787 | |
bouquet | #AF87AF | |
lavender | #AF87D7 | |
heliotrope 2 | #AF87FF | |
gold 1 | #AFAF00 | |
olive green | #AFAF5F | |
hillary | #AFAF87 | |
silver chalice | #AFAFAF | |
wistful | #AFAFD7 | |
melrose | #AFAFFF | |
rio grande | #AFD700 | |
conifer | #AFD75F | |
feijoa 1 | #AFD787 | |
pixie green | #AFD7AF | |
jungle mist | #AFD7D7 | |
anakiwa 2 | #AFD7FF | |
lime 1 | #AFFF00 | |
green yellow | #AFFF5F | |
mint green 1 | #AFFF87 | |
dark sea green | #AFFFAF | |
aero blue | #AFFFD7 | |
french pass | #AFFFFF | |
guardsman red | #D70000 | |
razzmatazz | #D7005F | |
hollywood cerise | #D70087 | |
hollywood cerise 1 | #D700AF | |
purple pizzazz | #D700D7 | |
electric violet 1 | #D700FF | |
tenn | #D75F00 | |
roman | #D75F5F | |
cranberry | #D75F87 | |
hopbush | #D75FAF | |
orchid | #D75FD7 | |
medium orchid | #D75FFF | |
mango tango | #D78700 | |
copperfield | #D7875F | |
pink | #D78787 | |
cancan | #D787AF | |
light orchid | #D787D7 | |
heliotrope 3 | #D787FF | |
corn | #D7AF00 | |
tacha | #D7AF5F | |
tan | #D7AF87 | |
clam shell | #D7AFAF | |
thistle | #D7AFD7 | |
mauve | #D7AFFF | |
corn 1 | #D7D700 | |
khaki | #D7D75F | |
deco | #D7D787 | |
green mist | #D7D7AF | |
alto | #D7D7D7 | |
fog | #D7D7FF | |
chartreuse yellow | #D7FF00 | |
canary | #D7FF5F | |
honeysuckle | #D7FF87 | |
reef | #D7FFAF | |
snowy mint | #D7FFD7 | |
oyster bay | #D7FFFF | |
rose | #FF005F | |
deep pink | #FF0087 | |
hollywood cerise 2 | #FF00AF | |
purple pizzazz 1 | #FF00D7 | |
magenta | #FF00FF | |
blaze orange | #FF5F00 | |
bitter sweet | #FF5F5F | |
wild watermelon | #FF5F87 | |
hotpink | #FF5FAF | |
hotpink 1 | #FF5FD7 | |
pink flamingo | #FF5FFF | |
flush orange | #FF8700 | |
salmon | #FF875F | |
vivid tangerine | #FF8787 | |
pink salmon | #FF87AF | |
lavender rose | #FF87D7 | |
blush pink | #FF87FF | |
yellow sea | #FFAF00 | |
texas rose | #FFAF5F | |
hit pink | #FFAF87 | |
sundown | #FFAFAF | |
cotton candy | #FFAFD7 | |
lavender rose 1 | #FFAFFF | |
gold | #FFD700 | |
dandelion | #FFD75F | |
grandis | #FFD787 | |
caramel | #FFD7AF | |
cosmos | #FFD7D7 | |
pink lace | #FFD7FF | |
laser lemon | #FFFF5F | |
dolly | #FFFF87 | |
portafino | #FFFFAF | |
cumulus | #FFFFD7 | |
cod gray | #080808 | |
cod gray 1 | #121212 | |
cod gray 2 | #1C1C1C | |
mine shaft | #262626 | |
mine shaft 1 | #303030 | |
mine shaft 2 | #3A3A3A | |
tundora | #444444 | |
tundora 1 | #4E4E4E | |
scorpion 1 | #585858 | |
dove gray | #626262 | |
dove gray 1 | #6C6C6C | |
boulder | #767676 | |
gray 2 | #8A8A8A | |
grey 2 | #8A8A8A | |
dusty gray | #949494 | |
silver chalice 1 | #9E9E9E | |
silver chalice 2 | #A8A8A8 | |
silver chalice 3 | #B2B2B2 | |
silver 1 | #BCBCBC | |
silver 2 | #C6C6C6 | |
alto 1 | #D0D0D0 | |
alto 2 | #DADADA | |
mercury | #E4E4E4 | |
gallery | #EEEEEE |