[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/6] python/aqmp-tui: add syntax highlighting
From: |
G S Niteesh Babu |
Subject: |
[PATCH v2 5/6] python/aqmp-tui: add syntax highlighting |
Date: |
Wed, 14 Jul 2021 03:37:33 +0530 |
Add syntax highlighting for the incoming and outgoing QMP messages.
This is achieved using the pygments module which was added in a
previous commit.
The current implementation is a really simple one which doesn't
allow for any configuration. In future this has to be improved
to allow for easier theme config using an external config of
some sort.
Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
---
python/qemu/aqmp/aqmp_tui.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py
index f853efc1f5..9ee91f0e99 100644
--- a/python/qemu/aqmp/aqmp_tui.py
+++ b/python/qemu/aqmp/aqmp_tui.py
@@ -12,6 +12,8 @@
from logging import Handler
import signal
+from pygments import lexers
+from pygments import token as Token
import urwid
import urwid_readline
@@ -33,6 +35,11 @@
(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'),
]
@@ -133,7 +140,7 @@ def cb_add_to_history(self, msg, level=None):
formatted = []
if level:
msg = f'[{level}]: {msg}'
- formatted.append(msg)
+ formatted.append((level, msg))
else:
lexer = lexers.JsonLexer() # pylint: disable=no-member
for token in lexer.get_tokens(msg):
@@ -162,6 +169,7 @@ def __init__(self, address):
self.address = address
self.aloop = None
self.loop = None
+ self.screen = urwid.raw_display.Screen()
super().__init__()
def add_to_history(self, msg, level=None):
@@ -249,8 +257,10 @@ def run(self, debug=False):
self.aloop.add_signal_handler(sig, self.kill_app)
event_loop = urwid.AsyncioEventLoop(loop=self.aloop)
- self.loop = urwid.MainLoop(self.window,
+ self.loop = urwid.MainLoop(urwid.AttrMap(self.window, 'background'),
unhandled_input=self.unhandled_input,
+ screen=self.screen,
+ palette=palette,
handle_mouse=True,
event_loop=event_loop)
--
2.17.1
- [PATCH v2 0/6] python: AQMP-TUI Prototype, G S Niteesh Babu, 2021/07/13
- [PATCH v2 1/6] python: disable pylint errors for aqmp-tui, G S Niteesh Babu, 2021/07/13
- [PATCH v2 2/6] python: Add dependencies for AQMP TUI, G S Niteesh Babu, 2021/07/13
- [PATCH v2 3/6] python/aqmp-tui: Add AQMP TUI draft, G S Niteesh Babu, 2021/07/13
- [PATCH v2 4/6] python: add optional pygments dependency, G S Niteesh Babu, 2021/07/13
- [PATCH v2 5/6] python/aqmp-tui: add syntax highlighting,
G S Niteesh Babu <=
- [PATCH v2 6/6] python: add entry point for aqmp-tui, G S Niteesh Babu, 2021/07/13
- Re: [PATCH v2 0/6] python: AQMP-TUI Prototype, Niteesh G. S., 2021/07/14