From c0284b69fe0ee82d1f604a1b6f0511b4f129b919 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 19 Aug 2011 00:05:22 -0600 Subject: Support thread cancelation, and handle ^C in the client. --- dimension/dimension.in | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'dimension') diff --git a/dimension/dimension.in b/dimension/dimension.in index 01dc2f3..f0db4fc 100644 --- a/dimension/dimension.in +++ b/dimension/dimension.in @@ -111,21 +111,33 @@ from dimension import * # Display a progress bar def _progress_bar(str, progress): - if not _args.quiet: - print(str, end = ' ') - _sys.stdout.flush() + try: + if not _args.quiet: + print(str, end = ' ') + _sys.stdout.flush() + + term_width = terminal_width() + width = term_width - (len(str) + 1)%term_width + for i in range(width): + progress.wait((i + 1)/width) + print('.', end = '') + _sys.stdout.flush() - term_width = terminal_width() - width = term_width - (len(str) + 1)%term_width - for i in range(width): - progress.wait((i + 1)/width) - print('.', end = '') + print() _sys.stdout.flush() + progress.finish() + except KeyboardInterrupt: print() _sys.stdout.flush() - progress.finish() + progress.cancel() + try: + progress.finish() + except: + # Swallow the failure exception + pass + raise # --strict option die_on_warnings(_args.strict) -- cgit v1.2.3