Sha256: cb57e3bb0a05c69128121e1204506b77677afac5e67e81034ac1a33f04042f6f

Contents?: true

Size: 1.35 KB

Versions: 68

Compression:

Stored size: 1.35 KB

Contents

# coding: utf-8

class HighLine
  class Terminal
    # HighLine::Terminal option that uses external "stty" program
    # to control terminal options.
    class UnixStty < Terminal
      # A Unix savvy method using stty to fetch the console columns, and rows.
      # ... stty does not work in JRuby
      # @return (see Terminal#terminal_size)
      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 &&
           `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
          [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i)
        elsif `stty size` =~ /^(\d+)\s(\d+)$/
          [Regexp.last_match(2).to_i, Regexp.last_match(1).to_i]
        else
          [80, 24]
        end
      end

      # (see Terminal#raw_no_echo_mode)
      def raw_no_echo_mode
        @state = `stty -g`
        system "stty raw -echo -icanon isig"
      end

      # (see Terminal#restore_mode)
      def restore_mode
        system "stty #{@state}"
        print "\r"
      end

      # (see Terminal#get_character)
      def get_character(input = STDIN)
        input.getc
      end
    end
  end
end

Version data entries

68 entries across 54 versions & 3 rubygems

Version Path
brakeman-6.1.1 bundle/ruby/3.0.0/gems/highline-2.1.0/lib/highline/terminal/unix_stty.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/highline-2.1.0/lib/highline/terminal/unix_stty.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/highline-2.1.0/lib/highline/terminal/unix_stty.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/highline-2.1.0/lib/highline/terminal/unix_stty.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/highline-2.1.0/lib/highline/terminal/unix_stty.rb
highline-2.1.0 lib/highline/terminal/unix_stty.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.2.3 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.2.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.1.2 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.1.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.1.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.0.4 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.0.2 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.0.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb
brakeman-5.0.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/terminal/unix_stty.rb