Class: Przn::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/przn/controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(presentation, terminal, renderer) ⇒ Controller

Returns a new instance of Controller.



5
6
7
8
9
10
# File 'lib/przn/controller.rb', line 5

def initialize(presentation, terminal, renderer)
  @presentation = presentation
  @terminal = terminal
  @renderer = renderer
  @preload_gen = 0
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/przn/controller.rb', line 12

def run
  @terminal.enter_alt_screen
  @terminal.hide_cursor
  render_current

  @terminal.raw do
    loop do
      case read_key
      when :right, :down, 'l', 'j', ' '
        @presentation.next_slide
        render_current
      when :left, :up, 'h', 'k'
        @presentation.prev_slide
        render_current
      when 'g'
        @presentation.first_slide!
        render_current
      when 'G'
        @presentation.last_slide!
        render_current
      when 'q', "\x03"
        break
      end
    end
  end
ensure
  @preload_gen += 1
  @preload_thread&.join
  @terminal.write "\e]7772;bg-clear\a"
  @terminal.show_cursor
  @terminal.leave_alt_screen
end