Class: Kodo::Channels::Console
- Defined in:
- lib/kodo/channels/console.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #connect! ⇒ Object
- #disconnect! ⇒ Object
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #poll ⇒ Object
-
#push(text) ⇒ Object
Push a message into the inbox (called from CLI input thread).
- #send_message(message) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
6 7 8 9 |
# File 'lib/kodo/channels/console.rb', line 6 def initialize @inbox = Queue.new super(channel_id: "console") end |
Instance Method Details
#connect! ⇒ Object
11 12 13 14 15 |
# File 'lib/kodo/channels/console.rb', line 11 def connect! @running = true Kodo.logger.info("Console channel ready") self end |
#disconnect! ⇒ Object
17 18 19 |
# File 'lib/kodo/channels/console.rb', line 17 def disconnect! @running = false end |
#poll ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/kodo/channels/console.rb', line 21 def poll = [] << @inbox.pop(true) until @inbox.empty? rescue ThreadError # Queue.pop(true) raises ThreadError when empty end |
#push(text) ⇒ Object
Push a message into the inbox (called from CLI input thread)
35 36 37 38 39 40 41 42 |
# File 'lib/kodo/channels/console.rb', line 35 def push(text) @inbox << Message.new( channel_id: channel_id, sender: :user, content: text, metadata: { chat_id: "console" } ) end |
#send_message(message) ⇒ Object
30 31 32 |
# File 'lib/kodo/channels/console.rb', line 30 def () puts "\n\e[36mKodo:\e[0m #{.content}\n\n" end |