Class: Slideck::Presenter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slideck/presenter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for presenting slides

Instance Method Summary collapse

Constructor Details

#initialize(reader, renderer, tracker, screen, output, &reloader) ⇒ Presenter

Create a Presenter

Parameters:

  • reader (TTY::Reader)

    the keyboard input reader

  • renderer (Slideck::Renderer)

    the slides renderer

  • tracker (Slideck::Tracker)

    the tracker for slides

  • screen (TTY::Screen)

    the terminal screen size

  • output (IO)

    the output stream for the slides

  • reloader (Proc)

    the metadata and slides reloader



32
33
34
35
36
37
38
39
40
41
# File 'lib/slideck/presenter.rb', line 32

def initialize(reader, renderer, tracker, screen, output, &reloader)
  @reader = reader
  @renderer = renderer
  @tracker = tracker
  @screen = screen
  @output = output
  @reloader = reloader
  @stop = false
  @buffer = []
end

Instance Method Details

#add_to_buffer(input_key) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Add to the input buffer

Parameters:

  • input_key (String)

    the input key



268
269
270
# File 'lib/slideck/presenter.rb', line 268

def add_to_buffer(input_key)
  @buffer += [input_key]
end

#clear_screenvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Clear terminal screen



110
111
112
# File 'lib/slideck/presenter.rb', line 110

def clear_screen
  @output.print @renderer.clear
end

#go_to_firstvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Navigate to the fist slide



237
238
239
# File 'lib/slideck/presenter.rb', line 237

def go_to_first
  @tracker = @tracker.first
end

#go_to_lastvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Navigate to the last slide



246
247
248
# File 'lib/slideck/presenter.rb', line 246

def go_to_last
  @tracker = @tracker.last
end

#go_to_slidevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Navigate to a given slide



255
256
257
258
# File 'lib/slideck/presenter.rb', line 255

def go_to_slide
  @tracker = @tracker.go_to(@buffer.join.to_i - 1)
  @buffer.clear
end

#hide_cursorvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Hide cursor



132
133
134
# File 'lib/slideck/presenter.rb', line 132

def hide_cursor
  @output.print @renderer.cursor.hide
end

#keyctrl_lvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Reload presentation



217
218
219
# File 'lib/slideck/presenter.rb', line 217

def keyctrl_l(*)
  reload
end

#keyctrl_xvoid Also known as: keyescape

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Exit presentation



226
227
228
229
# File 'lib/slideck/presenter.rb', line 226

def keyctrl_x(*)
  clear_screen
  stop
end

#keyleftvoid Also known as: keybackspace, keypage_up

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Navigate to the previous slide



206
207
208
# File 'lib/slideck/presenter.rb', line 206

def keyleft(*)
  @tracker = @tracker.previous
end

#keypress(event) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Handle a keypress event

Parameters:

  • event (TTY::Reader::KeyEvent)

    the key event



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/slideck/presenter.rb', line 177

def keypress(event)
  case event.value
  when "n", "l" then keyright
  when "p", "h" then keyleft
  when "f", "^" then go_to_first
  when "t", "$" then go_to_last
  when "g" then go_to_slide
  when /\d/ then add_to_buffer(event.value)
  when "r" then keyctrl_l
  when "q" then keyctrl_x
  end
end

#keyrightvoid Also known as: keyspace, keypage_down

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Navigate to the next slide



195
196
197
# File 'lib/slideck/presenter.rb', line 195

def keyright(*)
  @tracker = @tracker.next
end

#reloadSlideck::Presenter

Reload presentation

Examples:

presenter.reload

Returns:



51
52
53
54
55
# File 'lib/slideck/presenter.rb', line 51

def reload
  @metadata, @slides = *@reloader.()
  @tracker = @tracker.resize(@slides.size)
  self
end

#rendervoid

This method returns an undefined value.

Render presentation on cleared screen

Examples:

presenter.render


100
101
102
103
# File 'lib/slideck/presenter.rb', line 100

def render
  clear_screen
  render_slide
end

#render_slidevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Render the current slide



119
120
121
122
123
124
125
# File 'lib/slideck/presenter.rb', line 119

def render_slide
  @output.print @renderer.render(
    @metadata,
    @slides[@tracker.current],
    @tracker.current + 1,
    @tracker.total)
end

#resizeSlideck::Presenter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resize presentation

Returns:



164
165
166
167
# File 'lib/slideck/presenter.rb', line 164

def resize
  @renderer = @renderer.resize(@screen.width, @screen.height)
  self
end

#show_cursorvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Show cursor



141
142
143
# File 'lib/slideck/presenter.rb', line 141

def show_cursor
  @output.print @renderer.cursor.show
end

#startvoid

This method returns an undefined value.

Start presentation

Examples:

presenter.start


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/slideck/presenter.rb', line 65

def start
  reload
  @reader.subscribe(self)
  hide_cursor
  subscribe_to_screen_resize { resize.render }

  until @stop
    render
    @reader.read_keypress
  end
ensure
  show_cursor
end

#stopSlideck::Presenter

Stop presentation

Examples:

presenter.stop

Returns:



87
88
89
90
# File 'lib/slideck/presenter.rb', line 87

def stop
  @stop = true
  self
end

#subscribe_to_screen_resize(&resizer) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Subscribe to the terminal screen size change signal

Parameters:

  • resizer (Proc)

    the presentation resizer



153
154
155
156
157
# File 'lib/slideck/presenter.rb', line 153

def subscribe_to_screen_resize(&resizer)
  return if @screen.windows?

  Signal.trap(TERM_SCREEN_SIZE_CHANGE_SIG, &resizer)
end