Commits

Jérôme Berger  committed 32df99b Merge

Merged revisions 4af10dce21e0 and 2f46fc3bca18.

  • Participants
  • Parent commits 4af10dc, 2f46fc3

Comments (0)

Files changed (1)

File crecord/chunk_selector.py

 import os
 import re
 import sys
-import fcntl
 import struct
-import termios
 import signal
 
 from crpatch import Patch, header, hunk, HunkLine
 
 # os.name is one of: 'posix', 'nt', 'dos', 'os2', 'mac', or 'ce'
-if os.name == 'posix':
-    import curses
-else:
-    # I have no idea if wcurses works with crecord...
-    import wcurses as curses
+import curses
 
-#from curses import textpad
+try:
+    import fcntl
+    import termios
+    def gethw():
+        """
+        Magically get the current height and width of the window
+        (without initscr)
+
+        This is a rip-off of a rip-off - taken from the bpython code.
+        It is useful / necessary because otherwise curses.initscr()
+        must be called, which can leave the terminal in a nasty state
+        after exiting.
+
+        """
+        h, w = struct.unpack(
+            "hhhh", fcntl.ioctl(orig_stdout, termios.TIOCGWINSZ, "\000"*8))[0:2]
+        return h, w
+
+except ImportError:
+    def gethw():
+        return curses.initscr().getmaxyx()
+
+#from curses import textpad 
 import textpad # customized textpad
 
 try:
 except NameError:
     raise util.Abort(
         _('the python curses/wcurses module is not available/installed'))
-
+    
 
 orig_stdout = sys.__stdout__ # used by gethw()
 
-def gethw():
-    """
-    Magically get the current height and width of the window (without initscr)
-
-    This is a rip-off of a rip-off - taken from the bpython code.  It is
-    useful / necessary because otherwise curses.initscr() must be called,
-    which can leave the terminal in a nasty state after exiting.
-
-    """
-    h, w = struct.unpack(
-        "hhhh", fcntl.ioctl(orig_stdout, termios.TIOCGWINSZ, "\000"*8))[0:2]
-    return h, w
-
 
 def chunkselector(opts, headerList):
     """
         if selected:
             colorPair = self.getColorPair(name="selected")
         elif lineStr.startswith("+"):
-            colorPair = self.getColorPair(name="addition")
+            colorPair = self.getColorPair(name="addition", attrList = [ curses.A_BOLD ])
         elif lineStr.startswith("-"):
-            colorPair = self.getColorPair(name="deletion")
+            colorPair = self.getColorPair(name="deletion", attrList = [ curses.A_BOLD ])
         elif lineStr.startswith("\\"):
             colorPair = self.getColorPair(name="normal")
 
         Method to be wrapped by curses.wrapper() for selecting chunks.
 
         """
-        signal.signal(signal.SIGWINCH, self.sigwinchHandler)
+        try:
+            signal.signal(signal.SIGWINCH, self.sigwinchHandler)
+        except Exception:
+            pass
         self.stdscr = stdscr
         self.yScreenSize, self.xScreenSize = self.stdscr.getmaxyx()