Introduce hack to color all click.echo instances at once.
This commit is contained in:
@@ -1,7 +1,42 @@
|
||||
# iottb/utils/user_interaction.py
|
||||
|
||||
import click
|
||||
import logging
|
||||
from iottb import definitions
|
||||
from iottb.definitions import TB_ECHO_STYLES
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
class IottbPrompt:
|
||||
pass
|
||||
def tb_echo2(msg: str, lvl='i', log=True):
|
||||
style = TB_ECHO_STYLES.get(lvl, {})
|
||||
click.secho(f'[IOTTB]', **style)
|
||||
click.secho(f'[IOTTB] \t {msg}', **style)
|
||||
|
||||
|
||||
last_prefix = None
|
||||
|
||||
|
||||
def tb_echo(msg: str, lvl='i', log=True):
|
||||
global last_prefix
|
||||
prefix = f'Testbed [{lvl.upper()}]\n'
|
||||
|
||||
if last_prefix != prefix:
|
||||
click.secho(prefix, nl=False, **TB_ECHO_STYLES['header'])
|
||||
last_prefix = prefix
|
||||
|
||||
click.secho(f' {msg}', **TB_ECHO_STYLES[lvl])
|
||||
|
||||
|
||||
def main():
|
||||
tb_echo('Info message', 'i')
|
||||
tb_echo('Warning message', 'w')
|
||||
tb_echo('Error message', 'e')
|
||||
tb_echo('Success message', 's')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# arrrgggg hacky
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
project_root = os.path.abspath(os.path.join(current_dir, '../../'))
|
||||
sys.path.insert(0, project_root)
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user