From: G S Niteesh Babu <niteesh.gs@gmail.com>
To: jsnow@redhat.com
Cc: G S Niteesh Babu <niteesh.gs@gmail.com>,
Cleber Rosa <crosa@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
qemu-devel@nongnu.org
Subject: [PATCH 5/6] python/aqmp-tui: add syntax highlighting
Date: Sat, 3 Jul 2021 02:56:02 +0530 [thread overview]
Message-ID: <20210702212603.26465-6-niteesh.gs@gmail.com> (raw)
In-Reply-To: <20210702212603.26465-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 | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py
index 8e9e8ac8ff..03cb70a523 100644
--- a/python/qemu/aqmp/aqmp_tui.py
+++ b/python/qemu/aqmp/aqmp_tui.py
@@ -11,6 +11,8 @@
import logging
import signal
+from pygments import lexers
+from pygments import token as Token
import urwid
import urwid_readline
@@ -21,6 +23,16 @@
UPDATE_MSG = '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'),
+ ('background', '', 'black', '', '', 'g7'),
+]
+
class StatusBar(urwid.Text):
"""
@@ -115,7 +127,11 @@ def __init__(self, master):
urwid.connect_signal(self.master, UPDATE_MSG, self.cb_add_to_history)
def cb_add_to_history(self, msg):
- self.history.add_to_history(msg)
+ formatted = []
+ 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):
@@ -139,6 +155,7 @@ def __init__(self, address):
self.address = address
self.aloop = asyncio.get_event_loop()
self.loop = None
+ self.screen = urwid.raw_display.Screen()
super().__init__()
# Gracefully handle SIGTERM and SIGINT signals
@@ -210,10 +227,14 @@ def handle_event(self, event):
self.window.footer.set_text('Server shutdown')
def run(self):
+ self.screen.set_terminal_properties(256)
+
self.aloop.set_debug(True)
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-02 21:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-02 21:25 [PATCH 0/6] python: AQMP-TUI Prototype G S Niteesh Babu
2021-07-02 21:25 ` [PATCH 1/6] python: disable pylint errors for aqmp-tui G S Niteesh Babu
2021-07-20 18:00 ` John Snow
2021-07-20 18:30 ` John Snow
2021-07-02 21:25 ` [PATCH 2/6] python: Add dependencies for AQMP TUI G S Niteesh Babu
2021-07-08 1:39 ` John Snow
2021-07-02 21:26 ` [PATCH 3/6] python/aqmp-tui: Add AQMP TUI draft G S Niteesh Babu
2021-07-08 3:20 ` John Snow
2021-07-08 17:20 ` John Snow
2021-07-13 22:08 ` Niteesh G. S.
2021-07-02 21:26 ` [PATCH 4/6] python: add optional pygments dependency G S Niteesh Babu
2021-07-02 21:26 ` G S Niteesh Babu [this message]
2021-07-02 21:26 ` [PATCH 6/6] python: add entry point for aqmp-tui G S Niteesh Babu
2021-07-08 2:14 ` 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=20210702212603.26465-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).