From 9ec5fd07cf329691599ff7fb9be6348e77ffdc30 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 13 Apr 2009 16:23:17 +1000 Subject: [PATCH] MH is now Zork; changed some wordings --- mitterlib/ui/{ui_mh.py => ui_zork.py} | 69 +++++++++++++++++---------- 1 file changed, 43 insertions(+), 26 deletions(-) rename mitterlib/ui/{ui_mh.py => ui_zork.py} (75%) diff --git a/mitterlib/ui/ui_mh.py b/mitterlib/ui/ui_zork.py similarity index 75% rename from mitterlib/ui/ui_mh.py rename to mitterlib/ui/ui_zork.py index 7f73225..1c78132 100644 --- a/mitterlib/ui/ui_mh.py +++ b/mitterlib/ui/ui_zork.py @@ -21,6 +21,7 @@ import logging import cmd import datetime import warnings +import pickle import mitterlib.ui.helpers.console_utils as console_utils import mitterlib.constants @@ -33,9 +34,9 @@ _log = logging.getLogger('ui.cmd') class Interface(cmd.Cmd): - """A MH-like interface to Mitter.""" + """A MH/zork-like interface to Mitter.""" - NAMESPACE = 'mh' + NAMESPACE = 'zork' # ----------------------------------------------------------------------- # Commands @@ -62,30 +63,48 @@ class Interface(cmd.Cmd): print '%d new messages, %d total messages now' % (len(data), len(self._messages)) - def do_next(self, line=None): - """Get the next message in the top of the list. The message is marked - as read and removed from the list.""" - - try: - self._current_message = self._messages.pop(0) - except IndexError: - print 'There are no unread messages.' + def do_display(self, line=None): + """Display the current message or move the cursor to the + next/previous.""" + + if not line: + line = '' # so 'lower()' doesn't fail. + + line = line.lower() + if line == 'current': + pass + elif line == 'next': + if self._cursor + 1 > len(self._message): + print 'There is no next message.' + print + return + self._cursor += 1 + elif line == 'previous': + if self._cursor == 0: + print 'You are in the top of the list.' + print + return + self.cursor -= 1 + else: + print 'Display WHAT?' + print '("current", "previous" or "next")' return - console_utils.print_messages(self._current_message, self._connection) + message = self._messages[self._cursor] + console_utils.print_messages(message, self._connection) return - def do_print(self, line=None): - """Print the message in the current pointer.""" - if self._current_message is None: - print 'There is no current message.' - return - console_utils.print_messages(self._current_message, self._connection) - def do_list(self, line=None): """Print a summary of the messages in the list.""" - for message in self._messages: - long_line = '%s: %s' % (message.username, message.message) + for pos in xrand(len(self._message)): + if pos == self._cursor: + indicator = '>' + else: + indicator = ' ' + + message = self._messages[pos] + long_line = '%s%s: %s' % (indicator, message.username, + message.message) if len(long_line) > 75: last_space = long_line.rfind(' ', 0, 76) @@ -96,15 +115,13 @@ class Interface(cmd.Cmd): def do_reply(self, line): """Make a reply to the current message.""" - if self._current_message is None: - print 'There is no current message.' - return + message = self._messages[self._cursor] - if self._update(line, reply_to=self._current_message): + if self._update(line, reply_to=message): print 'Reply send.' self.lastcmd = None - def do_update(self, line): + def do_say(self, line): """Update your status.""" if self._update(line): print 'Status updated' @@ -148,7 +165,7 @@ class Interface(cmd.Cmd): self._last_update = None self._connection = connection self._messages = [] - self._current_message = None + self._cursor = 0 self.prompt = '> ' return