Class: Yildun::Console
- Inherits:
-
Object
- Object
- Yildun::Console
- Defined in:
- lib/yildun/console.rb,
sig/yildun.rbs
Instance Method Summary collapse
-
#initialize(terminal, input: $stdin, output: $stdout) ⇒ Console
constructor
A new instance of Console.
- #render ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(terminal, input: $stdin, output: $stdout) ⇒ Console
Returns a new instance of Console.
7 8 9 |
# File 'lib/yildun/console.rb', line 7 def initialize(terminal, input: $stdin, output: $stdout) @terminal, @input, @output = terminal, input, output end |
Instance Method Details
#render ⇒ Object
34 35 36 37 38 |
# File 'lib/yildun/console.rb', line 34 def render @output.write("\e[H") @terminal.screen.lines.each { |line| @output.write("\e[2K#{line}\r\n") } @output.flush end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yildun/console.rb', line 11 def run return render unless @input.tty? && @output.tty? && @input.respond_to?(:raw) @input.raw do @output.write("\e[?25l") loop do resize @terminal.pump(timeout: 0.02) render break unless @terminal.session.alive? next unless IO.select([@input], nil, nil, 0.02) @terminal.input(@input.read_nonblock(4096)) rescue IO::WaitReadable retry rescue EOFError, Errno::EIO break end ensure @output.write("\e[0m\e[?25h\e[H\e[2J") end end |