18bf93a628b2 — Alain Leufroy 3 years ago
widget: let user choose main window splitting orientation

Related to https://todo.sr.ht/~alainl/lairucrem/4
2 files changed, 22 insertions(+), 0 deletions(-)

M lairucrem/config.py
M lairucrem/widgets/mainwidget.py
M lairucrem/config.py +14 -0
@@ 350,6 350,8 @@ CMD_MENU = 'menu'
 CMD_ESCAPE = 'escape'
 CMD_SCROLL_LEFT = 'scroll left'
 CMD_SCROLL_RIGHT = 'scroll right'
+CMD_SPLIT_HORIZONTALLY = 'split horizontally'
+CMD_SPLIT_VERTICALLY = 'split vertically'
 CURSOR_UP_NEXT_PACKED = 'up next packed'
 CURSOR_DOWN_NEXT_PACKED = 'down next packed'
 CURSOR_PAGE_UP_NEXT_PACKED = 'page up next packed'

          
@@ 387,6 389,9 @@ def keybindings_default():
     command_map['meta home'] = CURSOR_MAX_LEFT_NEXT_PACKED
     command_map['meta end'] = CURSOR_MAX_RIGHT_NEXT_PACKED
 
+    command_map['-'] = CMD_SPLIT_HORIZONTALLY
+    command_map['|'] = CMD_SPLIT_VERTICALLY
+
     command_map['ctrl f'] = CMD_FILTER
     command_map['/'] = CMD_SEARCH
     command_map['n'] = CMD_NEXT_MATCH

          
@@ 413,6 418,9 @@ def keybindings_mouse():
     command_map[('ctrl mouse press', 4)] = CMD_PREV_MATCH
     command_map[('ctrl mouse press', 5)] = CMD_NEXT_MATCH
 
+    command_map[('ctrl mouse press', 2)] = CMD_SPLIT_VERTICALLY
+    command_map[('ctrl mouse press', 3)] = CMD_SPLIT_HORIZONTALLY
+
 
 def keybindings_vim():
     command_map['ctrl w'] = CMD_NEXT_SELECTABLE

          
@@ 432,6 440,9 @@ def keybindings_vim():
     command_map['ESC'] = CMD_ESCAPE
     command_map['ctrl c'] = CMD_ESCAPE
 
+    command_map['ctrl s'] = CMD_SPLIT_HORIZONTALLY
+    command_map['ctrl v'] = CMD_SPLIT_VERTICALLY
+
     command_map['ctrl f'] = CMD_FILTER
     command_map['/'] = CMD_SEARCH
     command_map['n'] = CMD_NEXT_MATCH

          
@@ 478,6 489,9 @@ def keybindings_emacs():
     command_map['esc'] = CMD_ESCAPE
     command_map['ctrl g'] = CMD_ESCAPE
 
+    command_map['meta 3'] = CMD_SPLIT_VERTICALLY
+    command_map['meta 2'] = CMD_SPLIT_HORIZONTALLY
+
     command_map['ctrl f'] = CMD_FILTER
     command_map['/'] = CMD_SEARCH
     command_map['n'] = CMD_NEXT_MATCH

          
M lairucrem/widgets/mainwidget.py +8 -0
@@ 166,6 166,14 @@ class packer(delegate_to_widget_mixin('_
         key = super(packer, self).keypress(size, key)
         widget = self._original_widget
         command = self._command_map[key]
+        if command == config.CMD_SPLIT_HORIZONTALLY:
+            self._orientation = 'vertical'
+            self._update_container()
+            return
+        if command == config.CMD_SPLIT_VERTICALLY:
+            self._orientation = 'horizontal'
+            self._update_container()
+            return
         if command == CURSOR_LEFT:
             widget.focus_position = max(0, widget.focus_position - 1)
             return