From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE04C4338F for ; Wed, 18 Aug 2021 18:57:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 72679610FA for ; Wed, 18 Aug 2021 18:57:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 72679610FA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:51012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGQkK-0007Lj-JT for qemu-devel@archiver.kernel.org; Wed, 18 Aug 2021 14:57:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGQis-0006UM-4t for qemu-devel@nongnu.org; Wed, 18 Aug 2021 14:55:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGQin-00009Q-U5 for qemu-devel@nongnu.org; Wed, 18 Aug 2021 14:55:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629312929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pj4iTPZVamEI75jloPNb8vAfkXqLrne3yC3yQcevdbw=; b=Lfkly2BiSMgG29ovmjGPOYG6NHZEBmy0XVZyW50mfeZ9f1gAdS8EReuPFbXtqLqki0ZNrO qSb34Az4h7hMaF7EMfSeDCXEDYAyVbeIdGFrBNGitvQMglLqYWJ4gwjjK78Nj7pROvAyVL eVt/JpW6KIKrPGc7wc67VDHmrlLgjqA= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-543-Z7YC4rRKOIOi4bw0oXeWLQ-1; Wed, 18 Aug 2021 14:55:25 -0400 X-MC-Unique: Z7YC4rRKOIOi4bw0oXeWLQ-1 Received: by mail-oi1-f199.google.com with SMTP id c6-20020aca35060000b029025c5504f461so1405129oia.22 for ; Wed, 18 Aug 2021 11:55:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pj4iTPZVamEI75jloPNb8vAfkXqLrne3yC3yQcevdbw=; b=tF0AxyqOB7tmdxYOqDUPvFeHwCaSCl2zROxjXQa0r/X+4AK/q4w2IFOVcGG7m3xUl5 o6ObOZRwagPcfu7zHloqbFxmXTTkgNKG++LLHb9Waee8tVPLekE5OtMt9TkSGHpE70ed Ljy2pclCoTjbSwsLwf3CQm+0+zg145kAEHFVh1Aih+iAs22Cqac79lQPZzsMp/LIZN/p 1FqfC1SMaOW8nlYli+L1gqA0sNOc+EDEs/ZSERpAhMQvgkWEdxjOt7LL13AIzQGUmpu8 EYopjrfRdJGQzMMNxGV5fij3r1pZdbIqmeNw3gCrjEkWQhx0WRVcligKMC2xq+MhumB6 n6Uw== X-Gm-Message-State: AOAM530WdtAQrNYaozl5C3910Dyt6WRJk/ksXVVVitBV4TV3BYHS7kCd oBE5pYtLCyPzkGvMK9a08oIsaS9NQNDW1d/jXM/XiMPjW1L9VfewG5otoPiUBvLml7BYhGqEKYx Md8UQUQuQTXGBtUWj+JRCOcbWT3Wi8iE= X-Received: by 2002:a05:6808:f94:: with SMTP id o20mr8001860oiw.112.1629312924650; Wed, 18 Aug 2021 11:55:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIAMmzy+R+RLQhwP2D0Mju2tRq7S7oyvX96nfwjq5uK28ty3voxj4x/KNwnbSYLv376sVs3v/OO89icz50edw= X-Received: by 2002:a05:6808:f94:: with SMTP id o20mr8001838oiw.112.1629312924428; Wed, 18 Aug 2021 11:55:24 -0700 (PDT) MIME-Version: 1.0 References: <20210730201846.5147-1-niteesh.gs@gmail.com> <20210730201846.5147-9-niteesh.gs@gmail.com> In-Reply-To: From: John Snow Date: Wed, 18 Aug 2021 14:55:13 -0400 Message-ID: Subject: Re: [PATCH v3 08/13] python/aqmp-tui: add syntax highlighting To: "Niteesh G. S." Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="00000000000016c46905c9d9fa39" Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Kashyap Chamarthy , Markus Armbruster , Wainer Moschetta , qemu-devel , Stefan Hajnoczi , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --00000000000016c46905c9d9fa39 Content-Type: text/plain; charset="UTF-8" On Mon, Aug 16, 2021 at 5:20 PM Niteesh G. S. wrote: > > > On Tue, Aug 17, 2021 at 1:14 AM John Snow wrote: > >> >> >> On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu >> wrote: >> >>> 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 >>> --- >>> python/qemu/aqmp/aqmp_tui.py | 52 +++++++++++++++++++++++++++--------- >>> 1 file changed, 40 insertions(+), 12 deletions(-) >>> >>> diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py >>> index ab9ada793a..0d5ec62cb7 100644 >>> --- a/python/qemu/aqmp/aqmp_tui.py >>> +++ b/python/qemu/aqmp/aqmp_tui.py >>> @@ -19,6 +19,8 @@ >>> Union, >>> ) >>> >>> +from pygments import lexers >>> +from pygments import token as Token >>> import urwid >>> import urwid_readline >>> >>> @@ -35,6 +37,22 @@ >>> LOGGER = logging.getLogger() >>> >>> >>> +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: >>> """ >>> Formats given multiline JSON message into a single line message. >>> @@ -57,17 +75,14 @@ def __init__(self, address: Union[str, Tuple[str, >>> int]]) -> None: >>> self.aloop: Optional[Any] = None # FIXME: Use more concrete >>> type. >>> super().__init__() >>> >>> - def add_to_history(self, msg: str) -> None: >>> - urwid.emit_signal(self, UPDATE_MSG, msg) >>> + def add_to_history(self, msg: str, level: Optional[str] = None) -> >>> None: >>> + urwid.emit_signal(self, UPDATE_MSG, msg, level) >>> >>> def _cb_outbound(self, msg: Message) -> Message: >>> # FIXME: I think the ideal way to omit these messages during >>> in-TUI >>> - # logging will be to add a filter to the logger. We can use >>> regex to >>> - # filter out messages starting with 'Request:' or 'Response:' >>> but I >>> - # think a better approach will be encapsulate the message in an >>> object >>> - # and filter based on the object. Encapsulation of the message >>> will >>> - # also be necessary when we want different formatting of >>> messages >>> - # inside TUI. >>> + # logging will be to add a filter to the logger. We can use >>> + # regex/startswith to filter out messages starting with >>> 'Request:' or >>> + # 'Response:'. If possible please suggest other ideas. >>> >> >> We'll want to fix this up earlier in the series -- the finished version >> of your series shouldn't have FIXME comments, and later patches in the >> series shouldn't edit comments added earlier. We chatted on IRC about the >> right strategy for filtering log messages, so I think V4 should have a >> strategy in place to avoid this comment, right? >> > Yes, this has been addressed in the v4. > We avoid logging messages when we log the messages to the TUI screen. This > is done by checking if TUILogHandler is installed on the logger or not. > >> >> >>> handler = LOGGER.handlers[0] >>> if not isinstance(handler, TUILogHandler): >>> LOGGER.debug('Request: %s', str(msg)) >>> @@ -156,6 +171,9 @@ def _get_formatted_address(self) -> str: >>> self._set_status('Server shutdown') >>> >>> def run(self, debug: bool = False) -> None: >>> + screen = urwid.raw_display.Screen() >>> + screen.set_terminal_properties(256) >>> >> >> I'm not sure if this will work everywhere, but ... it's fine for now, I >> assume. >> > I'll add a note here. > >> + >>> self.aloop = asyncio.get_event_loop() >>> self.aloop.set_debug(debug) >>> >>> @@ -167,6 +185,8 @@ def run(self, debug: bool = False) -> None: >>> event_loop = urwid.AsyncioEventLoop(loop=self.aloop) >>> main_loop = urwid.MainLoop(urwid.AttrMap(self.window, >>> 'background'), >>> unhandled_input=self.unhandled_input, >>> + screen=screen, >>> + palette=palette, >>> handle_mouse=True, >>> event_loop=event_loop) >>> >>> @@ -251,7 +271,8 @@ def __init__(self, master: App) -> None: >>> self.history = urwid.SimpleFocusListWalker([]) >>> 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: >>> self.history.append(urwid.Text(history)) >>> if self.history: >>> self.history.set_focus(len(self.history) - 1) >>> @@ -271,8 +292,15 @@ def __init__(self, master: App) -> None: >>> super().__init__(self.body) >>> urwid.connect_signal(self.master, UPDATE_MSG, >>> self.cb_add_to_history) >>> >>> - def cb_add_to_history(self, msg: str) -> None: >>> - self.history.add_to_history(msg) >>> + def cb_add_to_history(self, msg: str, level: Optional[str] = None) >>> -> None: >>> + formatted = [] >>> + if level: >>> + 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) >>> >> >> This looks like it's conflating having a debugging level with receiving a >> message that's already formatted. >> >> i.e., the code here assumes that if it receives a level, it is ALSO >> already formatted. That smells like trouble -- but I think there are some >> changes to the logging and rendering you had planned for V4 anyway, I >> believe? >> > Why do you think it is trouble? > When a level is provided, it is most probably going to be text messages or > QMP messages with text. In either case, there is no formatting to be done. > In the second case, we don't have a JSON formattor that can format > a JSON message along with text without breaking. So I thought it is better > to leave the formatting to the user and just use the level to provide > syntax highlighting. > > Because it's an indirect type inference -- you are *indirectly* measuring whether or not a message has been formatted yet. Using the presence or absence of 'level' is an indirect way of proving the condition; are there not more direct ways? Talking on IRC, I see that you have plans for an abstracted Item view that might make this a null point, though -- so I'll drop this line of interrogation for now. Thanks! --00000000000016c46905c9d9fa39 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Aug 16, 2021 at 5:20 PM Nitee= sh G. S. <niteesh.gs@gmail.com> wrote:



On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu <niteesh.gs@gmail.com> wrote:
Add syntax highli= ghting 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>
---
=C2=A0python/qemu/aqmp/aqmp_tui.py | 52 +++++++++++++++++++++++++++--------= -
=C2=A01 file changed, 40 insertions(+), 12 deletions(-)

diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py index ab9ada793a..0d5ec62cb7 100644
--- a/python/qemu/aqmp/aqmp_tui.py
+++ b/python/qemu/aqmp/aqmp_tui.py
@@ -19,6 +19,8 @@
=C2=A0 =C2=A0 =C2=A0Union,
=C2=A0)

+from pygments import lexers
+from pygments import token as Token
=C2=A0import urwid
=C2=A0import urwid_readline

@@ -35,6 +37,22 @@
=C2=A0LOGGER =3D logging.getLogger()


+palette =3D [
+=C2=A0 =C2=A0 (Token.Punctuation, '', '', '', '= ;h15,bold', 'g7'),
+=C2=A0 =C2=A0 (Token.Text, '', '', '', '',= 'g7'),
+=C2=A0 =C2=A0 (Token.Name.Tag, '', '', '', 'bo= ld,#f88', 'g7'),
+=C2=A0 =C2=A0 (Token.Literal.Number.Integer, '', '', '= ', '#fa0', 'g7'),
+=C2=A0 =C2=A0 (Token.Literal.String.Double, '', '', '&= #39;, '#6f6', 'g7'),
+=C2=A0 =C2=A0 (Token.Keyword.Constant, '', '', '',= '#6af', 'g7'),
+=C2=A0 =C2=A0 ('DEBUG', '', '', '', '#= ddf', 'g7'),
+=C2=A0 =C2=A0 ('INFO', '', '', '', 'g1= 00', 'g7'),
+=C2=A0 =C2=A0 ('WARNING', '', '', '', '= ;#ff6', 'g7'),
+=C2=A0 =C2=A0 ('ERROR', '', '', '', '#= a00', 'g7'),
+=C2=A0 =C2=A0 ('CRITICAL', '', '', '', = 9;#a00', 'g7'),
+=C2=A0 =C2=A0 ('background', '', 'black', '= 9;, '', 'g7'),
+]
+
+
=C2=A0def format_json(msg: str) -> str:
=C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0Formats given multiline JSON message into a single line= message.
@@ -57,17 +75,14 @@ def __init__(self, address: Union[str, Tuple[str, int]]= ) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.aloop: Optional[Any] =3D None=C2=A0 = # FIXME: Use more concrete type.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__()

-=C2=A0 =C2=A0 def add_to_history(self, msg: str) -> None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 urwid.emit_signal(self, UPDATE_MSG, msg)
+=C2=A0 =C2=A0 def add_to_history(self, msg: str, level: Optional[str] =3D = None) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 urwid.emit_signal(self, UPDATE_MSG, msg, level= )

=C2=A0 =C2=A0 =C2=A0def _cb_outbound(self, msg: Message) -> Message:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# FIXME: I think the ideal way to omit th= ese messages during in-TUI
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # logging will be to add a filter to the logge= r. We can use regex to
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # filter out messages starting with 'Reque= st:' or 'Response:' but I
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # think a better approach will be encapsulate = the message in an object
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # and filter based on the object. Encapsulatio= n of the message will
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # also be necessary when we want different for= matting of messages
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # inside TUI.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # logging will be to add a filter to the logge= r. We can use
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # regex/startswith to filter out messages star= ting with 'Request:' or
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # 'Response:'. If possible please sugg= est other ideas.

We'll want to fix = this up earlier in the series -- the finished version of your series should= n't have FIXME comments, and later patches in the series shouldn't = edit comments added earlier. We chatted on IRC about the right strategy for= filtering log messages, so I think V4 should have a strategy in place to a= void this comment, right?
Yes, this has been addressed = in the v4.
We avoid logging messages when we log the messages to the TUI scre= en. This is done by checking if TUILogHandler is installed on the logger or= not.
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0handler =3D LOGGER.handlers[0]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if not isinstance(handler, TUILogHandler)= :
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LOGGER.debug('Request: = %s', str(msg))
@@ -156,6 +171,9 @@ def _get_formatted_address(self) -> str:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._set_status('Serve= r shutdown')

=C2=A0 =C2=A0 =C2=A0def run(self, debug: bool =3D False) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 screen =3D urwid.raw_display.Screen()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 screen.set_terminal_properties(256)

I'm not sure if this will work everywhere, bu= t ... it's fine for now, I assume.
<= span class=3D"gmail_default" style=3D"font-size:small">I'll add a note = here.=C2=A0
<= div dir=3D"ltr">
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.aloop =3D asyncio.get_event_loop() =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.aloop.set_debug(debug)

@@ -167,6 +185,8 @@ def run(self, debug: bool =3D False) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0event_loop =3D urwid.AsyncioEventLoop(loo= p=3Dself.aloop)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0main_loop =3D urwid.MainLoop(urwid.AttrMa= p(self.window, 'background'),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 unhandled_input=3Dself= .unhandled_input,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0screen=3Dscreen,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0palette=3Dpalette,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 handle_mouse=3DTrue, =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 event_loop=3Devent_loo= p)

@@ -251,7 +271,8 @@ def __init__(self, master: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.history =3D urwid.SimpleFocusListWal= ker([])
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(self.history)

-=C2=A0 =C2=A0 def add_to_history(self, history: str) -> None:
+=C2=A0 =C2=A0 def add_to_history(self,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0history: Union[str, List[Tuple[str, str]]]) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.history.append(urwid.Text(history))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if self.history:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.history.set_focus(len(= self.history) - 1)
@@ -271,8 +292,15 @@ def __init__(self, master: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(self.body)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0urwid.connect_signal(self.master, UPDATE_= MSG, self.cb_add_to_history)

-=C2=A0 =C2=A0 def cb_add_to_history(self, msg: str) -> None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.history.add_to_history(msg)
+=C2=A0 =C2=A0 def cb_add_to_history(self, msg: str, level: Optional[str] = =3D None) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 formatted =3D []
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if level:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 formatted.append((level, msg)) +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 lexer =3D lexers.JsonLexer()=C2= =A0 # pylint: disable=3Dno-member
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for token in lexer.get_tokens(ms= g):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 formatted.append(t= oken)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.history.add_to_history(formatted)

This looks like it's conflating having a d= ebugging level with receiving a message that's already formatted.
=

i.e., the code here assumes that if it receives a level= , it is ALSO already formatted. That smells like trouble -- but I think the= re are some changes to the logging and rendering you had planned for V4 any= way, I believe?
Why do you think it is=C2=A0trouble?
When a level is provided, it is most probably going to be text message= s or QMP messages with text. In either case, there is no formatting to be d= one. In the second case, we don't have a JSON formattor that can format=
a JSON message along with text without= breaking. So I thought it is better to leave the formatting to the user an= d just use the level to provide syntax highlighting.


Because it's an indirect type inference -- you are *indirectly* measur= ing whether or not a message has been formatted yet. Using the presence or = absence of 'level' is an indirect way of proving the condition; are= there not more direct ways?

Talking on IRC, I see= that you have plans for an abstracted Item view that might make this a nul= l point, though -- so I'll drop this line of interrogation for now.

Thanks!
--00000000000016c46905c9d9fa39--