Class: Pytty::Client::Cli::StreamCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/pytty/client/cli/stream_command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pytty/client/cli/stream_command.rb', line 13

def execute
  env = {
    "LINES" => IO.console.winsize.first.to_s,
    "COLUMNS" => IO.console.winsize.last.to_s
  }

  url = "ws://localhost:1234/v1/stream"
  endpoint = Async::HTTP::URLEndpoint.parse url
  Async::Reactor.run do |task|
    endpoint.connect do |socket|
      connection = Async::WebSocket::Client.new socket, url

      connection.send_message({
        cmd: cmd_list,
        env: env
      })

      while message = connection.next_message
        print message
      end
    end
  end
end