浏览代码

Merge pull request #11 from myint/sigint

Handle keyboard interrupt gracefully
Matthew Wang 11 年前
父节点
当前提交
e0a0d7a152
共有 1 个文件被更改,包括 8 次插入5 次删除
  1. 8
    5
      cdiff.py

+ 8
- 5
cdiff.py 查看文件

@@ -536,8 +536,11 @@ def markup_to_pager(stream, opts):
536 536
     # args stolen fron git source: github.com/git/git/blob/master/pager.c
537 537
     pager = subprocess.Popen(['less', '-FRSX'],
538 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 545
     pager.stdin.close()
543 546
     pager.wait()
@@ -600,8 +603,7 @@ def main():
600 603
         diff_hdl = revision_control_log()
601 604
         if not diff_hdl:
602 605
             sys.stderr.write(('*** Not in a supported workspace, supported '
603
-                              'are: %s\n\n') % ', '.join(supported_vcs))
604
-            parser.print_help()
606
+                              'are: %s\n') % ', '.join(supported_vcs))
605 607
             return 1
606 608
     elif len(args) > 2:
607 609
         parser.print_help()
@@ -640,7 +642,8 @@ def main():
640 642
                 pass
641 643
     else:
642 644
         # pipe out stream untouched to make sure it is still a patch
643
-        sys.stdout.write(''.join(stream))
645
+        for line in stream:
646
+            sys.stdout.write(decode(line))
644 647
 
645 648
     if diff_hdl is not sys.stdin:
646 649
         diff_hdl.close()