- commit
- b26087a0952a16a410d2ae6417acd31377af1b52
- parent
- 6a1db89ae43453fba7aac71d69f703a62b9ccd0e
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-08-18 10:59
show in-app help
Diffstat
| M | README.md | 7 | ++++--- |
| M | sheet/__main__.py | 36 | +++++++++++++++++++++++++++++++++++- |
2 files changed, 39 insertions, 4 deletions
diff --git a/README.md b/README.md
@@ -16,15 +16,16 @@ option. 16 16 mode. The difference between the two modes is the behavior of arrow keys: 17 17 In full edit mode, arrow keys move the text cursor. In quick edit mode, 18 18 arrow keys move the cell cursor (after submitting the changes).19 -1 - `q` - quit20 -1 - `>`/`<` - increase/decrease the width of the current column21 -1 - Delete - clear the current cell22 19 - `#` - Start drag mode (blue). Move the cursor to a different cell and press 23 20 enter. The area between the two cells will be filled with the formula from 24 21 the first cell. References to rows and columns that are not prefixed with 25 22 `$` will be adapted. -1 23 - Delete - clear the current cell -1 24 - `>`/`<` - increase/decrease the width of the current column 26 25 - `w` - Write the sheet to a file (source form). 27 26 - `W` - Write the sheet to a file (evaluated form). -1 27 - `q` - show help -1 28 - `q` - quit 28 29 29 30 ## Formulas 30 31
diff --git a/sheet/__main__.py b/sheet/__main__.py
@@ -2,6 +2,7 @@ import argparse 2 2 import sys 3 3 4 4 import boon -1 5 from wcwidth import wcswidth 5 6 6 7 from .csv import dump_csv 7 8 from .csv import load_csv @@ -19,6 +20,23 @@ from .term import blue 19 20 from .term import invert 20 21 from .term import red 21 22 -1 23 HELP = """ -1 24 Help -1 25 --- -1 26 -1 27 arrow keys - move the cursor -1 28 page up/down - move one screen up/down -1 29 enter - start edit mode -1 30 =, -, 0-9 - start quick edit mode -1 31 # - start drag mode -1 32 del - delete -1 33 >, < - adjust column width -1 34 w - write to file (source form) -1 35 W - write to file (evaluated form) -1 36 h - show help -1 37 q - quit -1 38 """ -1 39 22 40 23 41 def to_cell(value: float|int|str|None|Exception, width: int) -> str: 24 42 if isinstance(value, float|int): @@ -50,6 +68,7 @@ class App(boon.App): 50 68 self.widths = {} 51 69 self.input = None 52 70 self.drag = None -1 71 self.help = False 53 72 54 73 @property 55 74 def cursor(self): @@ -71,6 +90,17 @@ class App(boon.App): 71 90 self.x0 += offset 72 91 73 92 def render(self, rows, cols): -1 93 if self.help: -1 94 lines = HELP.strip().split('\n') -1 95 max_width = max(wcswidth(line) for line in lines) -1 96 x_offset = max(0, cols - max_width) // 2 -1 97 y_offset = max(0, rows - len(lines)) // 2 -1 98 for _ in range(y_offset): -1 99 yield '' -1 100 for line in lines: -1 101 yield ' ' * x_offset + line -1 102 return -1 103 74 104 self.scroll_into_view(rows, cols) 75 105 76 106 lines = [] @@ -121,7 +151,7 @@ class App(boon.App): 121 151 else: 122 152 lines.append(self.sheet.get_raw(self.cursor)) 123 153124 -1 return lines-1 154 yield from lines 125 155 126 156 def get_width(self, x): 127 157 return self.widths.get(x, 10) @@ -181,6 +211,10 @@ class App(boon.App): 181 211 self.on_key(key) 182 212 else: 183 213 self.input.on_key(key) -1 214 elif key == 'h': -1 215 self.help = not self.help -1 216 elif key == 'q' and self.help: -1 217 self.help = False 184 218 elif key == 'q': 185 219 self.running = False 186 220 elif key == boon.KEY_DOWN: