Browse Source

Gracefully handle keyboard interrupt

Previously, a keyboard interrupt would result in a corrupted terminal.
This would manifest when doing "cdiff --log" on somewhat large
repositories.
Steven Myint 11 years ago
parent
commit
6e9d22e205
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      cdiff.py

+ 5
- 2
cdiff.py View File

536
     # args stolen fron git source: github.com/git/git/blob/master/pager.c
536
     # args stolen fron git source: github.com/git/git/blob/master/pager.c
537
     pager = subprocess.Popen(['less', '-FRSX'],
537
     pager = subprocess.Popen(['less', '-FRSX'],
538
             stdin=subprocess.PIPE, stdout=sys.stdout)
538
             stdin=subprocess.PIPE, stdout=sys.stdout)
539
-    for line in color_diff:
540
-        pager.stdin.write(line.encode('utf-8'))
539
+    try:
540
+        for line in color_diff:
541
+            pager.stdin.write(line.encode('utf-8'))
542
+    except KeyboardInterrupt:
543
+        pass
541
 
544
 
542
     pager.stdin.close()
545
     pager.stdin.close()
543
     pager.wait()
546
     pager.wait()