From 35b5d886fdf7d66442522d950425b02e10b5ef71 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 8 Dec 2023 09:01:11 +0000 Subject: [PATCH] Add a final menu before posting a status. So far it doesn't have anything useful in it, but the idea is that it will be where you add all the other options in statuses, like media attachments, content warnings, etc. --- cursesclient.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/cursesclient.py b/cursesclient.py index 8bfad55..08ee59d 100644 --- a/cursesclient.py +++ b/cursesclient.py @@ -709,7 +709,7 @@ class NotificationsFile(ObjectFile): 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 @@ -968,9 +968,8 @@ class Composer: 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): @@ -980,12 +979,10 @@ class Composer: 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' @@ -1007,6 +1004,32 @@ class Composer: 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") -- 2.30.2