Class: Airstream::Io

Inherits:
Object
  • Object
show all
Defined in:
lib/airstream/io.rb

Constant Summary collapse

KEY_QUIT =
'q'
KEY_SKIP =
'>'
KEY_PREV =
'<'
KEY_FWD =
'.'
KEY_BACK =
','
KEY_PAUSE =
' '

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key


14
15
16
# File 'lib/airstream/io.rb', line 14

def key
  @key
end

#quiet=(value) ⇒ Object (writeonly)

Sets the attribute quiet

Parameters:

  • value

    the value to set the attribute quiet to.


13
14
15
# File 'lib/airstream/io.rb', line 13

def quiet=(value)
  @quiet = value
end

#verbose=(value) ⇒ Object (writeonly)

Sets the attribute verbose

Parameters:

  • value

    the value to set the attribute verbose to.


13
14
15
# File 'lib/airstream/io.rb', line 13

def verbose=(value)
  @verbose = value
end

Class Method Details

.hide_inputObject


32
33
34
# File 'lib/airstream/io.rb', line 32

def self.hide_input
  `stty raw -echo`
end

.show_inputObject


36
37
38
# File 'lib/airstream/io.rb', line 36

def self.show_input
  `stty -raw echo`
end

Instance Method Details

#back?Boolean

Returns:

  • (Boolean)

65
66
67
# File 'lib/airstream/io.rb', line 65

def back?
  @key == KEY_BACK
end

#catch_inputObject


40
41
42
43
44
45
46
47
# File 'lib/airstream/io.rb', line 40

def catch_input
  @key = nil
  if STDIN.ready?
    @key = STDIN.getc
  end
rescue
  show_input
end

#error(msg) ⇒ Object


28
29
30
# File 'lib/airstream/io.rb', line 28

def error(msg)
  STDERR.puts msg
end

#fwd?Boolean

Returns:

  • (Boolean)

61
62
63
# File 'lib/airstream/io.rb', line 61

def fwd?
  @key == KEY_FWD
end

#info(msg) ⇒ Object


24
25
26
# File 'lib/airstream/io.rb', line 24

def info(msg)
  STDOUT.puts msg if @verbose
end

#pause?Boolean

Returns:

  • (Boolean)

69
70
71
# File 'lib/airstream/io.rb', line 69

def pause?
  @key == KEY_PAUSE
end

#prev?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/airstream/io.rb', line 57

def prev?
  @key == KEY_PREV
end

16
17
18
# File 'lib/airstream/io.rb', line 16

def print(msg)
  STDOUT.print msg unless @quiet
end

#puts(msg) ⇒ Object


20
21
22
# File 'lib/airstream/io.rb', line 20

def puts(msg)
  STDOUT.puts msg unless @quiet
end

#quit?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'lib/airstream/io.rb', line 49

def quit?
  @key == KEY_QUIT
end

#skip?Boolean

Returns:

  • (Boolean)

53
54
55
# File 'lib/airstream/io.rb', line 53

def skip?
  @key == KEY_SKIP
end