Sha256: a06a7f00900df5271862a7a84612b902f62cae190d04f74909610a6582aea3a1

Contents?: true

Size: 814 Bytes

Versions: 3

Compression:

Stored size: 814 Bytes

Contents

require 'io/console'

require_relative '../support/esc'

module Vedeu
  module Terminal
    extend self
    # :nocov:
    def open(&block)
      console.cooked do
        output Esc.string('reset')
        output Esc.string('clear')
        output Esc.string('hide_cursor')

        yield
      end if block_given?
    ensure
      output Esc.string('show_cursor')
      output Esc.string('reset')
      output Esc.clear_last_line
    end
    # :nocov:

    def input
      console.gets.chomp
    end

    def output(stream = '')
      console.print(stream)

      stream
    end

    def centre
      [(height / 2), (width / 2)]
    end

    def width
      size.last
    end

    def height
      size.first
    end

    def size
      console.winsize
    end

    def console
      IO.console
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.0.34 lib/vedeu/support/terminal.rb
vedeu-0.0.33 lib/vedeu/support/terminal.rb
vedeu-0.0.32 lib/vedeu/support/terminal.rb