def websocket_exec_write_thread(ws, tty: nil)
      Thread.new do
        begin
          if tty
            console_height, console_width = TTY::Screen.size
            websocket_exec_write(ws, 'tty_size' => {
              width: console_width, height: console_height
            })
          end
          read_stdin(tty: tty) do |stdin|
            logger.debug "websocket exec stdin with encoding=#{stdin.encoding}: #{stdin.inspect}"
            websocket_exec_write(ws, 'stdin' => stdin)
          end
          websocket_exec_write(ws, 'stdin' => nil) # EOF
        rescue => exc
          logger.error exc
          ws.close(1001, "stdin read #{exc.class}: #{exc}")
        end
      end
    end
def websocket_exec_write_thread(ws, tty: nil)
      Thread.new do
        begin
          if tty
            console_height, console_width = TTY::Screen.size
            websocket_exec_write(ws, 'tty_size' => {
              width: console_width, height: console_height
            })
          end
          read_stdin(tty: tty) do |stdin|
            logger.debug "websocket exec stdin with encoding=#{stdin.encoding}: #{stdin.inspect}"
            websocket_exec_write(ws, 'stdin' => stdin)
          end
          websocket_exec_write(ws, 'stdin' => nil) # EOF
        rescue => exc
          logger.error exc
          ws.close(1001, "stdin read #{exc.class}: #{exc}")
        end
      end
    end
Start thread to read from stdin, and write to websocket.
 Closes websocket on stdin read errors.

 @param ws [Kontena::Websocket::Client]
 @param tty [Boolean]
 @return [Thread]