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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 03F4AC4338F for ; Fri, 30 Jul 2021 20:25:01 +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 BE84560E09 for ; Fri, 30 Jul 2021 20:25:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BE84560E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:47134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9Z3z-0002Zu-Q3 for qemu-devel@archiver.kernel.org; Fri, 30 Jul 2021 16:24:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9Yyo-0005oO-OB for qemu-devel@nongnu.org; Fri, 30 Jul 2021 16:19:39 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:43629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m9Yyn-00017l-3j for qemu-devel@nongnu.org; Fri, 30 Jul 2021 16:19:38 -0400 Received: by mail-pj1-x102f.google.com with SMTP id pj14-20020a17090b4f4eb029017786cf98f9so5386831pjb.2 for ; Fri, 30 Jul 2021 13:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4KZ0HzG+B9+mKhjGsq5d786iXcrEj0YCq/8pG6bXXhM=; b=LSvJoPc3F/6GdhImMoPMULwzxA9ZjJktB6VK/VwTTMa+MMQY1w5PpeLa3u8reoT0F1 NmH22XETOaYY1A5+b9upKawuR84JMLsI0fvgHxcbARNIA8FFBIK0Z3W/+MiLNzxtA3s+ v9Id5epyO9+ceWw/gUsHIQZKOe6Nct3YIvOOYJMZRV43FnHdK+4F2Qq1Y7vhID6HhiMN EG1sTgwzonBNOKYzBufPggO4vVMdwP55yJChTdnCqGLwzWrcE4AvZ+GfuTvY+hPL4JsF PVarvTiYQsrQZrfb0NX1H1NISJS6KXolj4S6IPpKQ9DfeHkaPbjQd5aClvqkVQOpj0+5 Rc3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4KZ0HzG+B9+mKhjGsq5d786iXcrEj0YCq/8pG6bXXhM=; b=caS6eSjl8XyCkQBcuhDVnVfwAzQnDgyqudUIE/wk20ZLhZLlkM/WW7705Su6MDXUmt ZGsSgPXe+qeT1K+gYbnH7Dye+DLcRX8q7gE+G3V03l2ZUtkwFoeRO7bDZhp3pkPXbPeI CVWomg5Av/Doa4G0pwU2jVO5EziT72MNuSAtP6ceQkRQBMQ6JAkL+92pYg/L0Z4lRIXk 0n7RAHINO7JRey8BTTI8angJDy0ByKNpD3T8anu6LAQRUXNfUxFTxY+GomQt9uhhO0J8 cLbVbp/wA+b/vZLee8S2Z1scYvfjQSprPMvUWYrTQB30nkgXTYHWEBgdHhp+qeUit0XE Na3g== X-Gm-Message-State: AOAM531Kxx6wtuUncJ2TEwynpC8XqZEsBCmAF1vwwrVNeAnooA3B/cfP 5rvwJEGMaFfH90B+1KdYojuZgVpNZZIHPw== X-Google-Smtp-Source: ABdhPJyTfLpfinEvXIJ7cwLyBEEDRCKzuOeafixbUN3CnmGEQ1RIBRdvd5F90ecA8ORfjmc+kvftbg== X-Received: by 2002:a05:6a00:1756:b029:340:d051:518b with SMTP id j22-20020a056a001756b0290340d051518bmr4236316pfc.25.1627676375683; Fri, 30 Jul 2021 13:19:35 -0700 (PDT) Received: from localhost.localdomain ([120.138.12.243]) by smtp.gmail.com with ESMTPSA id s50sm3256842pfw.212.2021.07.30.13.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jul 2021 13:19:35 -0700 (PDT) From: G S Niteesh Babu To: qemu-devel@nongnu.org Subject: [PATCH v3 11/13] python/aqmp-tui: Add ability to highlight messages Date: Sat, 31 Jul 2021 01:48:44 +0530 Message-Id: <20210730201846.5147-12-niteesh.gs@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210730201846.5147-1-niteesh.gs@gmail.com> References: <20210730201846.5147-1-niteesh.gs@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=niteesh.gs@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: ehabkost@redhat.com, kchamart@redhat.com, jsnow@redhat.com, armbru@redhat.com, wainersm@redhat.com, G S Niteesh Babu , stefanha@redhat.com, crosa@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Adds ability to highlight messages in the history box. The messages can be selected using up/down arrow keys. This can be enhanced in the future to apply specific settings to a particular message. Signed-off-by: G S Niteesh Babu --- python/qemu/aqmp/aqmp_tui.py | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py index fb828b1a27..4bae0d4e89 100644 --- a/python/qemu/aqmp/aqmp_tui.py +++ b/python/qemu/aqmp/aqmp_tui.py @@ -344,6 +344,7 @@ def __init__(self, master: App) -> None: self.master = master self.history = urwid.SimpleFocusListWalker([]) super().__init__(self.history) + self.highlighting = -1 def add_to_history(self, history: Union[str, List[Tuple[str, str]]]) -> None: @@ -351,8 +352,57 @@ def add_to_history(self, if self.history: self.history.set_focus(len(self.history) - 1) + def _remove_highlighting(self) -> None: + assert self.highlighting != -1 + pos = self.highlighting + widget = self.history[pos] + widget = widget.original_widget + self.history[pos] = widget + + def _update_highlighting(self) -> None: + assert self.highlighting != -1 + pos = self.highlighting + widget = self.history[pos] + self.history[pos] = urwid.LineBox(widget) + + def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]: + if key == 'up': + if self.highlighting != -1: + pos = self.highlighting + self._remove_highlighting() + pos = max(pos - 1, 0) + self.highlighting = pos + else: + self.highlighting = len(self.history) - 1 + self._update_highlighting() + self.change_focus(size, self.highlighting) + return None + if key == 'down': + pos = self.highlighting + if pos == -1: + return None + + self._remove_highlighting() + if pos == len(self.history) - 1: + self.highlighting = -1 + else: + self.highlighting = pos + 1 + self._update_highlighting() + self.change_focus(size, self.highlighting) + return None + + # Remove highlighting if someother key is pressed + if self.highlighting != -1: + self._remove_highlighting() + self.highlighting = -1 + return super().keypress(size, key) # type: ignore + def mouse_event(self, size: Tuple[int, int], _event: str, button: float, _x: int, _y: int, focus: bool) -> None: + if self.highlighting != -1: + self._remove_highlighting() + self.highlighting = -1 + # Scroll only on focus. Therefore it is required to # click on the widget to enable scrolling. if not focus: -- 2.17.1