chiark / gitweb /
Add target highlights in the Ego Log.
authorSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 07:25:18 +0000 (07:25 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 07:25:18 +0000 (07:25 +0000)
Forgot!

cursesclient.py
text.py

index 51871350915fa70b76c2b634d9fe9125b00233ae..7ca769ad43e762c818aeed07f3798c2d0d3723ba 100644 (file)
@@ -427,6 +427,8 @@ class File(Activity):
                 self.send_mode()
             elif ch in {'f', 'F'}:
                 self.favourite_mode()
+            elif ch in {ctrl('b')}:
+                self.boost_mode()
         elif self.mode == 'select':
             if ch in {'q', 'Q'}:
                 self.mode = 'normal'
@@ -443,11 +445,19 @@ class File(Activity):
             elif (self.select_type == 'favourite' and
                   ch in {'d', 'D'}):
                 self.favourite_complete(-1)
+            elif (self.select_type == 'boost' and
+                  ch in {'e', 'E', ' '}):
+                self.boost_complete(+1)
+            elif (self.select_type == 'boost' and
+                  ch in {'d', 'D'}):
+                self.boost_complete(-1)
 
     def send_mode(self):
         pass # not supported
     def favourite_mode(self):
         pass # not supported
+    def boost_mode(self):
+        pass # not supported
 
 class ObjectFile(File):
     def __init__(self, cc, constructor, feed, title):
@@ -511,7 +521,7 @@ class ObjectFile(File):
         for thing, itemindex in self.iter_text_indexed():
             params = {}
             if (self.mode == 'select' and itemindex == self.select_target and
-                isinstance(thing, text.FromLine)):
+                hasattr(thing, 'can_highlight_as_target')):
                 params['target'] = True
             for line in thing.render(width, **params):
                 for s in line.split(width):
@@ -536,6 +546,9 @@ class ObjectFile(File):
             elif self.select_type == 'favourite':
                 sl.keys.append(('SPACE', 'Fave'))
                 sl.keys.append(('D', 'Unfave'))
+            elif self.select_type == 'boost':
+                sl.keys.append(('SPACE', 'Boost'))
+                sl.keys.append(('D', 'Unboost'))
             sl.keys.append(('-', None))
             sl.keys.append(('+', None))
             sl.keys.append(('Q', 'Quit'))
@@ -544,19 +557,31 @@ class ObjectFile(File):
                 sl.keys.append(('-', 'Up'))
             else:
                 sl.keys.append(('SPACE', 'More'))
+            if self.items_have_authors:
+                sl.keys.append(('S', 'Reply'))
+            if self.items_are_statuses:
+                sl.keys.append(('F', 'Fave'))
+                sl.keys.append(('^B', 'Boost'))
             sl.keys.append(('Q', 'Exit'))
             sl.proportion = self.linepos / len(self.lines)
         sl_rendered = util.exactly_one(sl.render(self.cc.scr_w))
         self.cc.print_at(self.cc.scr_h - 1, 0, sl_rendered)
 
     def send_mode(self):
-        self.mode = 'select'
-        self.select_type = 'send'
-        self.select_target = self.index_by_line[self.linepos-1]
+        if self.items_have_authors:
+            self.mode = 'select'
+            self.select_type = 'send'
+            self.select_target = self.index_by_line[self.linepos-1]
     def favourite_mode(self):
-        self.mode = 'select'
-        self.select_type = 'favourite'
-        self.select_target = self.index_by_line[self.linepos-1]
+        if self.items_are_statuses:
+            self.mode = 'select'
+            self.select_type = 'favourite'
+            self.select_target = self.index_by_line[self.linepos-1]
+    def boost_mode(self):
+        if self.items_are_statuses:
+            self.mode = 'select'
+            self.select_type = 'boost'
+            self.select_target = self.index_by_line[self.linepos-1]
     def prev_select_target(self):
         self.select_target = max(self.minpos, self.select_target-1)
     def next_select_target(self):
@@ -595,6 +620,12 @@ class ObjectFile(File):
         verb = "favourite" if direction > 0 else "unfavourite"
         self.cc.post(f"statuses/{reply_id}/{verb}")
 
+    def boost_complete(self, direction):
+        self.mode = 'normal'
+        reply_id = self.statuses[self.select_target].get_reply_id()
+        verb = "reblog" if direction > 0 else "unreblog"
+        self.cc.post(f"statuses/{reply_id}/{verb}")
+
     def move_to(self, pos):
         old_linepos = self.linepos
         self.linepos = pos
@@ -613,10 +644,14 @@ class ObjectFile(File):
     def goto_bottom(self): return self.move_to(len(self.lines))
 
 class StatusFile(ObjectFile):
+    items_are_statuses = True
+    items_have_authors = True
     def __init__(self, cc, feed, title):
         super().__init__(cc, client.Status, feed, title)
 
 class NotificationsFile(ObjectFile):
+    items_are_statuses = False
+    items_have_authors = True
     def __init__(self, cc, feed, title):
         super().__init__(cc, client.Notification, feed, title)
 
diff --git a/text.py b/text.py
index a0be501985d15efb1501ff8d5122aa609a45793d..e3d5794dc1a51672e3163c7b33ef84d38e9ddd6c 100644 (file)
--- a/text.py
+++ b/text.py
@@ -145,6 +145,7 @@ class UsernameHeader:
                               self.colour))
 
 class FromLine(UsernameHeader):
+    can_highlight_as_target = True
     header = "From"
     colour = "F"
 class BoosterLine(UsernameHeader):
@@ -351,26 +352,27 @@ class Paragraph:
         return f"Paragraph({self.words!r}, unfinished={self.unfinished_word!r})"
 
 class NotificationLog:
+    can_highlight_as_target = True
+
     def __init__(self, timestamp, account, nameline, ntype, cparas):
         self.timestamp = timestamp
         self.account = account
         self.nameline = nameline
 
-        date = time.strftime("%Y-%m-%d %H:%M:%S",
-                             time.localtime(self.timestamp))
-        sentence = f"{self.nameline} ({self.account})"
+        self.date = ColouredString(
+            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.timestamp)))
+        self.account_desc = f"{self.nameline} ({self.account})"
+
+        self.para = Paragraph()
         want_content = False
         if ntype == 'reblog':
-            sentence += ' boosted:'
+            self.para.add('boosted:')
             want_content = True
         elif ntype == 'favourite':
-            sentence += ' favourited:'
+            self.para.add('favourited:')
             want_content = True
         elif ntype == 'follow':
-            sentence += ' followed you'
-
-        self.para = Paragraph()
-        self.para.add(ColouredString(date + " " + sentence))
+            self.para.add('followed you')
         self.para.end_word()
 
         if want_content:
@@ -379,8 +381,15 @@ class NotificationLog:
                 self.para.add_para(cpara)
             self.para.delete_mention_words_from(currlen)
 
-    def render(self, width):
-        it = self.para.render(width, max(0, width-2))
+    def render(self, width, target=False):
+        full_para = Paragraph()
+        full_para.add(ColouredString(self.date + " "))
+        full_para.add(ColouredString(
+            self.account_desc, "f" if target else " "))
+        full_para.add_para(self.para)
+        full_para.end_word()
+
+        it = full_para.render(width, max(0, width-2))
         yield next(it)
         try:
             line = next(it)