Jérôme Berger avatar Jérôme Berger committed 164a4a7 Merge

Merged revisions 32df99b740bc and 5618ae4accb4.

Comments (0)

Files changed (1)

crecord/chunk_selector.py

 import os
 import re
 import sys
-import fcntl
 import struct
-import termios
 import signal
 import textwrap
 
 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
+
+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()
 
 try:
     curses
 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, ui):
     """
         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()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.