Просмотр исходного кода

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 лет назад
Родитель
Сommit
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()