Skip to content

Commit

Permalink
Moving Owlcat to trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
o-smirnov committed Jun 30, 2010
0 parents commit fb5c8bb
Show file tree
Hide file tree
Showing 75 changed files with 3,712 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Owlcat/Console.py
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));



Loading

0 comments on commit fb5c8bb

Please sign in to comment.