- commit
- 57a4c0d7db05de8dd0ff807071229dd4a321bbed
- parent
- 89750318d03c797ab6a46a92327505108f92601f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-07-06 16:48
refactor input on_key
Diffstat
| M | sheet/__main__.py | 48 | +++++++++++++++++++++--------------------------- |
1 files changed, 21 insertions, 27 deletions
diff --git a/sheet/__main__.py b/sheet/__main__.py
@@ -113,44 +113,38 @@ class App(boon.App): 113 113 def cancel_input(self): 114 114 self.input = None 115 115116 -1 def maybe_submit_input(self):-1 116 def on_key(self, key): 117 117 if self.input:118 -1 if self.input.full:119 -1 return False120 -1 else:-1 118 if not self.input.full and key in [ -1 119 boon.KEY_DOWN, -1 120 boon.KEY_UP, -1 121 boon.KEY_NPAGE, -1 122 boon.KEY_PPAGE, -1 123 boon.KEY_RIGHT, -1 124 boon.KEY_LEFT, -1 125 ]: 121 126 self.submit_input()122 -1 return True123 -1124 -1 def on_key(self, key):125 -1 if key == boon.KEY_DOWN:126 -1 if self.maybe_submit_input():127 -1 self.cursor_y += 1-1 127 self.on_key(key) -1 128 else: -1 129 self.input.on_key(key) -1 130 elif key == 'q': -1 131 self.running = False -1 132 elif key == boon.KEY_DOWN: -1 133 self.cursor_y += 1 128 134 elif key == boon.KEY_UP:129 -1 if self.maybe_submit_input():130 -1 self.cursor_y = max(self.cursor_y - 1, 0)-1 135 self.cursor_y = max(self.cursor_y - 1, 0) 131 136 elif key == boon.KEY_NPAGE:132 -1 if self.maybe_submit_input():133 -1 self.cursor_y += self.rows - 3-1 137 self.cursor_y += self.rows - 3 134 138 elif key == boon.KEY_PPAGE:135 -1 if self.maybe_submit_input():136 -1 self.cursor_y = max(self.cursor_y - (self.rows - 3), 0)-1 139 self.cursor_y = max(self.cursor_y - (self.rows - 3), 0) 137 140 elif key == boon.KEY_RIGHT:138 -1 if self.maybe_submit_input():139 -1 self.cursor_x += 1-1 141 self.cursor_x += 1 140 142 elif key == boon.KEY_LEFT:141 -1 if self.maybe_submit_input():142 -1 self.cursor_x = max(self.cursor_x - 1, 0)143 -1144 -1 if self.input:145 -1 self.input.on_key(key)146 -1 elif key == 'q':147 -1 self.running = False-1 143 self.cursor_x = max(self.cursor_x - 1, 0) 148 144 elif key == '>': 149 145 self.change_width(self.cursor_x, 1) 150 146 elif key == '<': 151 147 self.change_width(self.cursor_x, -1)152 -1 # elif key == '=':153 -1 # self.set_width(self.cursor_x, max() # TODO auto width154 148 elif key == '\n': 155 149 raw = self.sheet.get_raw((self.cursor_x, self.cursor_y)) 156 150 self.input = Input(raw, self.submit_input, self.cancel_input, full=True)