Package: minchin.text
minchin.textPython library for text formatting on the command line.Available Data__version__library version.re_ansi_control_codesCompiled regex pattern for ANSI control codes, including colors.re_weburlCompiled regex pattern for web URL’s – http, https, and naked domains like “example.com”re_allurlCompiled regex pattern to match all URL’s, including “mailto:foo@example.com”,
“x-whatever://foo”, etc.AnswersAn Enum containing the possible query answers. Current containsYES,NO,QUIT,ALL, andNONE.YESandALLare “truth-y”
whileNO,QUIT, andNONEare “false-y”.Available Commandslength_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 stringcentered (mystring, linewidth=None, fill=” “)Takes a string, centres it, and pads it on both sides. Defaultlinewidthis
one less than the console width.clock_on_right(mystring)Takes a string, and prints it with the time right alignedquery_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.NOquery_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.ALLdef 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.QUITquery_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.NONEwait(sec)Prints a timer with the format 0:00 to the console,
and then clears the line when the timer is done.title(mytitle)Takesmytitle, centers it, and prints it in yellow letters on a blue
background.subtitle(mysubtitle)Takesmysubtitle, centers it, and prints it in bright (white) letters on a
normal (black) background.rainbow_print(text, offset=0)Prints outtextin a cycle of rainbow-esque colors!progressbar (class)This class is used to create and then update a ‘progress bar’, like:[================>]17/70progressbar(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.CodeThe code is available athttps://github.com/MinchinWeb/minchin.textContributions are welcome!TestsLocated in thetestfolder. Each is a “visual test”, so they need to be run and the output manually examined.LicenseThe code is licensed under the MIT license. See that attachedLICENSEfile.Minchin.Text Changelogv 6.1.0 [2021-02-09]addedprint_cols()to print text in multiple columnsv 6.0.2 [2020-04-17]fixed bug whereprogressbarwould sometimes not calculated the needed bar
lengthfixed 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 forprogressbarfixedprogressbarnumbers to be displayed with thousands commas, if large
enoughv 6.0.0 [2019-02-08][BREAKING CHANGE] queries now return one ofAnswer.YES,Answer.NO,Answer.QUIT,Answer.ALL, orAnswer.NONE, as appropriate.YESandALLare “Truth-y”, whileNO,QUIT, andNONEare “False-y”addedquery_yes_no_all_none()addedrainbow_print()to print strings in all the colours!v 5.1.1 [2017-10-03]allowsetup.pyto work with versions of Python before 3.6remove hardcoded terminal width of 79 charactersv 5.1.0 [2017-01-29]minchin.text.progressbar()will only print (by default) every 0.1 secondsfixed progressbar bug where “overfull” bars would go on to multiple linesaddedget_terminal_size()upgraded release machineryv 5.0 [2015-06-10][BREAKING CHANGE] moved package tominchin.textadded tests forminchin.text.centered()added end character to progress baradded documentation to README.rstv 4.4 [2014-10-26]typographic changes to allow wmtext to work in Python 3v 4.1 [2014-03-10]allow access as a direct object. i.e. useimport wmtextrather thanfrom wmtext import wmtextv 4.0 [2014-02-06]packaged as a separate moduleadded progress barfirst public releasev 3.2 [2014-02-02]addlength_no_ansi()allowing you to determine the length of a string
after stripping out ANSI codes.