-def format_time_interval(ti):
- if ti < 120: return '%d:%02d' % (ti / 60, ti % 60)
- if ti < 7200: return '%2dm' % (ti / 60)
- if ti < 86400: return '%dh' % (ti / 3600)
- return '%dd' % (ti / 86400)
+#----- ship management aid -----
+
+class Display_dumb(ProgressPrintPercentage):
+ def __init__(self):
+ ProgressPrintPercentage.__init__(self)
+ def show(self, s):
+ print '\n\n', s;
+ def realstart(self):
+ pass
+
+class Display_overwrite(ProgressPrintPercentage):
+ def __init__(self):
+ ProgressPrintPercentage.__init__(self)
+
+ null = file('/dev/null','w')
+ curses.setupterm(fd=null.fileno())
+
+ self._clear = curses.tigetstr('clear')
+ if not self._clear:
+ self._debug('missing clear!')
+ self.show = Display_dumb.show
+ return
+
+ self._t = {'el':'', 'ed':''}
+ if not self._init_sophisticated():
+ for k in self._t.keys(): self._t[k] = ''
+ self._t['ho'] = self._clear
+
+ def _debug(self,m): debug('display overwrite: '+m)
+
+ def _init_sophisticated(self):
+ for k in self._t.keys():
+ s = curses.tigetstr(k)
+ self._t[k] = s
+ self._t['ho'] = curses.tigetstr('ho')
+ if not self._t['ho']:
+ cup = curses.tigetstr('cup')
+ self._t['ho'] = curses.tparm(cup,0,0)
+ missing = [k for k in self._t.keys() if not self._t[k]]
+ if missing:
+ self.debug('missing '+(' '.join(missing)))
+ return 0
+ return 1
+
+ def show(self, s):
+ w = sys.stdout.write
+ def wti(k): w(self._t[k])
+
+ wti('ho')
+ nl = ''
+ for l in s.rstrip().split('\n'):
+ w(nl)
+ w(l)
+ wti('el')
+ nl = '\r\n'
+ wti('ed')
+ w(' ')
+ sys.stdout.flush()
+
+ def realstart(self):
+ sys.stdout.write(self._clear)
+ sys.stdout.flush()
+