chiark / gitweb /
Add a final menu before posting a status.
authorSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 09:01:11 +0000 (09:01 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 09:01:11 +0000 (09:01 +0000)
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

index 8bfad554e184a028772fcabf8359bc4209572479..08ee59d7cc58997ae156c621011197593b56b9f3 100644 (file)
@@ -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")