diff --git a/src/tt/cli.py b/src/tt/cli.py index 684b0b4..38a34f3 100644 --- a/src/tt/cli.py +++ b/src/tt/cli.py @@ -4,7 +4,8 @@ import lxml.html from typing_extensions import Annotated from .controller import add_task from .import_csv import import_tasks_from_csv -from . import tui +from .db import initialize_db +from .tui import tasks app = typer.Typer() @@ -16,6 +17,7 @@ def new( due: Annotated[str, typer.Option("-d", "--due", help="due")] = "", url: Annotated[str, typer.Option("-u", "--url", help="URL")] = "", ): + initialize_db() required = ["name", "category"] if url and not name: @@ -42,7 +44,8 @@ def new( def browse( view: Annotated[str, typer.Option("-v", "--view", help="saved view")] = "default", ): - tui.run(view) + initialize_db() + tasks.run(view) @app.command() diff --git a/src/tt/tui_editor.py b/src/tt/tui/editor.py similarity index 97% rename from src/tt/tui_editor.py rename to src/tt/tui/editor.py index c8e39c1..1a99f3a 100644 --- a/src/tt/tui_editor.py +++ b/src/tt/tui/editor.py @@ -7,13 +7,13 @@ from textual.widgets import ( ) from textual.containers import Container -from .utils import ( +from ..utils import ( remove_rich_tag, filter_to_string, advance_enum_val, get_text_from_editor, ) -from .tui_keybindings import KeyBindingsScreen +from .keymodal import KeyModal class NotifyValidationError(Exception): @@ -285,7 +285,7 @@ class TableEditor(App): cconf = self._active_column_config() if cconf.filterable: return - cur_filter_val = self.filters.get(cconf.name) or "" + cur_filter_val = self.filters.get(cconf.field) or "" self._show_input("filter", cur_filter_val) self.table.cursor_type = "column" @@ -299,7 +299,7 @@ class TableEditor(App): if self.table.cursor_row is None or self.table.cursor_column == 0: return - self._save_crefresh_data() + self._save_cursor() current_value = self.table.get_cell_at( (self.table.cursor_row, self.table.cursor_column) ) @@ -334,7 +334,7 @@ class TableEditor(App): self.refresh_data(restore_cursor=False) elif self.mode == "filter": cconf = self._active_column_config() - self.filters[cconf.name] = event.value + self.filters[cconf.field] = event.value self.refresh_data(restore_cursor=False) self.table.cursor_type = "cel" elif self.mode == "sort": @@ -350,12 +350,12 @@ class TableEditor(App): row, col = self.saved_cursor_pos item_id = int(self.table.get_cell_at((row, 0))) cconf = self.TABLE_CONFIG[col] - field = cconf.name + field = cconf.field update_data = {} # preprocess/validate the field being saved try: - update_data[field] = cconf.preprocess(new_value) + update_data[field] = cconf.preprocessor(new_value) self.update_item_callback(item_id, **update_data) self.refresh_data() except NotifyValidationError as e: @@ -367,4 +367,4 @@ class TableEditor(App): self.action_cancel_edit() def action_show_keys(self): - self.push_screen(KeyBindingsScreen()) + self.push_screen(KeyModal()) diff --git a/src/tt/tui_keybindings.py b/src/tt/tui/keymodal.py similarity index 96% rename from src/tt/tui_keybindings.py rename to src/tt/tui/keymodal.py index 66418da..23ed577 100644 --- a/src/tt/tui_keybindings.py +++ b/src/tt/tui/keymodal.py @@ -3,7 +3,7 @@ from rich.table import Table from textual.widgets import Static -class KeyBindingsScreen(ModalScreen): +class KeyModal(ModalScreen): CSS = """ KeyBindingsScreen { align: center middle; diff --git a/src/tt/tui.py b/src/tt/tui/tasks.py similarity index 97% rename from src/tt/tui.py rename to src/tt/tui/tasks.py index 8cd8e64..4acca0c 100644 --- a/src/tt/tui.py +++ b/src/tt/tui/tasks.py @@ -2,7 +2,7 @@ import json from textual.widgets import Input from datetime import datetime -from .controller import ( +from ..controller import ( get_task, get_tasks, add_task, @@ -11,13 +11,12 @@ from .controller import ( save_view, get_saved_view, ) -from .db import initialize_db -from .utils import ( +from ..utils import ( get_colored_category, get_colored_status, get_colored_date, ) -from .tui_editor import ( +from .editor import ( TableEditor, TableColumnConfig, NotifyValidationError,