From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHCg6-0001nu-Ik for qemu-devel@nongnu.org; Thu, 07 Jan 2016 10:40:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHCg2-0002yn-Ir for qemu-devel@nongnu.org; Thu, 07 Jan 2016 10:40:42 -0500 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:38277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHCg2-0002yj-CE for qemu-devel@nongnu.org; Thu, 07 Jan 2016 10:40:38 -0500 Received: by mail-wm0-x22e.google.com with SMTP id b14so129544148wmb.1 for ; Thu, 07 Jan 2016 07:40:38 -0800 (PST) Sender: Paolo Bonzini References: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> <1449749584-23214-28-git-send-email-frankja@linux.vnet.ibm.com> From: Paolo Bonzini Message-ID: <568E86F3.1020109@redhat.com> Date: Thu, 7 Jan 2016 16:40:35 +0100 MIME-Version: 1.0 In-Reply-To: <1449749584-23214-28-git-send-email-frankja@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 27/34] scripts/kvm/kvm_stat: Make tui function a class List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Janosch Frank , qemu-devel@nongnu.org Cc: cornelia.huck@de.ibm.com On 10/12/2015 13:12, Janosch Frank wrote: > + > +def tui(screen, stats): > + interface = Tui(screen, stats) > + interface.show_stats() > I think it would make sense to "reimplement" curses.wrapper as __enter__/__exit__ methods in Tui(), and then use with here. It's really just a bunch of curses calls: self.stdscr = curses.initscr() curses.noecho() curses.cbreak() # Start color, too. Harmless if the terminal doesn't have # color; user can test with has_color() later on. The try/catch # works around a minor bit of over-conscientiousness in the curses # module -- the error return from C start_color() is ignorable. try: curses.start_color() except: pass curses.use_default_colors() --- # Set everything back to normal if self.stdscr: self.stdscr.keypad(0) curses.echo() curses.nocbreak() curses.endwin() where the existing calls to curses.use_default_colors and curses.noecho can then be removed. Paolo