forked from Mirror/pmbootstrap
pmbootstrap: add color support (MR 2090)
Can be disabled by setting the $NO_COLOR environment variable
This commit is contained in:
parent
e1aef47271
commit
87dd1d0961
3 changed files with 52 additions and 6 deletions
|
@ -3,6 +3,7 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
import pmb.config
|
||||
|
||||
|
||||
class log_handler(logging.StreamHandler):
|
||||
|
@ -20,7 +21,33 @@ class log_handler(logging.StreamHandler):
|
|||
not self._args.quiet and
|
||||
record.levelno >= logging.INFO):
|
||||
stream = self.stream
|
||||
stream.write(msg)
|
||||
|
||||
styles = pmb.config.styles
|
||||
|
||||
msg_col = (
|
||||
msg.replace(
|
||||
"NOTE:",
|
||||
f"{styles['BLUE']}NOTE:{styles['END']}",
|
||||
1,
|
||||
)
|
||||
.replace(
|
||||
"WARNING:",
|
||||
f"{styles['YELLOW']}WARNING:{styles['END']}",
|
||||
1,
|
||||
)
|
||||
.replace(
|
||||
"ERROR:",
|
||||
f"{styles['RED']}ERROR:{styles['END']}",
|
||||
1,
|
||||
)
|
||||
.replace(
|
||||
"DONE!",
|
||||
f"{styles['GREEN']}DONE!{styles['END']}",
|
||||
1,
|
||||
)
|
||||
)
|
||||
|
||||
stream.write(msg_col)
|
||||
stream.write(self.terminator)
|
||||
self.flush()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue