Class: Milktea::Renderer

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

Overview

Renderer handles TUI rendering and screen management

Instance Method Summary collapse

Constructor Details

#initialize(output = $stdout) ⇒ Renderer

Returns a new instance of Renderer.



9
10
11
12
13
# File 'lib/milktea/renderer.rb', line 9

def initialize(output = $stdout)
  @output = output
  @cursor = TTY::Cursor
  @last_screen_size = TTY::Screen.size
end

Instance Method Details

#render(model) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/milktea/renderer.rb', line 15

def render(model)
  @output.print @cursor.clear_screen
  @output.print @cursor.move_to(0, 0)
  content = model.view
  @output.print content
  @output.flush
end

#resize?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/milktea/renderer.rb', line 36

def resize?
  current_size = TTY::Screen.size
  return false if current_size == @last_screen_size

  @last_screen_size = current_size
  true
end

#restore_screenObject



30
31
32
33
34
# File 'lib/milktea/renderer.rb', line 30

def restore_screen
  @output.print @cursor.clear_screen_down
  @output.print @cursor.show
  @output.flush
end

#setup_screenObject



23
24
25
26
27
28
# File 'lib/milktea/renderer.rb', line 23

def setup_screen
  @output.print @cursor.hide
  @output.print @cursor.clear_screen_down
  @output.print @cursor.move_to(0, 0)
  @output.flush
end