Module: Remedy::Console
- Defined in:
- lib/remedy/console.rb,
lib/remedy/console_resize.rb
Defined Under Namespace
Modules: Resize
Classes: UnknownConsoleSize
Constant Summary
collapse
- TIOCGWINSZ =
case RbConfig::CONFIG['host_os']
when /darwin|mac os/
0x40087468
when /linux/
0x5413
else
0x00
end
Class Method Summary
collapse
Class Method Details
.columns ⇒ Object
Also known as:
width
44
45
46
|
# File 'lib/remedy/console.rb', line 44
def columns
size.cols
end
|
.cooked! ⇒ Object
39
40
41
42
|
# File 'lib/remedy/console.rb', line 39
def cooked!
input.echo = true
input.cooked!
end
|
18
19
20
|
# File 'lib/remedy/console.rb', line 18
def input
@input ||= $stdin
end
|
.interactive? ⇒ Boolean
63
64
65
|
# File 'lib/remedy/console.rb', line 63
def interactive?
input.isatty
end
|
.output ⇒ Object
22
23
24
|
# File 'lib/remedy/console.rb', line 22
def output
@output ||= $stdout
end
|
.raw ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/remedy/console.rb', line 26
def raw
raw!
result = yield
ensure
cooked!
return result
end
|
.raw! ⇒ Object
34
35
36
37
|
# File 'lib/remedy/console.rb', line 34
def raw!
input.echo = false
input.raw!
end
|
.rows ⇒ Object
Also known as:
height
49
50
51
|
# File 'lib/remedy/console.rb', line 49
def rows
size.rows
end
|
.set_console_resized_hook! ⇒ Object
.size ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/remedy/console.rb', line 54
def size
str = [0, 0, 0, 0].pack('SSSS')
if input.ioctl(TIOCGWINSZ, str) >= 0 then
Size.new str.unpack('SSSS').first 2
else
raise UnknownConsoleSize, "Unable to get console size"
end
end
|