diff --git a/src/tt/tui.py b/src/tt/tui.py index f6f6034..6a2f122 100644 --- a/src/tt/tui.py +++ b/src/tt/tui.py @@ -1,6 +1,7 @@ +import re from textual.app import App -from textual.widgets import DataTable, Header, Input -from textual.containers import Container +from textual.widgets import DataTable, Header, Input, Static +from textual.containers import Container, Horizontal from datetime import datetime from .controller import get_tasks, add_task, update_task, TaskStatus @@ -15,6 +16,11 @@ column_to_field = { } +def remove_rich_tag(text): + pattern = r"\[[^\]]*\](.*?)\[/\]" + return re.sub(pattern, r"\1", text) + + def get_colored_status(status: str) -> str: colors = { "zero": "#666666", @@ -34,12 +40,23 @@ def get_colored_category(category: str) -> str: class TaskManagerApp(App): CSS = """ - Input { + #input_bar { dock: bottom; + height: 1; + layout: grid; + grid-size: 2; + grid-columns: 10 1fr; + } + + #prompt_label { + width: 10; + content-align: left middle; + } + + #input_widget { + width: 100%; margin: 0; - padding: 0; border: none; - background: $boost; } """ @@ -69,11 +86,14 @@ class TaskManagerApp(App): def compose(self): self.header = Header() self.table = DataTable() - self.input_bar = Input(id="input_bar") - self.input_bar.display = False + self.input_widget = Input(id="input_widget") + self.input_label = Static("label", id="prompt_label") + self.input_bar = Container(id="input_bar") yield self.header yield Container(self.table) - yield self.input_bar + with self.input_bar: + yield self.input_label + yield self.input_widget def on_mount(self): self.table.add_columns("ID", "Task", "Status", "Type", "Due", "Category") @@ -133,8 +153,12 @@ class TaskManagerApp(App): def _show_input(self, mode, start_value): self.mode = mode self.input_bar.display = True - self.input_bar.value = start_value - self.set_focus(self.input_bar) + self.input_widget.value = start_value + if mode == "search": + self.input_label.update("search: ") + else: + self.input_label.update("edit: ") + self.set_focus(self.input_widget) def _hide_input(self): self.input_bar.display = False @@ -154,7 +178,7 @@ class TaskManagerApp(App): current_value = self.table.get_cell_at( (self.table.cursor_row, self.table.cursor_column) ) - # TODO: remove color codes + current_value = remove_rich_tag(current_value) self._show_input("edit", current_value) def on_input_submitted(self, event: Input.Submitted):