Class: TTY::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/terminal.rb,
lib/tty/terminal/raw.rb,
lib/tty/terminal/echo.rb,
lib/tty/terminal/home.rb,
lib/tty/terminal/pager.rb,
lib/tty/terminal/pager/basic.rb,
lib/tty/terminal/pager/system.rb

Defined Under Namespace

Classes: BasicPager, Echo, Home, Pager, Raw, SystemPager

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Terminal

Initialize a Terminal



22
23
24
25
26
27
28
# File 'lib/tty/terminal.rb', line 22

def initialize(options = {})
  @color = Pastel.new
  @echo  = TTY::Terminal::Echo.new
  @raw   = TTY::Terminal::Raw.new
  @pager = TTY::Terminal::Pager
  @home  = Home.new
end

Instance Attribute Details

#colorTTY::Terminal::Color (readonly)

Return access to color terminal

Returns:

  • (TTY::Terminal::Color)


10
11
12
# File 'lib/tty/terminal.rb', line 10

def color
  @color
end

#pagerTTY::Terminal::Pager (readonly)

Output pager



17
18
19
# File 'lib/tty/terminal.rb', line 17

def pager
  @pager
end

Instance Method Details

#echo(is_on = true, &block) ⇒ Object

Echo given block

Parameters:

  • is_on (Boolean) (defaults to: true)


49
50
51
# File 'lib/tty/terminal.rb', line 49

def echo(is_on = true, &block)
  @echo.echo(is_on, &block)
end

#echo_offObject

Switch echo off



40
41
42
# File 'lib/tty/terminal.rb', line 40

def echo_off
  @echo.off
end

#echo_onObject

Switch echo on



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

def echo_on
  @echo.on
end

#homeString

Find user home directory

Returns:

  • (String)


81
82
83
# File 'lib/tty/terminal.rb', line 81

def home
  @home.home
end

#page(text) ⇒ Object

Run text through a dynamically chosen pager

Parameters:

  • text (String)

    the text to page



91
92
93
# File 'lib/tty/terminal.rb', line 91

def page(text)
  @pager.page(text)
end

#raw(is_on = true, &block) ⇒ Object

Use raw mode in the given block

Parameters:

  • is_on (Boolean) (defaults to: true)


72
73
74
# File 'lib/tty/terminal.rb', line 72

def raw(is_on = true, &block)
  @raw.raw(is_on, &block)
end

#raw_offObject

Switch raw mode off



63
64
65
# File 'lib/tty/terminal.rb', line 63

def raw_off
  @raw.off
end

#raw_onObject

Switch raw mode on



56
57
58
# File 'lib/tty/terminal.rb', line 56

def raw_on
  @raw.on
end