Python library to decorate and beautify your standard output ๐
To get the latest version, simply use pip:
pip install outputformat
There are no dependencies.
Python>=3.6
is needed, as it uses f strings.
It is recommended to use ouf
as shortcut for outputformat
:
import outputformat as ouf
Main functions are:
ouf.boxtitle
ouf.linetitle
ouf.bigtitle
ouf.showlist
ouf.bar
ouf.barlist
By default, functions print
the result. You have the alternative to return a string
instead, by passing the argument return_str=True
(nothing will be printed in this case).
To decorate titles with a box around it, use ouf.boxtitle
:
ouf.boxtitle("Long title in a box")
โญโโโโโโโโโโโโโโโโโโโโโโฎ
โ Long title in a box โ
โฐโโโโโโโโโโโโโโโโโโโโโโฏ
Boxes can have different styles:
ouf.boxtitle("Box with 'line' style", style="line")
ouf.boxtitle("Box with 'double' style", style="double")
ouf.boxtitle("Box with 'dashes' style", style="dashes")
โญโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Box with 'line' style โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโฏ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Box with 'double' style โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Box with 'dashes' style โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Or you can pass any character and it will be used for the decoration:
ouf.boxtitle("Box with custom character as style", style="รธ")
รธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธ
รธ Box with custom character as style รธ
รธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธรธ
With all the same options as for boxtitle
, you can use linetitle
for a simple line underneath your text:
ouf.linetitle("Long title with 'double' underline", style="double")
Long title with 'double' underline
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
It is possible to use ASCII art to generate big titles:
outputstring = ouf.bigtitle("Here's a big title!")
โ โ โโโ โโโ โโโ โ โโ โโโ โโโ โ โโโ โโโ โ โโโ โ โโโ โ
โโโ โโโ โโโ โโโ โโ โโโ โโโ โ โโโ โ โ โ โโโ โโโ โ
Currently, only one font is available, and the supported characters are: "0123456789abcdefghijklmnopqrstuvwxyz_-!.' "
(You can get them by using ouf.fonts.suported_chars
)
You can simply show a list using bullet points:
data = ["Item A", "Item B", "Item C", "Item D"]
ouf.showlist(data)
โข Item A
โข Item B
โข Item C
โข Item D
And also there's an option to add a title to your list:
data = ["Item A", "Item B", "Item C", "Item D"]
ouf.showlist(data, title="List of items")
List of items
โข Item A
โข Item B
โข Item C
โข Item D
Different styles are available, as bullet
, line
, box
and ordinal
data = ["Item A", "Item B", "Item C", "Item D"]
ouf.showlist(data, style="line", title="Style line")
ouf.showlist(data, style="box", title="Style box")
ouf.showlist(data, style="ordinal", title="Style ordinal")
Style line
โญโโโโโโโโโโ
โ Item A
โ Item B
โ Item C
โฐ Item D
โญโโโโโโโโโโโโฎ
โ Style box โ
โโโโโโโโโโโโโฏ
โ Item A
โ Item B
โ Item C
โฐ Item D
Style ordinal
1. Item A
2. Item B
3. Item C
4. Item D
Or pass any string to be used as marker
data = ["Item A", "Item B", "Item C", "Item D"]
ouf.showlist(data, style="~>", title="Custom style list")
Custom style list
~> Item A
~> Item B
~> Item C
~> Item D
You can create a simple horizontal bar using ouf.bar
The first parameter (value
) is the filled amount, the second (maxvalue
) is the maximum amount
ouf.bar(35, 50)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 35/50 ( 70.00%)
Note that there's some integer rounding needed to create the bar, so the size is not precise, more like a ballpark visualisation.
The size of the bar (in characters) is defined by length
ouf.bar(35, 50, length=10)
ouf.bar(35, 50, length=50)
โโโโโโโโโโ 35/50 ( 70.00%)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 35/50 ( 70.00%)
Different styles are available, as well as the option to have a title before the bar:
ouf.bar(35, 50, style="block", length=15, title="Block style", title_pad=15)
ouf.bar(35, 50, style="battery", length=15,title="Battery style", title_pad=15)
ouf.bar(35, 50, style="bar", length=15, title="Bar style", title_pad=15)
ouf.bar(35, 50, style="circle", length=15, title="Circle style", title_pad=15)
Block style....: โโโโโโโโโโโโโโโ 35/50 ( 70.00%)
Battery style..: โซโโโโโโโโโโ โฃ 35/50 ( 70.00%)
Bar style......: [โ โ โ โ โ โ โ โ โ โ ] 35/50 ( 70.00%)
Circle style...: โโโโโโโโโโโโโโโ 35/50 ( 70.00%)
There's also a star emoji style, that works better with small values for length
and using show_percentage=False
and show_values=False
ouf.bar(60, 100, style="star", length=5, title="Item A", show_percentage=False, show_values=False)
ouf.bar(20, 100, style="star", length=5, title="Item B", show_percentage=False, show_values=False)
ouf.bar(90, 100, style="star", length=5, title="Item C", show_percentage=False, show_values=False)
Item A: โญโญโญ
Item B: โญ
Item C: โญโญโญโญ
A totally custom style for the bar can be created, passing a list of characters as style
ouf.bar(35, 50, style=["(", "X", "-", ")"], title="Custom style")
Custom style: (XXXXXXXXXXXXXXXXXXXXXX----------) 35/50 ( 70.00%)
Or you can pass just a simple character, and it will be used for a basic bar:
ouf.bar(35, 50, style="$", title="Custom style")
Custom style: [$$$$$$$$$$$$$$$$$$$$$$ ] 35/50 ( 70.00%)
It is possible to use ouf.barlist
and pass directly a list of values
with the correspondent list of titles
values = [6, 3, 13, 8]
titles = ["var", "long var name", "medium var", "one more"]
ouf.barlist(values, titles, maxvalue=15, style="bar")
var..........: [โ โ โ โ โ โ โ โ โ โ โ โ ] 6/15 ( 40.00%)
long var name: [โ โ โ โ โ โ ] 3/15 ( 20.00%)
medium var...: [โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ ] 13/15 ( 86.67%)
one more.....: [โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ ] 8/15 ( 53.33%)
The same parameters from ouf.bar
can be used. Only one maxvalue
is used for all the lists
Some shortcuts for the unicode values of common emoji are available
print(ouf.emoji.heart, ouf.emoji.thumbs_up)
๐ ๐
Current shortcuts are the following:
crazy.............:๐คช
sad...............:๐ฅ
circle_red........:๐ด
circle_orange.....:๐
circle_yellow.....:๐ก
circle_green......:๐ข
circle_white......:โช
circle_black......:โซ
star..............:โญ
heart.............:๐
thumbs_up.........:๐
check.............:โ
clap..............:๐
bomb..............:๐ฃ