Class: Echoes::Terminal
- Inherits:
-
Object
- Object
- Echoes::Terminal
- Defined in:
- lib/echoes/terminal.rb
Instance Attribute Summary collapse
-
#screen ⇒ Object
readonly
Returns the value of attribute screen.
Instance Method Summary collapse
-
#initialize(command: Echoes.config.shell, rows: nil, cols: nil) ⇒ Terminal
constructor
A new instance of Terminal.
- #run ⇒ Object
Constructor Details
#initialize(command: Echoes.config.shell, rows: nil, cols: nil) ⇒ Terminal
Returns a new instance of Terminal.
10 11 12 13 14 15 16 17 |
# File 'lib/echoes/terminal.rb', line 10 def initialize(command: Echoes.config.shell, rows: nil, cols: nil) size = IO.console&.winsize || [24, 80] @rows = rows || size[0] @cols = cols || size[1] @command = command @screen = Screen.new(rows: @rows, cols: @cols) @parser = Parser.new(@screen, writer: ->(s) { @write_io&.write(s) rescue nil }) end |
Instance Attribute Details
#screen ⇒ Object (readonly)
Returns the value of attribute screen.
8 9 10 |
# File 'lib/echoes/terminal.rb', line 8 def screen @screen end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/echoes/terminal.rb', line 19 def run PTY.spawn(@command) do |read_io, write_io, pid| @read_io = read_io @write_io = write_io @pid = pid @read_io.winsize = [@rows, @cols] setup_signal_handlers STDIN.raw do reader = Thread.new { read_loop } write_loop reader.kill end end end |