Sha256: d530ebbe63f0d979a6df766abdc152ee99742918a736356b3337970249ec3b21

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

module ANSI

  module Terminal
    module_function

    #COLS_FALLBACK = 80
    #ROWS_FALLBACK = 25

    #CHARACTER_MODE = "stty"    # For Debugging purposes only.

    #
    # Unix savvy getc().  (Second choice.)
    #
    # *WARNING*:  This method requires the external "stty" program!
    #
    def get_character( input = STDIN )
      raw_no_echo_mode

      begin
        input.getc
      ensure
        restore_mode
      end
    end

    #
    # Switched the input mode to raw and disables echo.
    #
    # *WARNING*:  This method requires the external "stty" program!
    #
    def raw_no_echo_mode
      @state = `stty -g`
      system "stty raw -echo cbreak isig"
    end

    #
    # Restores a previously saved input mode.
    #
    # *WARNING*:  This method requires the external "stty" program!
    #
    def restore_mode
      system "stty #{@state}"
    end

    # A Unix savvy method to fetch the console columns, and rows.
    def terminal_size
      if /solaris/ =~ RUBY_PLATFORM && (`stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/)
        w, r = [$2, $1]
      else
        w, r = `stty size`.split.reverse
      end
      w = `tput cols` unless w  # last ditch effort to at least get width

      w = w.to_i if w
      r = r.to_i if r

      return w, r
    end

  end

end

Version data entries

15 entries across 15 versions & 5 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-1.0.0 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
swipe-rails-0.0.5 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-1.0.0.beta3 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-1.0.0.beta2 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-1.0.0.beta vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-0.9.1.beta.3 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-0.9.1.beta vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-0.9.0 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
challah-0.8.3 vendor/bundle/gems/ansi-1.4.3/lib/ansi/terminal/stty.rb
ansi-1.4.3 lib/ansi/terminal/stty.rb
challah-0.6.1 vendor/bundle/gems/ansi-1.4.2/lib/ansi/terminal/stty.rb
challah-0.6.0 vendor/bundle/gems/ansi-1.4.2/lib/ansi/terminal/stty.rb
ansi-1.4.2 lib/ansi/terminal/stty.rb