pw_console: Remove Ctrl-Alt-hjkl and Ctrl-w bindings

Backspace in many terminals is mapped to Ctrl-H. The move window left
keybinding Ctrl-Alt-H clashes with this if you press Alt-Backspace to
delete previous word in the repl. Since Ctrl-Alt-Left also moves the
window left I'm removing these bindings. It's also easy to move windows
using the View menu and the mouse only.

Removed Ctrl-W keybind to quit. This conflicts with vim ctrl-w for
window movement and Chrome ctrl-w to close a tab. Quiting can be done
with the mouse in the File > Exit menu or by typing 'quit' or 'exit' in
the repl.

Bug fix to tab view: If a window pane is hidden then view is switched
to tabbed an exception will occur. This un-hides all panes when
switching to tabbed mode. Also prevents hiding windows if tabbed mode
is enabled.

Change-Id: I538e6cd4b147773b880b92c3aae01592b0a8e278
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/62040
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Anthony DiGirolamo <tonymd@google.com>
diff --git a/pw_console/py/pw_console/console_app.py b/pw_console/py/pw_console/console_app.py
index 3a2e722..cd9e20d3 100644
--- a/pw_console/py/pw_console/console_app.py
+++ b/pw_console/py/pw_console/console_app.py
@@ -184,9 +184,6 @@
         # Two space separator
         self.message.append(('', '  '))
 
-        self.message.extend(
-            pw_console.widgets.checkbox.to_keybind_indicator('Ctrl-W', 'Quit'))
-
         # Auto-generated keybindings list for all active panes
         self.keybind_help_window = HelpWindow(self, title='Keyboard Shortcuts')
 
@@ -419,50 +416,50 @@
             MenuItem(
                 '[View]',
                 children=[
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Move Window Up         Ctrl-Alt-k',
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Move Window Up         Ctrl-Alt-Up',
                              handler=functools.partial(
                                  self.run_pane_menu_option,
                                  self.window_manager.move_pane_up)),
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Move Window Down       Ctrl-Alt-j',
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Move Window Down     Ctrl-Alt-Down',
                              handler=functools.partial(
                                  self.run_pane_menu_option,
                                  self.window_manager.move_pane_down)),
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Move Window Left       Ctrl-Alt-h',
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Move Window Left     Ctrl-Alt-Left',
                              handler=functools.partial(
                                  self.run_pane_menu_option,
                                  self.window_manager.move_pane_left)),
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Move Window Right      Ctrl-Alt-l',
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Move Window Right   Ctrl-Alt-Right',
                              handler=functools.partial(
                                  self.run_pane_menu_option,
                                  self.window_manager.move_pane_right)),
                     MenuItem('-'),
 
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Enlarge Window Height       Alt-=',
-                             handler=functools.partial(
-                                 self.run_pane_menu_option,
-                                 self.window_manager.enlarge_pane)),
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Shrink Window Height    Alt-Minus',
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Shrink Height            Alt-Minus',
                              handler=functools.partial(
                                  self.run_pane_menu_option,
                                  self.window_manager.shrink_pane)),
-                    MenuItem('-'),
-
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Enlarge Column Split        Alt-.',
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Enlarge Height               Alt-=',
                              handler=functools.partial(
                                  self.run_pane_menu_option,
-                                 self.window_manager.enlarge_split)),
-                    #         [Menu Item            ][Keybind  ]
-                    MenuItem('Shrink Column Split         Alt-,',
+                                 self.window_manager.enlarge_pane)),
+                    MenuItem('-'),
+
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Shrink Column                Alt-,',
                              handler=functools.partial(
                                  self.run_pane_menu_option,
                                  self.window_manager.shrink_split)),
+                    #         [Menu Item             ][Keybind  ]
+                    MenuItem('Enlarge Column               Alt-.',
+                             handler=functools.partial(
+                                 self.run_pane_menu_option,
+                                 self.window_manager.enlarge_split)),
                     MenuItem('-'),
 
                     #         [Menu Item            ][Keybind  ]
diff --git a/pw_console/py/pw_console/docs/user_guide.rst b/pw_console/py/pw_console/docs/user_guide.rst
index 7d5bc42..1b647d7 100644
--- a/pw_console/py/pw_console/docs/user_guide.rst
+++ b/pw_console/py/pw_console/docs/user_guide.rst
@@ -23,8 +23,7 @@
 ~~~~~~~
 
 1.  Click the :guilabel:`[File]` menu and then :guilabel:`Exit`.
-2.  Type ``quit`` or ``exit`` in the Python Input window.
-3.  The keyboard shortcut :kbd:`Ctrl-W` also quits.
+2.  Type ``quit`` or ``exit`` in the Python Input window and press :kbd:`Enter`.
 
 
 Interface Layout
@@ -424,10 +423,10 @@
 Shrink vertical split width                   :kbd:`Alt-.`
 Reset window sizes                            :kbd:`Ctrl-u`
 
-Move window up                                :kbd:`Ctrl-Alt-k`
-Move window down                              :kbd:`Ctrl-Alt-j`
-Move window left                              :kbd:`Ctrl-Alt-h`
-Move window right                             :kbd:`Ctrl-Alt-l`
+Move window up                                :kbd:`Ctrl-Alt-Up`
+Move window down                              :kbd:`Ctrl-Alt-Down`
+Move window left                              :kbd:`Ctrl-Alt-Left`
+Move window right                             :kbd:`Ctrl-Alt-Right`
 ============================================  =====================
 
 Moving windows left and right will create a new vertical splits. Each vertical
diff --git a/pw_console/py/pw_console/key_bindings.py b/pw_console/py/pw_console/key_bindings.py
index dd0d040..e227bb7 100644
--- a/pw_console/py/pw_console/key_bindings.py
+++ b/pw_console/py/pw_console/key_bindings.py
@@ -49,27 +49,23 @@
     # F3 is ptpython history
 
     @bindings.add('escape', 'c-left')  # Alt-Ctrl-
-    @bindings.add('escape', 'c-h')  # Alt-Ctrl-
     def move_pane_left(event):
         """Move window pane left."""
         console_app.window_manager.move_pane_left()
 
     @bindings.add('escape', 'c-right')  # Alt-Ctrl-
-    @bindings.add('escape', 'c-l')  # Alt-Ctrl-
     def move_pane_right(event):
         """Move window pane right."""
         console_app.window_manager.move_pane_right()
 
     # NOTE: c-up and c-down seem swapped in prompt_toolkit
     @bindings.add('escape', 'c-up')  # Alt-Ctrl-
-    @bindings.add('escape', 'c-j')  # Alt-Ctrl-
     def move_pane_down(event):
         """Move window pane down."""
         console_app.window_manager.move_pane_down()
 
     # NOTE: c-up and c-down seem swapped in prompt_toolkit
     @bindings.add('escape', 'c-down')  # Alt-Ctrl-
-    @bindings.add('escape', 'c-k')  # Alt-Ctrl-
     def move_pane_up(event):
         """Move window pane up."""
         console_app.window_manager.move_pane_up()
@@ -99,7 +95,6 @@
         """Balance all window sizes."""
         console_app.window_manager.balance_window_sizes()
 
-    @bindings.add('c-w')
     @bindings.add('c-q')
     def exit_(event):
         """Quit the console application."""
diff --git a/pw_console/py/pw_console/window_list.py b/pw_console/py/pw_console/window_list.py
index a32fd0e..7ca80bb 100644
--- a/pw_console/py/pw_console/window_list.py
+++ b/pw_console/py/pw_console/window_list.py
@@ -124,18 +124,13 @@
 
         if self.display_mode == DisplayMode.TABBED:
             self.focused_pane_index = 0
+            # Un-hide all panes, they must be visible to switch between tabs.
+            for pane in self.active_panes:
+                pane.show_pane = True
 
         self.application.focus_main_menu()
         self.refresh_ui()
 
-    def set_display_mode_stack(self):
-        self.display_mode = DisplayMode.STACK
-        self.refresh_ui()
-
-    def set_display_mode_tabbed(self):
-        self.display_mode = DisplayMode.TABBED
-        self.refresh_ui()
-
     def refresh_ui(self):
         self.window_manager.update_root_container_body()
         # Update menu after the window manager rebuilds the root container.
diff --git a/pw_console/py/pw_console/window_manager.py b/pw_console/py/pw_console/window_manager.py
index a4f1465..cbcd8ba 100644
--- a/pw_console/py/pw_console/window_manager.py
+++ b/pw_console/py/pw_console/window_manager.py
@@ -258,6 +258,12 @@
 
     def toggle_pane(self, pane):
         """Toggle a pane on or off."""
+        window_list, _pane_index = (
+            self._find_window_list_and_pane_index(pane))
+
+        # Don't hide if tabbed mode is enabled, the container can't be rendered.
+        if window_list.display_mode == DisplayMode.TABBED:
+            return
         pane.show_pane = not pane.show_pane
         self.application.update_menu_items()
         self.update_root_container_body()