Class: Kreator::InteractiveCLI::ChatModel
- Inherits:
-
Object
- Object
- Kreator::InteractiveCLI::ChatModel
- Defined in:
- lib/kreator/interactive_cli.rb
Constant Summary collapse
- CHAT_KEY_HANDLERS =
{ "ctrl+c" => :quit_update, "esc" => :quit_update, "ctrl+m" => :open_model_picker_update, "ctrl+r" => :open_session_picker_update, "ctrl+t" => :toggle_next_tool_update, "ctrl+s" => :save_draft_update, "enter" => :submit_prompt_update, "alt+enter" => :insert_newline_update }.freeze
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize(runtime:) ⇒ ChatModel
constructor
A new instance of ChatModel.
- #update(message) ⇒ Object
- #view ⇒ Object
Constructor Details
#initialize(runtime:) ⇒ ChatModel
Returns a new instance of ChatModel.
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/kreator/interactive_cli.rb', line 590 def initialize(runtime:) @runtime = runtime @lines = [runtime.welcome_panel, *runtime.transcript] @mode = :chat @model_list = nil @session_list = nil @draft_buffer = nil @textarea = Bubbles::TextArea.new(width: 80, height: 3) @textarea.placeholder = "Send a message..." @textarea.prompt = "> " @textarea.show_line_numbers = false @textarea.focus @viewport = Bubbles::Viewport.new(width: 88, height: 24) @title_style = defined?(Lipgloss) ? Lipgloss::Style.new.bold(true).foreground("#2D7D9A") : nil @status_style = defined?(Lipgloss) ? Lipgloss::Style.new.foreground("#6B7280") : nil end |
Instance Method Details
#init ⇒ Object
619 |
# File 'lib/kreator/interactive_cli.rb', line 619 def init = [self, @textarea.cursor.focus] |
#update(message) ⇒ Object
621 622 623 624 625 626 |
# File 'lib/kreator/interactive_cli.rb', line 621 def update() return update_window() if .is_a?(Bubbletea::WindowSizeMessage) return update_key() if .is_a?(Bubbletea::KeyMessage) update_inputs() end |
#view ⇒ Object
628 629 630 631 632 633 634 |
# File 'lib/kreator/interactive_cli.rb', line 628 def view title = styled(@title_style, "Kreator") status = styled(@status_style, status_text) return [title, status, "", picker_view].join("\n") unless @mode == :chat [title, status, "", @viewport.view, "", @textarea.view, autocomplete_panel, ].compact.join("\n") end |