浏览代码

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 13 年前
父节点
当前提交
6e9d22e205
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5
    2
      cdiff.py

+ 5
- 2
cdiff.py 查看文件

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()