+#----- 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()
+
+
+def do_ship_aid(args, bu):
+ if opts.ship_duty is None: opts.ship_duty = True
+
+ displayer = globals()['Display_'+opts.display]()
+ rotate_nya = '/-\\'
+
+ (myself, track) = prep_chat_log(args, bu, progress=displayer)
+
+ def timeevent(t,e):
+ if t is None: return ' ' * 22
+ return " %-4s %-16s" % (format_time_interval(now - t),e)
+
+ displayer.realstart()
+
+ while True:
+ track.catchup()
+ now = time.time()
+
+ s = "%s" % track.myname()
+
+ vn = track.vessel()
+ if vn is None:
+ s += " not on a vessel?!"
+ else:
+ s += " on board the %s at %s\n" % (
+ vn, time.strftime("%Y-%m-%d %H:%M:%S"))
+
+ tbl = StandingsTable()
+ tbl.headings()
+
+ for pa in track.aboard():
+ pi = pa.pirate_info()
+
+ xs = ''
+ if pa.gunner: xs += 'G '
+ else: xs += ' '
+ xs += timeevent(pa.last_time, pa.last_event)
+ xs += timeevent(pa.last_chat_time, pa.last_chat_chan)
+
+ if pi is None:
+ tbl.pirate_dummy(pa.name, rotate_nya[0], xs)
+ else:
+ tbl.pirate(pi, xs)
+
+ s += tbl.results()
+
+ displayer.show(s)
+ time.sleep(1)
+ rotate_nya = rotate_nya[1:2] + rotate_nya[0]
+
+#---------- main program ----------
+