From 2858c7e235f9efcbba62e93b327a26ca1a763445 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 30 May 2026 23:03:04 -0700 Subject: [PATCH] Update tui.py --- src/ui/tui.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/ui/tui.py b/src/ui/tui.py index fa4f0a2..6f08213 100644 --- a/src/ui/tui.py +++ b/src/ui/tui.py @@ -22,14 +22,20 @@ from src.persistence.lore import update_lore class EditModal(ModalScreen): - def __init__(self, initial_text: str, on_save: callable): + def __init__(self, initial_text: str, initial_type: str, initial_target: str, on_save: callable): super().__init__() self.initial_text = initial_text + self.initial_type = initial_type + self.initial_target = initial_target self.on_save = on_save def compose(self) -> ComposeResult: with Vertical(id="modal-container"): - yield Label("Edit Fact Content:") + yield Label("Type:") + yield Input(value=self.initial_type, id="edit-type") + yield Label("Target:") + yield Input(value=self.initial_target, id="edit-target") + yield Label("Content:") yield Input(value=self.initial_text, id="edit-input") with Horizontal(id="modal-actions"): yield Button("Save", id="btn-save") @@ -38,7 +44,9 @@ class EditModal(ModalScreen): def on_button_pressed(self, event: Button.Pressed) -> None: if event.button.id == "btn-save": edit_input = self.query_one("#edit-input", Input) - self.on_save(edit_input.value) + type_input = self.query_one("#edit-type", Input) + target_input = self.query_one("#edit-target", Input) + self.on_save(edit_input.value, type_input.value, target_input.value) self.dismiss() elif event.button.id == "btn-cancel": self.dismiss() @@ -109,7 +117,7 @@ class ConfirmationApp(App): align: right middle; } - #edit-input { + #edit-input, #edit-type, #edit-target { margin: 1 0; } @@ -199,7 +207,7 @@ class ConfirmationApp(App): table = self.query_one("#pending-facts-table", DataTable) if isinstance(update, LoreUpdate): table.add_row( - "Lore", update.entity_name or "General", update.content, key=str(index) + update.category, update.entity_name or "General", update.content, key=str(index) ) elif isinstance(update, CharacterStateUpdate): change_text = f"HP: {update.hp_change or 0}" @@ -292,24 +300,34 @@ class ConfirmationApp(App): update = self.pending_updates[row_index] initial_text = "" + initial_type = "" + initial_target = "" + if isinstance(update, LoreUpdate): initial_text = update.content + initial_type = update.category + initial_target = update.entity_name or "" elif isinstance(update, CharacterStateUpdate): initial_text = str(update.hp_change or 0) + initial_type = "Char" + initial_target = update.character_name - def save_callback(new_text: str): + def save_callback(new_text: str, new_type: str, new_target: str): if isinstance(update, LoreUpdate): update.content = new_text + update.category = new_type + update.entity_name = new_target if new_target else None elif isinstance(update, CharacterStateUpdate): try: update.hp_change = int(new_text) except ValueError: pass + update.character_name = new_target # Update the table self.refresh_table() - self.push_screen(EditModal(initial_text, save_callback)) + self.push_screen(EditModal(initial_text, initial_type, initial_target, save_callback)) def remove_update(self, index: int) -> None: del self.pending_updates[index]