class Pytty::Client::Api::Yield

Public Class Methods

run(cmd:, id:, env:) click to toggle source
# File lib/pytty/client/api/yield.rb, line 5
def self.run(cmd:, id:, env:)
  internet = Async::HTTP::Internet.new
  headers = [['accept', 'application/json']]

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

  body = {
    id: id,
    cmd: cmd,
    env: term_env
  }.to_json

  response = internet.post("#{Pytty::Client.host_url}/v1/yield", headers, [body])
  [response, JSON.parse(response.body.read)]
end