|
@@ -30,6 +30,8 @@
|
|
cast,
|
|
cast,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+from pygments import lexers
|
|
|
|
+from pygments import token as Token
|
|
import urwid
|
|
import urwid
|
|
import urwid_readline
|
|
import urwid_readline
|
|
|
|
|
|
@@ -45,6 +47,22 @@
|
|
UPDATE_MSG: str = 'UPDATE_MSG'
|
|
UPDATE_MSG: str = 'UPDATE_MSG'
|
|
|
|
|
|
|
|
|
|
|
|
+palette = [
|
|
|
|
+ (Token.Punctuation, '', '', '', 'h15,bold', 'g7'),
|
|
|
|
+ (Token.Text, '', '', '', '', 'g7'),
|
|
|
|
+ (Token.Name.Tag, '', '', '', 'bold,#f88', 'g7'),
|
|
|
|
+ (Token.Literal.Number.Integer, '', '', '', '#fa0', 'g7'),
|
|
|
|
+ (Token.Literal.String.Double, '', '', '', '#6f6', 'g7'),
|
|
|
|
+ (Token.Keyword.Constant, '', '', '', '#6af', 'g7'),
|
|
|
|
+ ('DEBUG', '', '', '', '#ddf', 'g7'),
|
|
|
|
+ ('INFO', '', '', '', 'g100', 'g7'),
|
|
|
|
+ ('WARNING', '', '', '', '#ff6', 'g7'),
|
|
|
|
+ ('ERROR', '', '', '', '#a00', 'g7'),
|
|
|
|
+ ('CRITICAL', '', '', '', '#a00', 'g7'),
|
|
|
|
+ ('background', '', 'black', '', '', 'g7'),
|
|
|
|
+]
|
|
|
|
+
|
|
|
|
+
|
|
def format_json(msg: str) -> str:
|
|
def format_json(msg: str) -> str:
|
|
"""
|
|
"""
|
|
Formats valid/invalid multi-line JSON message into a single-line message.
|
|
Formats valid/invalid multi-line JSON message into a single-line message.
|
|
@@ -353,6 +371,9 @@ def run(self, debug: bool = False) -> None:
|
|
:param debug:
|
|
:param debug:
|
|
Enables/Disables asyncio event loop debugging
|
|
Enables/Disables asyncio event loop debugging
|
|
"""
|
|
"""
|
|
|
|
+ screen = urwid.raw_display.Screen()
|
|
|
|
+ screen.set_terminal_properties(256)
|
|
|
|
+
|
|
self.aloop = asyncio.get_event_loop()
|
|
self.aloop = asyncio.get_event_loop()
|
|
self.aloop.set_debug(debug)
|
|
self.aloop.set_debug(debug)
|
|
|
|
|
|
@@ -364,6 +385,8 @@ def run(self, debug: bool = False) -> None:
|
|
event_loop = urwid.AsyncioEventLoop(loop=self.aloop)
|
|
event_loop = urwid.AsyncioEventLoop(loop=self.aloop)
|
|
main_loop = urwid.MainLoop(urwid.AttrMap(self.window, 'background'),
|
|
main_loop = urwid.MainLoop(urwid.AttrMap(self.window, 'background'),
|
|
unhandled_input=self.unhandled_input,
|
|
unhandled_input=self.unhandled_input,
|
|
|
|
+ screen=screen,
|
|
|
|
+ palette=palette,
|
|
handle_mouse=True,
|
|
handle_mouse=True,
|
|
event_loop=event_loop)
|
|
event_loop=event_loop)
|
|
|
|
|
|
@@ -487,7 +510,8 @@ def __init__(self, parent: App) -> None:
|
|
self.history = urwid.SimpleFocusListWalker([])
|
|
self.history = urwid.SimpleFocusListWalker([])
|
|
super().__init__(self.history)
|
|
super().__init__(self.history)
|
|
|
|
|
|
- def add_to_history(self, history: str) -> None:
|
|
|
|
|
|
+ def add_to_history(self,
|
|
|
|
+ history: Union[str, List[Tuple[str, str]]]) -> None:
|
|
"""
|
|
"""
|
|
Appends a message to the list and set the focus to the last appended
|
|
Appends a message to the list and set the focus to the last appended
|
|
message.
|
|
message.
|
|
@@ -531,10 +555,18 @@ def cb_add_to_history(self, msg: str, level: Optional[str] = None) -> None:
|
|
|
|
|
|
:param msg:
|
|
:param msg:
|
|
The message to be appended to the history box.
|
|
The message to be appended to the history box.
|
|
|
|
+ :param level:
|
|
|
|
+ The log level of the message, if it is a log message.
|
|
"""
|
|
"""
|
|
|
|
+ formatted = []
|
|
if level:
|
|
if level:
|
|
msg = f'[{level}]: {msg}'
|
|
msg = f'[{level}]: {msg}'
|
|
- self.history.add_to_history(msg)
|
|
|
|
|
|
+ formatted.append((level, msg))
|
|
|
|
+ else:
|
|
|
|
+ lexer = lexers.JsonLexer() # pylint: disable=no-member
|
|
|
|
+ for token in lexer.get_tokens(msg):
|
|
|
|
+ formatted.append(token)
|
|
|
|
+ self.history.add_to_history(formatted)
|
|
|
|
|
|
|
|
|
|
class Window(urwid.Frame):
|
|
class Window(urwid.Frame):
|