class HighLine::Terminal::UnixStty

HighLine::Terminal option that uses external “stty” program to control terminal options.

Public Instance Methods

get_character(input = STDIN) click to toggle source

(see HighLine::Terminal#get_character)

# File lib/highline/terminal/unix_stty.rb, line 45
def get_character(input = STDIN)
  input.getc
end
raw_no_echo_mode() click to toggle source

(see HighLine::Terminal#raw_no_echo_mode)

# File lib/highline/terminal/unix_stty.rb, line 33
def raw_no_echo_mode
  @state = %xstty -g`
  system "stty raw -echo -icanon isig"
end
restore_mode() click to toggle source

(see HighLine::Terminal#restore_mode)

# File lib/highline/terminal/unix_stty.rb, line 39
def restore_mode
  system "stty #{@state}"
  print "\r"
end
terminal_size() click to toggle source

A Unix savvy method using stty to fetch the console columns, and rows. … stty does not work in JRuby @return (see HighLine::Terminal#terminal_size)

# File lib/highline/terminal/unix_stty.rb, line 10
def terminal_size
  begin
    require "io/console"
    winsize = begin
                IO.console.winsize.reverse
              rescue NoMethodError
                nil
              end
    return winsize if winsize
  rescue LoadError
  end

  if /solaris/ =~ RUBY_PLATFORM &&
     %xstty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
    [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i)
  elsif %xstty size` =~ /^(\d+)\s(\d+)$/
    [Regexp.last_match(2).to_i, Regexp.last_match(1).to_i]
  else
    [80, 24]
  end
end