def __init__(self, cc, feed, title):
super().__init__(cc, client.Notification, feed, title)
-class Composer:
+class Composer(Activity):
class DisplayText:
def __init__(self, text):
self.text = text
if self.text[self.point-3:self.point] == '\n.\n':
self.text = (self.text[:self.point-2] +
self.text[self.point:])
- self.post()
- self.cc.composer = None
- self.cc.activity_stack.pop()
+ self.point -= 2
+ self.chain_to(PostMenu(self))
elif ch in {ctrl('o')}:
self.mode = 'ctrlo'
elif isinstance(ch, str) and (' ' <= ch < '\x7F' or '\xA0' <= ch):
self.point += 1
elif self.mode == 'ctrlo':
if ch == ' ':
- self.post()
- self.cc.composer = None
- self.cc.activity_stack.pop()
+ self.chain_to(PostMenu(self))
elif ch == 'q':
self.cc.composer = None
- self.cc.activity_stack.pop()
+ return 'quit'
else:
self.mode = 'normal'
return
self.cc.post("statuses", **params)
+class PostMenu(Menu):
+ def __init__(self, composer):
+ super().__init__(composer.cc)
+ self.composer = composer
+ self.title = text.ColouredString("Post a status", "H")
+ self.items.append(text.MenuKeypressLine(
+ 'SPACE', text.ColouredString("Post")))
+ self.items.append(text.BlankLine())
+ self.items.append(text.MenuKeypressLine(
+ 'Q', text.ColouredString("Cancel post")))
+ self.items.append(text.MenuKeypressLine(
+ 'A', text.ColouredString("Re-edit post")))
+
+ def handle_key(self, ch):
+ if ch in {'q', 'Q'}:
+ self.cc.composer = None
+ return 'quit' # FIXME: maybe a confirmation, like real Mono?
+ elif ch in {'a', 'A'}:
+ self.chain_to(self.composer)
+ elif ch in {' '}:
+ self.composer.post()
+ self.cc.composer = None
+ self.cc.activity_stack.pop()
+ else:
+ return super().handle_key(ch)
+
class testComposerLayout(unittest.TestCase):
def testLayout(self):
t = Composer.DisplayText("abc")