Method: Net::SSH::Connection::Channel#request_pty

Defined in:
lib/net/ssh/connection/channel.rb

#request_pty(opts = {}, &block) ⇒ Object

Requests that a pseudo-tty (or “pty”) be made available for this channel. This is useful when you want to invoke and interact with some kind of screen-based program (e.g., vim, or some menuing system).

Note, that without a pty some programs (e.g. sudo, or subversion) on some systems, will not be able to run interactively, and will error instead of prompt if they ever need some user interaction.

Note, too, that when a pty is requested, user’s shell configuration scripts (.bashrc and such) are not run by default, whereas they are run when a pty is not present.

channel.request_pty do |ch, success|
  if success
    puts "pty successfully obtained"
  else
    puts "could not obtain pty"
  end
end

Raises:

  • (ArgumentError)


218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/net/ssh/connection/channel.rb', line 218

def request_pty(opts={}, &block)
  extra = opts.keys - VALID_PTY_OPTIONS.keys
  raise ArgumentError, "invalid option(s) to request_pty: #{extra.inspect}" if extra.any?

  opts = VALID_PTY_OPTIONS.merge(opts)

  modes = opts[:modes].inject(Buffer.new) do |memo, (mode, data)|
    memo.write_byte(mode).write_long(data)
  end
  # mark the end of the mode opcode list with a 0 byte
  modes.write_byte(0)

  send_channel_request("pty-req", :string, opts[:term],
    :long, opts[:chars_wide], :long, opts[:chars_high],
    :long, opts[:pixels_wide], :long, opts[:pixels_high],
    :string, modes.to_s, &block)
end