Class: Yatte::Terminal
- Inherits:
-
Object
- Object
- Yatte::Terminal
- Defined in:
- lib/yatte/terminal.rb
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(stdin: $stdin, stdout: $stdout, console: IO.console) ⇒ Terminal
constructor
A new instance of Terminal.
- #raw_mode(&block) ⇒ Object
- #read_byte ⇒ Object
- #read_byte_nonblocking(timeout: 0.05) ⇒ Object
- #size ⇒ Object
- #write(string) ⇒ Object
Constructor Details
#initialize(stdin: $stdin, stdout: $stdout, console: IO.console) ⇒ Terminal
Returns a new instance of Terminal.
5 6 7 8 9 |
# File 'lib/yatte/terminal.rb', line 5 def initialize(stdin: $stdin, stdout: $stdout, console: IO.console) @stdin = stdin @stdout = stdout @console = console end |
Instance Method Details
#flush ⇒ Object
33 34 35 |
# File 'lib/yatte/terminal.rb', line 33 def flush @stdout.flush end |
#raw_mode(&block) ⇒ Object
15 16 17 |
# File 'lib/yatte/terminal.rb', line 15 def raw_mode(&block) @console.raw(&block) end |
#read_byte ⇒ Object
19 20 21 |
# File 'lib/yatte/terminal.rb', line 19 def read_byte @stdin.readpartial(1) end |
#read_byte_nonblocking(timeout: 0.05) ⇒ Object
23 24 25 26 27 |
# File 'lib/yatte/terminal.rb', line 23 def read_byte_nonblocking(timeout: 0.05) return nil unless IO.select([@stdin], nil, nil, timeout) @stdin.readpartial(1) end |
#size ⇒ Object
11 12 13 |
# File 'lib/yatte/terminal.rb', line 11 def size @console.winsize end |
#write(string) ⇒ Object
29 30 31 |
# File 'lib/yatte/terminal.rb', line 29 def write(string) @stdout.write(string) end |