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'
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):
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):
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'))
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):
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
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)
self.colour))
class FromLine(UsernameHeader):
+ can_highlight_as_target = True
header = "From"
colour = "F"
class BoosterLine(UsernameHeader):
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:
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)