- Replaced
.format
with f-string - Added default return values for gets
- If default value is set and user input is blank, default value is returned
- Added docstring for every staticmethod, including description for parameters and return values
Avalon framework makes printing messages and getting user input easier. It includes all UNIX terminal 16 bit colors, ans is also compatible with Windows environments with the help of colorama
.
-
All Linux terminal 16 bit foreground color
-
All Linux terminal 16 bit background color
-
Standardized printing for info, warning, debug, error and etc.
-
The ability to log to syslog
-
The ability to specify output pipe (stdout, stderr, etc.)
-
Easiest way to get user True or False input
if Avalon.ask('Question?', True): # Default is True print('True!')
Avalon Framework includes a few built-in static methods for printing information to terminal.
- Avalon.info
- Avalon.warning
- Avalon.error
- Avalon.debug
- Avalon.debug_info
All of these methods have the same parameters. Avalon.info
, for example, works as the following.
Avalon.info(msg, log=False, file=sys.stdout)
msg
is the message to be printedlog
is a boolean value, whereTrue
means to log information to syslog if the system supports syslogfile
is takes a_io.TextIOWrapper
object, i.e. a pipe to write the message into if the user wants to overwrite the default values
To get user input as a string, Avalon Framework provided the Avalon.gets
method.
Avalon.gets(msg, default=None, batch=False, file=sys.stdout)
msg
is the message to be printeddefault
is the default value to return whenbatch
is True, or when user input is emptybatch
tells the function to return its default value without asking the user for inputfile
is takes a_io.TextIOWrapper
object, i.e. a pipe to write the message into if the user wants to overwrite the default values
Avalon Framework provides a simple way to ask users a Yes or No question with Avalon.ask
.
Avalon.ask(msg, default=False, batch=False)
msg
is the message to be printeddefault
is the default value to return when user input is blankbatch
tells the function to return its default value without asking the user for input
You may create a thread lock to make multi-threaded printing thread-safe.
import threading
Avalon.thread_lock = threading.Lock()
Avalon.info('Here\'s a message')