Skip to main content

Takes control of terminal

Project description

Logo

Test Python package codecov pre-commit.ci status PyPI PyPI - Python Version PyPI - Status

Installation

    pip install termspark

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()

This should show only "LE" on the left, and "RIG" on the right.

[!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
#000000 black #000000
#800000 maroon #800000
#008000 green #008000
#808000 olive #808000
#000080 navy #000080
#800080 purple #800080
#008080 teal #008080
#c0c0c0 silver #C0C0C0
#808080 gray #808080
#808080 grey #808080
#ff0000 red #FF0000
#00ff00 lime #00FF00
#ffff00 yellow #FFFF00
#0000ff blue #0000FF
#ff00ff fuchsia #FF00FF
#00ffff aqua #00FFFF
#ffffff white #FFFFFF
#00005f navy blue #00005F
#000087 dark blue #000087
#0000af dark blue 2 #0000AF
#0000d7 dark blue 1 #0000D7
#005f00 dark green #005F00
#005f5f blue stone #005F5F
#005f87 orient #005F87
#005faf endeavour #005FAF
#005fd7 science blue #005FD7
#005fff blue ribbon #005FFF
#008700 japanese laurel #008700
#00875f deep sea #00875F
#008787 turquoise #008787
#0087af deep cerulean #0087AF
#0087d7 lochmara #0087D7
#0087ff azure radiance #0087FF
#00af00 islamic green #00AF00
#00af5f spring green #00AF5F
#00af87 dark cyan #00AF87
#00afaf light sea green #00AFAF
#00afd7 cerulean #00AFD7
#00afff blue bolt #00AFFF
#00d700 electric green #00D700
#00d75f malachite #00D75F
#00d787 caribbean green #00D787
#00d7af cyan 1 #00D7AF
#00d7d7 dark turquoise #00D7D7
#00d7ff vivid sky blue #00D7FF
#00ff00 electric green 1 #00FF00
#00ff5f guppie green #00FF5F
#00ff87 spring green 1 #00FF87
#00ffaf medium spring green #00FFAF
#00ffd7 sea green #00FFD7
#00ffff cyan #00FFFF
#5f0000 rosewood #5F0000
#5f005f pompadour #5F005F
#5f0087 pigment indigo #5F0087
#5f00af purple 3 #5F00AF
#5f00d7 electic violet #5F00D7
#5f00ff blue violet #5F00FF
#5f5f00 verdun green #5F5F00
#5f5f5f scorpion #5F5F5F
#5f5f87 comet #5F5F87
#5f5faf scampi #5F5FAF
#5f5fd7 indigo #5F5FD7
#5f5fff cornflower blue 1 #5F5FFF
#5f8700 limeade #5F8700
#5f875f glade green #5F875F
#5f8787 juniper #5F8787
#5f87af hippie blue #5F87AF
#5f87d7 havelock blue #5F87D7
#5f87ff cornflower blue #5F87FF
#5faf00 limea #5FAF00
#5faf5f fern #5FAF5F
#5faf87 silver tree #5FAF87
#5fafaf tradewind #5FAFAF
#5fafd7 shakespeare #5FAFD7
#5fafff malibu #5FAFFF
#5fd700 bright green #5FD700
#5fd75f pale green #5FD75F
#5fd787 pastel green #5FD787
#5fd7af downy #5FD7AF
#5fd7d7 viking #5FD7D7
#5fd7ff steel blue #5FD7FF
#5fff00 chartreuse #5FFF00
#5fff5f screaming green #5FFF5F
#5fff87 sea green 1 #5FFF87
#5fffaf aquamarine 1 #5FFFAF
#5fffd7 aquamarine 2 #5FFFD7
#5fffff aquamarine #5FFFFF
#870000 dark red #870000
#87005f fresh eggplant #87005F
#870087 dark magenta #870087
#8700af purple 2 #8700AF
#8700d7 electric violet #8700D7
#8700ff purple 1 #8700FF
#875f00 brown #875F00
#875f5f copper rose #875F5F
#875f87 strike master #875F87
#875faf deluge #875FAF
#875fd7 medium purple #875FD7
#875fff heliotrope #875FFF
#878700 olive 1 #878700
#87875f clay creek #87875F
#878787 gray 1 #878787
#878787 grey 1 #878787
#8787af wild blue yonder #8787AF
#8787d7 chetwode blue #8787D7
#8787ff light slate blue #8787FF
#87af00 limeade 1 #87AF00
#87af5f chelsea cucumber #87AF5F
#87af87 bay leaf #87AF87
#87afaf gulf stream #87AFAF
#87afd7 polo blue #87AFD7
#87afff malibu 1 #87AFFF
#87d700 pistachio #87D700
#87d75f dark olive green #87D75F
#87d787 feijoa #87D787
#87d7af vista blue #87D7AF
#87d7d7 bermuda #87D7D7
#87d7ff anakiwa #87D7FF
#87ff00 chartreuse 1 #87FF00
#87ff5f light green #87FF5F
#87ff87 mint green #87FF87
#87ffaf pale green 1 #87FFAF
#87ffd7 aqua marine #87FFD7
#87ffff anakiwa 1 #87FFFF
#af0000 bright red #AF0000
#af005f flirt #AF005F
#af0087 medium violet red #AF0087
#af00af magenta 1 #AF00AF
#af00d7 dark violet #AF00D7
#af00ff purple 4 #AF00FF
#af5f00 rose of sharon #AF5F00
#af5f5f indian red #AF5F5F
#af5f87 tapestry #AF5F87
#af5faf fuchsia pink #AF5FAF
#af5fd7 medium purple 1 #AF5FD7
#af5fff heliotrope 1 #AF5FFF
#af8700 pirate gold #AF8700
#af875f muesli #AF875F
#af8787 pharlap #AF8787
#af87af bouquet #AF87AF
#af87d7 lavender #AF87D7
#af87ff heliotrope 2 #AF87FF
#afaf00 gold 1 #AFAF00
#afaf5f olive green #AFAF5F
#afaf87 hillary #AFAF87
#afafaf silver chalice #AFAFAF
#afafd7 wistful #AFAFD7
#afafff melrose #AFAFFF
#afd700 rio grande #AFD700
#afd75f conifer #AFD75F
#afd787 feijoa 1 #AFD787
#afd7af pixie green #AFD7AF
#afd7d7 jungle mist #AFD7D7
#afd7ff anakiwa 2 #AFD7FF
#afff00 lime 1 #AFFF00
#afff5f green yellow #AFFF5F
#afff87 mint green 1 #AFFF87
#afffaf dark sea green #AFFFAF
#afffd7 aero blue #AFFFD7
#afffff french pass #AFFFFF
#d70000 guardsman red #D70000
#d7005f razzmatazz #D7005F
#d70087 hollywood cerise #D70087
#d700af hollywood cerise 1 #D700AF
#d700d7 purple pizzazz #D700D7
#d700ff electric violet 1 #D700FF
#d75f00 tenn #D75F00
#d75f5f roman #D75F5F
#d75f87 cranberry #D75F87
#d75faf hopbush #D75FAF
#d75fd7 orchid #D75FD7
#d75fff medium orchid #D75FFF
#d78700 mango tango #D78700
#d7875f copperfield #D7875F
#d78787 pink #D78787
#d787af cancan #D787AF
#d787d7 light orchid #D787D7
#d787ff heliotrope 3 #D787FF
#d7af00 corn #D7AF00
#d7af5f tacha #D7AF5F
#d7af87 tan #D7AF87
#d7afaf clam shell #D7AFAF
#d7afd7 thistle #D7AFD7
#d7afff mauve #D7AFFF
#d7d700 corn 1 #D7D700
#d7d75f khaki #D7D75F
#d7d787 deco #D7D787
#d7d7af green mist #D7D7AF
#d7d7d7 alto #D7D7D7
#d7d7ff fog #D7D7FF
#d7ff00 chartreuse yellow #D7FF00
#d7ff5f canary #D7FF5F
#d7ff87 honeysuckle #D7FF87
#d7ffaf reef #D7FFAF
#d7ffd7 snowy mint #D7FFD7
#d7ffff oyster bay #D7FFFF
#ff005f rose #FF005F
#ff0087 deep pink #FF0087
#ff00af hollywood cerise 2 #FF00AF
#ff00d7 purple pizzazz 1 #FF00D7
#ff00ff magenta #FF00FF
#ff5f00 blaze orange #FF5F00
#ff5f5f bitter sweet #FF5F5F
#ff5f87 wild watermelon #FF5F87
#ff5faf hotpink #FF5FAF
#ff5fd7 hotpink 1 #FF5FD7
#ff5fff pink flamingo #FF5FFF
#ff8700 flush orange #FF8700
#ff875f salmon #FF875F
#ff8787 vivid tangerine #FF8787
#ff87af pink salmon #FF87AF
#ff87d7 lavender rose #FF87D7
#ff87ff blush pink #FF87FF
#ffaf00 yellow sea #FFAF00
#ffaf5f texas rose #FFAF5F
#ffaf87 hit pink #FFAF87
#ffafaf sundown #FFAFAF
#ffafd7 cotton candy #FFAFD7
#ffafff lavender rose 1 #FFAFFF
#ffd700 gold #FFD700
#ffd75f dandelion #FFD75F
#ffd787 grandis #FFD787
#ffd7af caramel #FFD7AF
#ffd7d7 cosmos #FFD7D7
#ffd7ff pink lace #FFD7FF
#ffff5f laser lemon #FFFF5F
#ffff87 dolly #FFFF87
#ffffaf portafino #FFFFAF
#ffffd7 cumulus #FFFFD7
#080808 cod gray #080808
#121212 cod gray 1 #121212
#1c1c1c cod gray 2 #1C1C1C
#262626 mine shaft #262626
#303030 mine shaft 1 #303030
#3a3a3a mine shaft 2 #3A3A3A
#444444 tundora #444444
#4e4e4e tundora 1 #4E4E4E
#585858 scorpion 1 #585858
#626262 dove gray #626262
#6c6c6c dove gray 1 #6C6C6C
#767676 boulder #767676
#8a8a8a gray 2 #8A8A8A
#8a8a8a grey 2 #8A8A8A
#949494 dusty gray #949494
#9e9e9e silver chalice 1 #9E9E9E
#a8a8a8 silver chalice 2 #A8A8A8
#b2b2b2 silver chalice 3 #B2B2B2
#bcbcbc silver 1 #BCBCBC
#c6c6c6 silver 2 #C6C6C6
#d0d0d0 alto 1 #D0D0D0
#dadada alto 2 #DADADA
#e4e4e4 mercury #E4E4E4
#eeeeee gallery #EEEEEE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

termspark-2.2.1-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file termspark-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: termspark-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for termspark-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6eef3d542bfaab5f0517285b146ad8ea57a3d11c8bb12a90d9607db4cd29e265
MD5 820bfe42f7d5f741d0a6f5196409e991
BLAKE2b-256 55aca216f96c330578abf92078f524adc04b8cba638c9b213e13b17f1f583880

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page