Module: EasyIO::Terminal

Defined in:
lib/easy_io/terminal.rb

Class Method Summary collapse

Class Method Details

.columnsObject



25
26
27
# File 'lib/easy_io/terminal.rb', line 25

def columns
  dimensions.last
end

.dimensionsObject

returns [rows, columns]



12
13
14
15
16
17
18
19
# File 'lib/easy_io/terminal.rb', line 12

def dimensions
  require 'io/console'
  IO.console.winsize
rescue LoadError
  # This works with older Ruby, but only with systems
  # that have a tput(1) command, such as Unix clones.
  [Integer(`tput li`), Integer(`tput co`)]
end

.interactive?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/easy_io/terminal.rb', line 33

def interactive?
  $stdout.isatty
end

.line(filler_character) ⇒ Object



29
30
31
# File 'lib/easy_io/terminal.rb', line 29

def line(filler_character)
  filler_character * (Terminal.columns - 1)
end

.rowsObject



21
22
23
# File 'lib/easy_io/terminal.rb', line 21

def rows
  dimensions.first
end

.sync_outputObject

Forces real-time output



6
7
8
9
# File 'lib/easy_io/terminal.rb', line 6

def sync_output
  $stdout.sync = true
  $stderr.sync = true
end