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.

Constant Summary collapse

READ_BUDGET =

Drain everything currently in the PTY’s kernel read buffer, feeding each chunk to the Terminal. Coalescing reads here means we render once per fully-formed output burst (fzf re-render, vim cursor+status redraw, etc.) instead of once per ~8 KiB chunk — the latter shows intermediate frames and is the main source of in-pane flicker. Bounded by a byte cap so a runaway producer can’t starve other panes on a single tick.

1 << 20

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)


63
64
65
# File 'lib/muxr/pane.rb', line 63

def alive?
  @process.alive?
end

#closeObject



71
72
73
# File 'lib/muxr/pane.rb', line 71

def close
  @process.close
end

#cwdObject



67
68
69
# File 'lib/muxr/pane.rb', line 67

def cwd
  @process.cwd || @initial_cwd
end

#drain_writesObject



31
32
33
# File 'lib/muxr/pane.rb', line 31

def drain_writes
  @process.drain
end

#ioObject



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

def io
  @process.io
end

#pending_write?Boolean

Returns:

  • (Boolean)


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

def pending_write?
  @process.pending_write?
end

#read_from_ptyObject

1 MiB



46
47
48
49
50
51
52
53
54
55
# File 'lib/muxr/pane.rb', line 46

def read_from_pty
  total = 0
  while total < READ_BUDGET
    chunk = @process.read_nonblock
    break unless chunk
    @terminal.feed(chunk)
    total += chunk.bytesize
  end
  total.positive? ? total : nil
end

#resize(rows, cols) ⇒ Object



57
58
59
60
61
# File 'lib/muxr/pane.rb', line 57

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

#write(data) ⇒ Object



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

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

#writer_ioObject



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

def writer_io
  @process.writer_io
end