/ archive / python-cli-final / kamaji / ui / simple.py
simple.py
  1  """
  2  Simple terminal-based TUI without external dependencies.
  3  """
  4  
  5  import os
  6  import sys
  7  from rich.console import Console
  8  from rich.panel import Panel
  9  from rich.text import Text
 10  from kamaji import __version__
 11  
 12  
 13  class SimpleTUI:
 14      """Simple terminal-based TUI."""
 15      
 16      def __init__(self):
 17          self.console = Console()
 18          self.running = True
 19          self.messages = []
 20      
 21      def clear_screen(self):
 22          """Clear the terminal screen."""
 23          os.system('clear' if os.name == 'posix' else 'cls')
 24      
 25      def show_header(self):
 26          """Show the header."""
 27          header = Panel(
 28              f"[bold #ff6b35]šŸ”„ Kamaji • Many Handed Worker šŸ”„[/bold #ff6b35]\n"
 29              f"[#4ecdc4]Multi-Agent Intelligence System v{__version__}[/#4ecdc4]",
 30              style="on #8b0000",
 31              title_align="center"
 32          )
 33          self.console.print(header)
 34          self.console.print()
 35      
 36      def show_welcome(self):
 37          """Show welcome message."""
 38          welcome = Text()
 39          welcome.append("šŸš€ Welcome to Kamaji TUI!\n\n", style="bold #64ffda")
 40          welcome.append("Available commands:\n", style="bold #4ecdc4")
 41          welcome.append("• help - Show help\n", style="#e8eaed")
 42          welcome.append("• clear - Clear screen\n", style="#e8eaed")
 43          welcome.append("• echo <text> - Echo text\n", style="#e8eaed")
 44          welcome.append("• quit/exit - Exit TUI\n", style="#e8eaed")
 45          welcome.append("\nType your commands below:", style="#888888")
 46          
 47          panel = Panel(
 48              welcome,
 49              title="[bold #667eea]šŸ“š Getting Started[/bold #667eea]",
 50              border_style="#667eea"
 51          )
 52          self.console.print(panel)
 53          self.console.print()
 54      
 55      def user_message(self, text: str):
 56          """Display user message."""
 57          panel = Panel(
 58              f"[bold #ffffff]{text}[/bold #ffffff]",
 59              title="[bold #ffffff]šŸ‘¤ You[/bold #ffffff]",
 60              style="on #34495e",
 61              title_align="left"
 62          )
 63          self.console.print(panel)
 64      
 65      def system_message(self, text: str, title: str = "āš™ļø System"):
 66          """Display system message."""
 67          panel = Panel(
 68              text,
 69              title=f"[bold #ffd600]{title}[/bold #ffd600]",
 70              border_style="#ffd600"
 71          )
 72          self.console.print(panel)
 73      
 74      def agent_response(self, text: str, arm_id: int = 1):
 75          """Display agent response."""
 76          colors = ["#ff6b35", "#4ecdc4", "#45b7d1", "#96ceb4", "#feca57", "#ff9ff3"]
 77          ordinals = ["1st", "2nd", "3rd", "4th", "5th", "6th"]
 78          
 79          color = colors[(arm_id - 1) % len(colors)]
 80          ordinal = ordinals[arm_id - 1] if arm_id <= 6 else f"{arm_id}th"
 81          
 82          panel = Panel(
 83              text,
 84              title=f"[bold {color}]šŸ”„ Kamaji's {ordinal} Arm[/bold {color}]",
 85              border_style=color
 86          )
 87          self.console.print(panel)
 88      
 89      def error_message(self, text: str):
 90          """Display error message."""
 91          panel = Panel(
 92              text,
 93              title="[bold #ff5252]āš ļø Error[/bold #ff5252]",
 94              border_style="#ff5252"
 95          )
 96          self.console.print(panel)
 97      
 98      def process_command(self, command: str):
 99          """Process user command."""
100          command = command.strip()
101          if not command:
102              return
103          
104          # Show user input
105          self.user_message(command)
106          
107          # Handle commands
108          if command.lower() in ['quit', 'exit']:
109              self.system_message("Goodbye! šŸ‘‹")
110              self.running = False
111              return
112          
113          if command.lower() == 'clear':
114              self.clear_screen()
115              self.show_header()
116              self.system_message("Screen cleared!")
117              return
118          
119          if command.lower() == 'help':
120              self.show_welcome()
121              return
122          
123          if command.lower().startswith('echo '):
124              self.system_message(command[5:], "šŸ“¢ Echo")
125              return
126          
127          # Default response
128          self.agent_response(f"Processing: {command}")
129          self.console.print()
130      
131      def run(self):
132          """Run the TUI."""
133          try:
134              self.clear_screen()
135              self.show_header()
136              self.show_welcome()
137              
138              while self.running:
139                  try:
140                      # Get user input
141                      user_input = input("\nšŸ’¬ > ")
142                      self.process_command(user_input)
143                      
144                  except KeyboardInterrupt:
145                      self.console.print("\n")
146                      self.system_message("Interrupted! Use 'quit' to exit cleanly.")
147                      continue
148                      
149                  except EOFError:
150                      break
151          
152          except Exception as e:
153              self.error_message(f"TUI Error: {str(e)}")
154          
155          finally:
156              self.console.print("\n[dim]Thanks for using Kamaji! šŸ”„[/dim]")
157  
158  
159  def run_simple_tui():
160      """Run the simple TUI."""
161      tui = SimpleTUI()
162      tui.run()
163  
164  
165  if __name__ == "__main__":
166      run_simple_tui()