home · contact · privacy
Add escape key "panic button" to return to play mode, whatever.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 04:08:43 +0000 (05:08 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 04:08:43 +0000 (05:08 +0100)
rogue_chat.html
rogue_chat_curses.py

index c871b6a8f48eba02a27f7283c1922733211468b7..ebe64f2041fe4a4f755da1bea1a670185c23cdc2 100644 (file)
@@ -1472,11 +1472,12 @@ tui.inputEl.addEventListener('keydown', (event) => {
     if (event.key == 'Enter') {
         event.preventDefault();
     }
-    if (tui.mode.has_input_prompt && event.key == 'Enter'
-        && tui.inputEl.value.length == 0
-        && ['chat', 'command_thing', 'take_thing', 'drop_thing',
-            'admin_enter'].includes(tui.mode.name)) {
-        if (tui.mode.name != 'chat') {
+    if ((!tui.mode.is_intro && event.key == 'Escape')
+        || (tui.mode.has_input_prompt && event.key == 'Enter'
+            && tui.inputEl.value.length == 0
+            && ['chat', 'command_thing', 'take_thing', 'drop_thing',
+                'admin_enter'].includes(tui.mode.name))) {
+        if (!['chat', 'play', 'study', 'edit'].includes(tui.mode.name)) {
             tui.log_msg('@ aborted');
         }
         tui.switch_mode('play');
index 6f136387b33f5353c1216fb13163cdb10da1ba93..8fc2817cbaf45dd1582a84d83e630f38e2cabb5a 100755 (executable)
@@ -1086,15 +1086,20 @@ class TUI:
                 self.do_refresh = True
             except curses.error:
                 continue
-            self.show_help = False
+            keycode = None
+            if len(key) == 1:
+                keycode = ord(key)
             if key == 'KEY_RESIZE':
                 reset_screen_size()
             elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE':
                 self.input_ = self.input_[:-1]
-            elif self.mode.has_input_prompt and key == '\n' and self.input_ == ''\
-                 and self.mode.name in {'chat', 'command_thing', 'take_thing',
-                                        'drop_thing', 'admin_enter'}:
-                if self.mode.name != 'chat':
+            elif (((not self.mode.is_intro) and keycode == 27)  # Escape
+                  or (self.mode.has_input_prompt and key == '\n'
+                      and self.input_ == ''\
+                      and self.mode.name in {'chat', 'command_thing',
+                                             'take_thing', 'drop_thing',
+                                             'admin_enter'})):
+                if self.mode.name not in {'chat', 'play', 'study', 'edit'}:
                     self.log_msg('@ aborted')
                 self.switch_mode('play')
             elif self.mode.has_input_prompt and key == '\n' and self.input_ == '/help':