- Replaced
.formatwith 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)msgis the message to be printedlogis a boolean value, whereTruemeans to log information to syslog if the system supports syslogfileis takes a_io.TextIOWrapperobject, 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)msgis the message to be printeddefaultis the default value to return whenbatchis True, or when user input is emptybatchtells the function to return its default value without asking the user for inputfileis takes a_io.TextIOWrapperobject, 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)msgis the message to be printeddefaultis the default value to return when user input is blankbatchtells 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')