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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pytty/client/cli/stream_command.rb', line 13

def execute

  $stdin.raw!
  $stdin.echo = false
  Async::Reactor.run do |task|
    async_stdin = Async::IO::Stream.new(
      Async::IO::Generic.new($stdin)
    )

    while c = async_stdin.read(1) do
      case c
      when "\x01"
        print "\r"
      when "\x03"
        puts "\r\n\nctrl+c\n\r"
        break
      when "\r"
        print "\n\r"
      when "\e"
        print c
        print async_stdin.read(2)
      else
        print c.inspect
#                print c
#                p c
      end
    end
  end

  exit 0

  #---------------
  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