ia64/xen-unstable

changeset 18381:9e276d5f3c58

PyGRUB: fix menu flicker

To avoid flickers, PyGRUB has to avoid spurious ncurses refresh as
much as possible, in particular before the complete screen is drawn,
and eventually call doupdate last.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 27 09:46:38 2008 +0100 (2008-08-27)
parents 2708ad934551
children fa98f03a6bcd
files tools/pygrub/src/pygrub
line diff
     1.1 --- a/tools/pygrub/src/pygrub	Wed Aug 27 09:46:22 2008 +0100
     1.2 +++ b/tools/pygrub/src/pygrub	Wed Aug 27 09:46:38 2008 +0100
     1.3 @@ -124,7 +124,7 @@ def get_fs_offset(file):
     1.4  class GrubLineEditor(curses.textpad.Textbox):
     1.5      def __init__(self, screen, startx, starty, line = ""):
     1.6          screen.addstr(startx, starty, "> ")
     1.7 -        screen.refresh()
     1.8 +        screen.noutrefresh()
     1.9          win = curses.newwin(1, 74, startx, starty + 2)
    1.10          curses.textpad.Textbox.__init__(self, win)
    1.11          
    1.12 @@ -137,7 +137,7 @@ class GrubLineEditor(curses.textpad.Text
    1.13          """Show the text.  One of our advantages over standard textboxes
    1.14          is that we can handle lines longer than the window."""
    1.15  
    1.16 -        self.win.clear()
    1.17 +        self.win.erase()
    1.18          p = self.pos
    1.19          off = 0
    1.20          while p > 70:
    1.21 @@ -188,6 +188,7 @@ class GrubLineEditor(curses.textpad.Text
    1.22          return 1
    1.23  
    1.24      def edit(self):
    1.25 +        curses.doupdate()
    1.26          r = curses.textpad.Textbox.edit(self)
    1.27          if self.cancelled:
    1.28              return None
    1.29 @@ -217,16 +218,15 @@ class Grub:
    1.30              curses.def_prog_mode()
    1.31          
    1.32          curses.reset_prog_mode()
    1.33 -        self.screen.clear()
    1.34 -        self.screen.refresh()
    1.35 +        self.screen.erase()
    1.36  
    1.37          # create basic grub screen with a box of entries and a textbox
    1.38          self.screen.addstr(1, 4, "pyGRUB  version %s" %(PYGRUB_VER,))
    1.39          self.entry_win.box()
    1.40 -        self.screen.refresh()
    1.41 +        self.screen.noutrefresh()
    1.42  
    1.43      def fill_entry_list(self):
    1.44 -        self.entry_win.clear()
    1.45 +        self.entry_win.erase()
    1.46          self.entry_win.box()
    1.47  
    1.48          maxy = self.entry_win.getmaxyx()[0]-3 # maxy - 2 for the frame + index
    1.49 @@ -244,7 +244,7 @@ class Grub:
    1.50              self.entry_win.addstr(y + 1 - self.start_image, 2, i.title.ljust(70))
    1.51              if y == self.selected_image:
    1.52                  self.entry_win.attroff(curses.A_REVERSE)
    1.53 -        self.entry_win.refresh()
    1.54 +        self.entry_win.noutrefresh()
    1.55  
    1.56      def edit_entry(self, origimg):
    1.57          def draw():
    1.58 @@ -259,13 +259,13 @@ class Grub:
    1.59              self.text_win.addch(0, 14, curses.ACS_DARROW)
    1.60              (y, x) = self.text_win.getmaxyx()
    1.61              self.text_win.move(y - 1, x - 1)
    1.62 -            self.text_win.refresh()
    1.63 +            self.text_win.noutrefresh()
    1.64  
    1.65          curline = 1
    1.66          img = copy.deepcopy(origimg)
    1.67          while 1:
    1.68              draw()
    1.69 -            self.entry_win.clear()
    1.70 +            self.entry_win.erase()
    1.71              self.entry_win.box()
    1.72              for idx in range(1, len(img.lines)):
    1.73                  # current line should be highlighted
    1.74 @@ -280,7 +280,8 @@ class Grub:
    1.75                  self.entry_win.addstr(idx, 2, l)
    1.76                  if idx == curline:
    1.77                      self.entry_win.attroff(curses.A_REVERSE)
    1.78 -            self.entry_win.refresh()
    1.79 +            self.entry_win.noutrefresh()
    1.80 +            curses.doupdate()
    1.81  
    1.82              c = self.screen.getch()
    1.83              if c in (ord('q'), 27): # 27 == esc
    1.84 @@ -318,10 +319,10 @@ class Grub:
    1.85              origimg.reset(img.lines)
    1.86  
    1.87      def edit_line(self, line):
    1.88 -        self.screen.clear()
    1.89 +        self.screen.erase()
    1.90          self.screen.addstr(1, 2, "[ Minimal BASH-like line editing is supported.  ")
    1.91          self.screen.addstr(2, 2, "  ESC at any time cancels.  ENTER at any time accepts your changes. ]")
    1.92 -        self.screen.refresh()
    1.93 +        self.screen.noutrefresh()
    1.94  
    1.95          t = GrubLineEditor(self.screen, 5, 2, line)
    1.96          enable_cursor(True)
    1.97 @@ -331,10 +332,10 @@ class Grub:
    1.98          return None
    1.99  
   1.100      def command_line_mode(self):
   1.101 -        self.screen.clear()
   1.102 +        self.screen.erase()
   1.103          self.screen.addstr(1, 2, "[ Minimal BASH-like line editing is supported.  ESC at any time ")
   1.104          self.screen.addstr(2, 2, "  exits.  Typing 'boot' will boot with your entered commands. ] ")
   1.105 -        self.screen.refresh()
   1.106 +        self.screen.noutrefresh()
   1.107  
   1.108          y = 5
   1.109          lines = []
   1.110 @@ -420,7 +421,7 @@ class Grub:
   1.111              self.text_win.addch(0, 14, curses.ACS_DARROW)
   1.112              (y, x) = self.text_win.getmaxyx()
   1.113              self.text_win.move(y - 1, x - 1)
   1.114 -            self.text_win.refresh()
   1.115 +            self.text_win.noutrefresh()
   1.116  
   1.117          # now loop until we hit the timeout or get a go from the user
   1.118          mytime = 0
   1.119 @@ -433,6 +434,7 @@ class Grub:
   1.120              else:
   1.121                  self.screen.addstr(20, 5, " " * 80)
   1.122              self.fill_entry_list()
   1.123 +            curses.doupdate()
   1.124  
   1.125              c = self.screen.getch()
   1.126              if c == -1: