self.escape_menu = EscMenu(self)
self.log_menu = LogMenu(self)
self.log_menu_2 = LogMenu2(self)
+ self.exit_menu = ExitMenu(self)
self.activity_stack = [self.main_menu]
elif ch == curses.KEY_RESIZE:
self.scr_h, self.scr_w = self.scr.getmaxyx()
else:
- if self.activity_stack[-1].handle_key(ch) == 'quit':
+ result = self.activity_stack[-1].handle_key(ch)
+ if result == 'quit':
if len(self.activity_stack) > 1:
self.activity_stack.pop()
- else:
- # Exit whole program when activity stack empties.
- # FIXME: do we want to do this, or should the Main
- # Menu be sticky at the bottom of the stack and
- # require a special ESC X X to exit?
- return
+ elif result == 'exit':
+ return
finally:
self.curses_shutdown()
y += 1
sl = text.FileStatusLine()
+ self.add_keys(sl)
sl_rendered = util.exactly_one(sl.render(self.cc.scr_w))
self.cc.print_at(self.cc.scr_h - 1, 0, sl_rendered)
+ def add_keys(self, sl):
+ sl.keys.append(('RET', 'Back'))
+
def chain_to(self, activity):
assert self.cc.activity_stack[-1] is self
self.cc.activity_stack[-1] = activity
self.title = text.ColouredString(
"Mastodonochrome Main Menu", 'H')
+ def add_keys(self, sl):
+ # intentionally don't call the base class, because [Q] doesn't
+ # do anything on this menu
+ sl.keys.append(('ESC', 'Utilities'))
+
def handle_key(self, ch):
if ch in {ord('h'), ord('H')}:
self.push_to(self.cc.home_timeline)
self.chain_to(self.cc.mentions_timeline)
elif ch in {ord('l'), ord('L')}:
self.chain_to(self.cc.log_menu)
+ elif ch in {ord('x'), ord('X')}:
+ self.chain_to(self.cc.exit_menu)
elif ch in {ord('g'), ord('G')}:
self.cc.activity_stack[:] = [self.cc.main_menu]
else:
else:
return super().handle_key(ch)
+class ExitMenu(Menu):
+ def __init__(self, cc):
+ super().__init__(cc)
+ self.title = text.ColouredString(
+ "Exit Mastodonochrome [ESC][X]",
+ "HHHHHHHHHHHHHHHHHHHHHHKKKHHKH")
+
+ def handle_key(self, ch):
+ if ch in {ord('x'), ord('X')}:
+ return 'exit'
+ else:
+ return super().handle_key(ch)
+
class File:
# Base class for anything where you page up and down.
def __init__(self, cc):