Class: Muxr::Pane

Inherits:
Object
  • Object
show all
Defined in:
lib/muxr/pane.rb

Overview

A Pane bundles a Terminal emulator buffer with the PTYProcess running the shell that feeds it. The Window keeps a list of panes; the Renderer asks each pane for its current grid contents and cursor position.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, rows: 24, cols: 80, cwd: nil, command: nil, process: nil) ⇒ Pane

Returns a new instance of Pane.



9
10
11
12
13
14
15
16
17
# File 'lib/muxr/pane.rb', line 9

def initialize(id:, rows: 24, cols: 80, cwd: nil, command: nil, process: nil)
  @id = id
  @rows = rows
  @cols = cols
  @terminal = Terminal.new(rows: rows, cols: cols)
  @process = process || PTYProcess.new(rows: rows, cols: cols, cwd: cwd, command: command)
  @rect = nil
  @initial_cwd = cwd || @process.cwd
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/muxr/pane.rb', line 6

def id
  @id
end

#processObject (readonly)

Returns the value of attribute process.



6
7
8
# File 'lib/muxr/pane.rb', line 6

def process
  @process
end

#rectObject

Returns the value of attribute rect.



7
8
9
# File 'lib/muxr/pane.rb', line 7

def rect
  @rect
end

#terminalObject (readonly)

Returns the value of attribute terminal.



6
7
8
# File 'lib/muxr/pane.rb', line 6

def terminal
  @terminal
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/muxr/pane.rb', line 40

def alive?
  @process.alive?
end

#closeObject



48
49
50
# File 'lib/muxr/pane.rb', line 48

def close
  @process.close
end

#cwdObject



44
45
46
# File 'lib/muxr/pane.rb', line 44

def cwd
  @process.cwd || @initial_cwd
end

#ioObject



19
20
21
# File 'lib/muxr/pane.rb', line 19

def io
  @process.io
end

#read_from_ptyObject



27
28
29
30
31
32
# File 'lib/muxr/pane.rb', line 27

def read_from_pty
  data = @process.read_nonblock
  return nil unless data
  @terminal.feed(data)
  data
end

#resize(rows, cols) ⇒ Object



34
35
36
37
38
# File 'lib/muxr/pane.rb', line 34

def resize(rows, cols)
  return if rows == @terminal.rows && cols == @terminal.cols
  @terminal.resize(rows, cols)
  @process.resize(rows, cols)
end

#write(data) ⇒ Object



23
24
25
# File 'lib/muxr/pane.rb', line 23

def write(data)
  @process.write(data)
end