spreadsheet

terminal spreadsheet application
git clone https://git.ce9e.org/spreadsheet.git

commit
005b87e1c8433d5c691dec546b37c3f89532cac0
parent
ab85e2e6055a2fab8da507d2e795624a17b62caf
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-07-20 17:45
allow to write csv

Diffstat

M sheet/__main__.py 32 ++++++++++++++++++++++++++++++--

1 files changed, 30 insertions, 2 deletions


diff --git a/sheet/__main__.py b/sheet/__main__.py

@@ -37,8 +37,9 @@ def to_cell(value: float|int|str|None|Exception, width: int) -> str:
   37    37 class App(boon.App):
   38    38     def __init__(self, path=None):
   39    39         super().__init__()
   -1    40         self.path = path or ''
   40    41         if path:
   41    -1             with open(path) as fh:
   -1    42             with open(self.path) as fh:
   42    43                 self.sheet = load_csv(fh)
   43    44         else:
   44    45             self.sheet = Sheet()
@@ -139,6 +140,17 @@ class App(boon.App):
  139   140     def cancel_input(self):
  140   141         self.input = None
  141   142 
   -1   143     def submit_write(self):
   -1   144         with open(self.input.value, 'w') as fh:
   -1   145             dump_csv(self.sheet, fh)
   -1   146         self.input = None
   -1   147 
   -1   148     def submit_write_eval(self):
   -1   149         self.path = self.input.value
   -1   150         with open(self.path, 'w') as fh:
   -1   151             dump_csv(self.sheet, fh, display=True)
   -1   152         self.input = None
   -1   153 
  142   154     def submit_drag(self):
  143   155         raw = self.sheet.get_raw(self.drag)
  144   156         if raw.startswith('='):
@@ -201,11 +213,27 @@ class App(boon.App):
  201   213             self.sheet.set(self.cursor, '')
  202   214         elif key == '#':
  203   215             self.drag = self.cursor
   -1   216         elif key == 'w':
   -1   217             self.input = Input(
   -1   218                 self.path,
   -1   219                 self.submit_write,
   -1   220                 self.cancel_input,
   -1   221                 prompt='Write: ',
   -1   222                 full=True,
   -1   223             )
   -1   224         elif key == 'W':
   -1   225             self.input = Input(
   -1   226                 self.path,
   -1   227                 self.submit_write_eval,
   -1   228                 self.cancel_input,
   -1   229                 prompt='Write (evaluated): ',
   -1   230                 full=True,
   -1   231             )
  204   232 
  205   233 
  206   234 def get_parser():
  207   235     parser = argparse.ArgumentParser()
  208    -1     parser.add_argument('path', nargs='?')
   -1   236     parser.add_argument('path', default='', nargs='?')
  209   237     parser.add_argument('--eval')
  210   238     return parser
  211   239