-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fb5c8bb
Showing
75 changed files
with
3,712 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import time | ||
import curses | ||
|
||
# Get width of terminal | ||
# I couldn't be bothered to get newline mode working properly when curses is active, | ||
# so I uses curses.wrapper() do init curses, get the width, then close curses. | ||
def get_width (scr): | ||
global _width; | ||
_width = scr.getmaxyx()[1] - 1; | ||
curses.wrapper(get_width); | ||
|
||
def timestamp (time_start,format="%H:%M:%S:"): | ||
return time.strftime(format,time.gmtime(time.time()-time_start)); | ||
|
||
class Reporter (object): | ||
"""A Reporter is used to make progress reports on the console, with optional timestamps.""" | ||
def __init__ (self,timestamp=False): | ||
self.time_start = timestamp and time.time(); | ||
|
||
def overprint (self,message): | ||
return self.pprint(message+"\r"); | ||
|
||
def pprint (self,message,newline=True): | ||
# print message | ||
if self.time_start: | ||
message = "%s %s"%(timestamp(self.time_start),message); | ||
if message[-1] == "\r": | ||
endline = "\r"; | ||
else: | ||
endline = "\n\r"; | ||
# cut message at width of terminal, and pad with spaces | ||
sys.stdout.write("%-*.*s"%(_width,_width,message.strip())); | ||
sys.stdout.write(endline); | ||
sys.stdout.flush(); | ||
|
||
def __call__ (self,*args): | ||
self.pprint(" ".join(args)); | ||
|
||
|
||
|
Oops, something went wrong.