Python library for text formatting on the command line.
Project description
minchin.text
Python library for text formatting on the command line.
Available Data
__version__
library version.
re_ansi_control_codes
Compiled regex pattern for ANSI control codes, including colors.
re_weburl
Compiled regex pattern for web URL’s – http, https, and naked domains like “example.com”
re_allurl
Compiled regex pattern to match all URL’s, including “mailto:foo@example.com”, “x-whatever://foo”, etc.
Answers
An Enum containing the possible query answers. Current contains YES, NO, QUIT, ALL, and NONE. YES and ALL are “truth-y” while NO, QUIT, and NONE are “false-y”.
Available Commands
length_no_ansi(mystring)
Takes a string, strips out the ANSI escape codes (used for colouring terminal output, etc.), and returns the length of the resulting string
centered (mystring, linewidth=None, fill=” “)
Takes a string, centres it, and pads it on both sides. Default linewidth is one less than the console width.
clock_on_right(mystring)
Takes a string, and prints it with the time right aligned
query_yes_no(question, default=”yes”)
Ask a yes/no question via raw_input() and return their answer.
“question” is a string that is presented to the user.
“default” is the presumed answer if the user just hits <Enter>. It must be “yes” (the default), “no” or None (meaning an answer is required of the user).
Returns one of Answer.YES or Answer.NO
query_yes_no_all(question, default=”yes”)
Ask a yes/no/all question via raw_input() and return their answer.
“question” is a string that is presented to the user.
“default” is the presumed answer if the user just hits <Enter>. It must be “yes” (the default), “no”, “all” or None (meaning an answer is required of the user).
Returns one of Answer.YES, Answer.NO, or Answer.ALL
def query_yes_quit(question, default=”quit”)
Ask a yes/quit question via raw_input() and return their answer.
“question” is a string that is presented to the user.
“default” is the presumed answer if the user just hits <Enter>. It must be “yes” (the default), “quit” or None (meaning an answer is required of the user).
Returns one of Answer.YES or Answer.QUIT
query_yes_no_all_none(question, default=”yes”)
Ask a yes/no/all/none question via raw_input() and return their answer.
“question” is a string that is presented to the user.
“default” is the presumed answer if the user just hits <Enter>. It must be “yes” (the default), “no”, “all”, “none” (i.e. the string) or None (meaning an answer is required of the user).
Returns one of Answer.YES, Answer.NO, Answer.ALL, or Answer.NONE
wait(sec)
Prints a timer with the format 0:00 to the console, and then clears the line when the timer is done.
title(mytitle)
Takes mytitle, centers it, and prints it in yellow letters on a blue background.
subtitle(mysubtitle)
Takes mysubtitle, centers it, and prints it in bright (white) letters on a normal (black) background.
rainbow_print(text, offset=0)
Prints out text in a cycle of rainbow-esque colors!
progressbar (class)
This class is used to create and then update a ‘progress bar’, like:
[================> ] 17 / 70
progressbar(current=0, maximum=100, bar_color=colorama.Fore.GREEN)
Creates a progress bar class. Prints the progress bar.
progressbar.update(currently=None)
Updates the value of the progress bar and prints it.
progressbar.reset()
Sets the value of the progress bar to 0 (zero) and prints it.
Code
The code is available at https://github.com/MinchinWeb/minchin.text
Contributions are welcome!
Tests
Located in the test folder. Each is a “visual test”, so they need to be run and the output manually examined.
License
The code is licensed under the MIT license. See that attached LICENSE file.
Minchin.Text Changelog
v 6.1.0 [2021-02-09]
added print_cols() to print text in multiple columns
v 6.0.2 [2020-04-17]
fixed bug where progressbar would sometimes not calculated the needed bar length
fixed display issue where is wasn’t clear what the possible answers to queries were. This does make the output quite a bit longer.
v 6.0.1 [2020-04-10]
fixed alignment issues if you change the maximum value for progressbar
fixed progressbar numbers to be displayed with thousands commas, if large enough
v 6.0.0 [2019-02-08]
[BREAKING CHANGE] queries now return one of Answer.YES, Answer.NO, Answer.QUIT, Answer.ALL, or Answer.NONE, as appropriate. YES and ALL are “Truth-y”, while NO, QUIT, and NONE are “False-y”
added query_yes_no_all_none()
added rainbow_print() to print strings in all the colours!
v 5.1.1 [2017-10-03]
allow setup.py to work with versions of Python before 3.6
remove hardcoded terminal width of 79 characters
v 5.1.0 [2017-01-29]
minchin.text.progressbar() will only print (by default) every 0.1 seconds
fixed progressbar bug where “overfull” bars would go on to multiple lines
added get_terminal_size()
upgraded release machinery
v 5.0 [2015-06-10]
[BREAKING CHANGE] moved package to minchin.text
added tests for minchin.text.centered()
added end character to progress bar
added documentation to README.rst
v 4.4 [2014-10-26]
typographic changes to allow wmtext to work in Python 3
v 4.1 [2014-03-10]
allow access as a direct object. i.e. use import wmtext rather than from wmtext import wmtext
v 4.0 [2014-02-06]
packaged as a separate module
added progress bar
first public release
v 3.2 [2014-02-02]
add length_no_ansi() allowing you to determine the length of a string after stripping out ANSI codes.
Project details
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 minchin.text-6.1.0.tar.gz
.
File metadata
- Download URL: minchin.text-6.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e01d4eec7e6b15ee9d550c07f0e80c96f5ab2f195f3253dbd8fe3d3a790d3907 |
|
MD5 | 5b6c101caf875b383d476fb1214f8dd9 |
|
BLAKE2b-256 | ac39dc0e49e44de6d0318d483707e00d93a8523a5318bc48dd2835da1afa4f3c |
File details
Details for the file minchin.text-6.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: minchin.text-6.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79e29975896061d6408ea4a075547da31d1498ce0054b5d0a0fa6f5a3b656d17 |
|
MD5 | 10e2bd2e5384447ccf770f79c3c149b1 |
|
BLAKE2b-256 | 03601b845695c346db55cf2b36206078c198a1fa52ffa1dc948d2628bdcb5549 |