From: G S Niteesh Babu <niteesh.gs@gmail.com>
To: qemu-devel@nongnu.org
Cc: G S Niteesh Babu <niteesh.gs@gmail.com>,
John Snow <jsnow@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Cleber Rosa <crosa@redhat.com>
Subject: [PATCH v2 5/6] python/aqmp-tui: add syntax highlighting
Date: Wed, 14 Jul 2021 03:37:33 +0530 [thread overview]
Message-ID: <20210713220734.26302-6-niteesh.gs@gmail.com> (raw)
In-Reply-To: <20210713220734.26302-1-niteesh.gs@gmail.com>
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
next prev parent reply other threads:[~2021-07-13 22:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-13 22:07 [PATCH v2 0/6] python: AQMP-TUI Prototype G S Niteesh Babu
2021-07-13 22:07 ` [PATCH v2 1/6] python: disable pylint errors for aqmp-tui G S Niteesh Babu
2021-07-13 22:07 ` [PATCH v2 2/6] python: Add dependencies for AQMP TUI G S Niteesh Babu
2021-07-13 22:07 ` [PATCH v2 3/6] python/aqmp-tui: Add AQMP TUI draft G S Niteesh Babu
2021-07-20 17:57 ` John Snow
2021-07-20 18:01 ` Niteesh G. S.
2021-07-20 19:04 ` John Snow
2021-07-21 20:22 ` Niteesh G. S.
2021-07-13 22:07 ` [PATCH v2 4/6] python: add optional pygments dependency G S Niteesh Babu
2021-07-13 22:07 ` G S Niteesh Babu [this message]
2021-07-13 22:07 ` [PATCH v2 6/6] python: add entry point for aqmp-tui G S Niteesh Babu
2021-07-14 19:06 ` [PATCH v2 0/6] python: AQMP-TUI Prototype Niteesh G. S.
2021-07-20 19:08 ` John Snow
2021-07-21 18:08 ` Niteesh G. S.
2021-07-21 20:03 ` John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210713220734.26302-6-niteesh.gs@gmail.com \
--to=niteesh.gs@gmail.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=jsnow@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.