Class: Muxr::Renderer

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

Overview

The Renderer composites the Session into a single grid of cells and then emits ANSI escape sequences to write that grid to STDOUT. It compares the new frame against the previous one and only repositions/redraws cells whose contents changed, keeping output volume low between ticks.

Defined Under Namespace

Classes: Cell

Constant Summary collapse

BORDER_FOCUSED =

yellow

[:c256, 11].freeze
BORDER_UNFOCUSED =

grey

[:c256, 8].freeze
BORDER_DRAWER_FOCUS =

magenta

[:c256, 13].freeze
BORDER_DRAWER_IDLE =

dark magenta

[:c256, 5].freeze
STATUS_BG =
[:c256, 236].freeze
STATUS_FG =
[:c256, 252].freeze
HORIZONTAL =
"".freeze
VERTICAL =
"".freeze
TL =
"".freeze
TR =
"".freeze
BL =
"".freeze
BR =
"".freeze

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout) ⇒ Renderer

Returns a new instance of Renderer.



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

def initialize(out: $stdout)
  @out = out
  @prev = nil
  @prev_w = 0
  @prev_h = 0
end

Instance Method Details

#enter_alt_screenObject



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

def enter_alt_screen
  @out.write("\e[?1049h\e[?25l\e[2J\e[H\e[0m")
  @out.flush
  @prev = nil
end

#exit_alt_screenObject



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

def exit_alt_screen
  @out.write("\e[0m\e[?25h\e[?1049l")
  @out.flush
end

#render(session, input_state: :idle, command_buffer: "", message: nil, help: false) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/muxr/renderer.rb', line 49

def render(session, input_state: :idle, command_buffer: "", message: nil, help: false)
  w = session.width
  h = session.height
  return if w < 4 || h < 3

  frame = Array.new(h) { Array.new(w) { Cell.new(" ", nil, nil, 0) } }

  compose_panes(frame, session)
  compose_drawer(frame, session) if session.drawer&.visible?
  compose_status_bar(frame, session, input_state: input_state, command_buffer: command_buffer, message: message)
  compose_help(frame, session) if help

  emit_frame(frame, session, input_state: input_state, command_buffer: command_buffer)
end

#reset_frame!Object



45
46
47
# File 'lib/muxr/renderer.rb', line 45

def reset_frame!
  @prev = nil
end