|
|
@ -21,6 +21,7 @@ import logging |
|
|
|
import cmd |
|
|
|
import cmd |
|
|
|
import datetime |
|
|
|
import datetime |
|
|
|
import warnings |
|
|
|
import warnings |
|
|
|
|
|
|
|
import pickle |
|
|
|
|
|
|
|
|
|
|
|
import mitterlib.ui.helpers.console_utils as console_utils |
|
|
|
import mitterlib.ui.helpers.console_utils as console_utils |
|
|
|
import mitterlib.constants |
|
|
|
import mitterlib.constants |
|
|
@ -33,9 +34,9 @@ _log = logging.getLogger('ui.cmd') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Interface(cmd.Cmd): |
|
|
|
class Interface(cmd.Cmd): |
|
|
|
"""A MH-like interface to Mitter.""" |
|
|
|
"""A MH/zork-like interface to Mitter.""" |
|
|
|
|
|
|
|
|
|
|
|
NAMESPACE = 'mh' |
|
|
|
NAMESPACE = 'zork' |
|
|
|
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------- |
|
|
|
# ----------------------------------------------------------------------- |
|
|
|
# Commands |
|
|
|
# Commands |
|
|
@ -62,30 +63,48 @@ class Interface(cmd.Cmd): |
|
|
|
print '%d new messages, %d total messages now' % (len(data), |
|
|
|
print '%d new messages, %d total messages now' % (len(data), |
|
|
|
len(self._messages)) |
|
|
|
len(self._messages)) |
|
|
|
|
|
|
|
|
|
|
|
def do_next(self, line=None): |
|
|
|
def do_display(self, line=None): |
|
|
|
"""Get the next message in the top of the list. The message is marked |
|
|
|
"""Display the current message or move the cursor to the |
|
|
|
as read and removed from the list.""" |
|
|
|
next/previous.""" |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
if not line: |
|
|
|
self._current_message = self._messages.pop(0) |
|
|
|
line = '' # so 'lower()' doesn't fail. |
|
|
|
except IndexError: |
|
|
|
|
|
|
|
print 'There are no unread messages.' |
|
|
|
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 |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
console_utils.print_messages(self._current_message, self._connection) |
|
|
|
message = self._messages[self._cursor] |
|
|
|
|
|
|
|
console_utils.print_messages(message, self._connection) |
|
|
|
return |
|
|
|
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): |
|
|
|
def do_list(self, line=None): |
|
|
|
"""Print a summary of the messages in the list.""" |
|
|
|
"""Print a summary of the messages in the list.""" |
|
|
|
for message in self._messages: |
|
|
|
for pos in xrand(len(self._message)): |
|
|
|
long_line = '%s: %s' % (message.username, message.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: |
|
|
|
if len(long_line) > 75: |
|
|
|
last_space = long_line.rfind(' ', 0, 76) |
|
|
|
last_space = long_line.rfind(' ', 0, 76) |
|
|
@ -96,15 +115,13 @@ class Interface(cmd.Cmd): |
|
|
|
|
|
|
|
|
|
|
|
def do_reply(self, line): |
|
|
|
def do_reply(self, line): |
|
|
|
"""Make a reply to the current message.""" |
|
|
|
"""Make a reply to the current message.""" |
|
|
|
if self._current_message is None: |
|
|
|
message = self._messages[self._cursor] |
|
|
|
print 'There is no current message.' |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self._update(line, reply_to=self._current_message): |
|
|
|
if self._update(line, reply_to=message): |
|
|
|
print 'Reply send.' |
|
|
|
print 'Reply send.' |
|
|
|
self.lastcmd = None |
|
|
|
self.lastcmd = None |
|
|
|
|
|
|
|
|
|
|
|
def do_update(self, line): |
|
|
|
def do_say(self, line): |
|
|
|
"""Update your status.""" |
|
|
|
"""Update your status.""" |
|
|
|
if self._update(line): |
|
|
|
if self._update(line): |
|
|
|
print 'Status updated' |
|
|
|
print 'Status updated' |
|
|
@ -148,7 +165,7 @@ class Interface(cmd.Cmd): |
|
|
|
self._last_update = None |
|
|
|
self._last_update = None |
|
|
|
self._connection = connection |
|
|
|
self._connection = connection |
|
|
|
self._messages = [] |
|
|
|
self._messages = [] |
|
|
|
self._current_message = None |
|
|
|
self._cursor = 0 |
|
|
|
|
|
|
|
|
|
|
|
self.prompt = '> ' |
|
|
|
self.prompt = '> ' |
|
|
|
return |
|
|
|
return |