core.py
1 """ 2 Core TUI application. 3 """ 4 5 from textual.app import App 6 from textual.containers import Container 7 from textual.widgets import Header 8 from textual.binding import Binding 9 from textual import ComposeResult 10 11 from .widgets import MessagePane, CommandInput 12 from .handlers import MessageHandler, CommandProcessor 13 14 15 class TUIApp(App): 16 """Main TUI application.""" 17 18 CSS = """ 19 Screen { background: #0f0f23; color: #e8eaed; } 20 Header { background: #8b0000; color: #ffffff; height: 3; } 21 #messages { height: 1fr; border: round #444444; } 22 #messages:focus { border: round #00f2fe; } 23 #input { height: 3; border: round #64ffda; } 24 #input:focus { border: round #00f2fe; } 25 """ 26 27 BINDINGS = [ 28 Binding("ctrl+c", "quit", "Exit"), 29 Binding("ctrl+l", "clear", "Clear"), 30 Binding("tab", "focus_next", "Tab"), 31 ] 32 33 TITLE = "🔥 Kamaji • Many Handed Worker 🔥" 34 35 def __init__(self, **kwargs): 36 super().__init__() 37 self.message_handler = None 38 self.command_processor = None 39 40 def compose(self) -> ComposeResult: 41 yield Header() 42 with Container(): 43 yield MessagePane(id="messages") 44 yield CommandInput(id="input") 45 46 async def on_mount(self) -> None: 47 messages = self.query_one("#messages", MessagePane) 48 input_widget = self.query_one("#input", CommandInput) 49 50 self.message_handler = MessageHandler(messages) 51 self.command_processor = CommandProcessor(self, self.message_handler) 52 53 # Show welcome 54 self.message_handler.show_welcome() 55 56 def on_command_input_submitted(self, event) -> None: 57 self.command_processor.process(event.value) 58 event.input.value = "" 59 60 def action_clear(self) -> None: 61 self.message_handler.clear() 62 63 def action_quit(self) -> None: 64 self.exit() 65 66 67 def run_tui(**kwargs): 68 """Run the TUI application.""" 69 app = TUIApp(**kwargs) 70 app.run()