Handful of utilities to do printing tricks to the terminal.
Project description
printbuddies
A few utilities to do terminal printing tricks.
Install with:
pip install printbuddies
Contains one class and three functions: ProgBar, print_in_place, ticker, and clear.
ProgBar
ProgBar is a self-incrementing, dynamically sized progress bar.
The progress counter and completion values can be manually overriden if desired.
The width of the progress bar is set according to a ratio of the terminal width
so it will be resized automatically if the terminal width is changed.
from printbuddies import ProgBar total = 100 bar = ProgBar(total=total) for _ in range(total): bar.display() bar.reset() my_list = [bar.display(return_object=i) for i in range(total)]
The display function has a 'return_object' parameter, allowing ProgBar to be used in comprehensions.
bar = ProgBar(10) def square(x: int | float)->int|float: return x * x myList = [bar.display(return_object=square(i)) for i in range(10)] {progress bar gets displayed} print(myList) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
ProgBar also supports being used with a context manager.
Spinner
This class will print the next character from a sequence every time it's display
method is called, clearing whatever is currently on the line.
The characters will be cycled through indefinitely.
from printbuddies import Spinner spinner = Spinner() for _ in range(10): spinner.display()
The default character sequence can be overridden:
spinner = Spinner(sequence=["~_~_~_~_~_~_", "_~_~_~_~_~_~"]) for _ in range(10): spinner.display()
When used with a context manager, the last character printed will be cleared from the terminal upon exiting.
print_in_place
'print_in_place' erases the current line in the terminal and then writes the value of
the 'string' param to the terminal.
from printbuddies import print_in_place import time #This will print numbers 0-99 to the terminal with each digit overwriting the last. for i in range(100): print_in_place(i) time.sleep(0.1)
ticker
'ticker' prints a list of strings to the terminal with empty lines above and below
such that previous text in the terminal is no longer visible.
Visually, It functions as a multi-line version of print_in_place.
from printbuddies import ticker import time #This will produce visually the same output as the above example for i in range(100): ticker([i]) time.sleep(0.1)
clear
A call to printbuddies.clear()
simply clears the current line from the terminal.
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 printbuddies-1.2.0.tar.gz
.
File metadata
- Download URL: printbuddies-1.2.0.tar.gz
- Upload date:
- Size: 53.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 478e75651121edbaca645f3f5371d004beb7d4c5df99a30457524be4fc52d223 |
|
MD5 | 6270c27aa1ae945538dd8b3ddf169e53 |
|
BLAKE2b-256 | a341ef80b53dac20477212bdbd9117814337811d2e35f28f30d3306bce33bc76 |
Provenance
File details
Details for the file printbuddies-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: printbuddies-1.2.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1632a8121e1092ab3e4ab5a424e9ed3d038c8b3be8a8a8ffbe459de48bb2e3f |
|
MD5 | 25c069dcabeeb8dd462064b565a6599f |
|
BLAKE2b-256 | 1036089e7e985e65640287ab4fa23446d505f572d31e6bdca9fa30cfd54008a2 |