Class: Slideck::Presenter Private
- Inherits:
-
Object
- Object
- Slideck::Presenter
- 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
-
#add_to_buffer(input_key) ⇒ void
private
Add to the input buffer.
-
#clear_screen ⇒ void
private
Clear terminal screen.
-
#go_to_first ⇒ void
private
Navigate to the fist slide.
-
#go_to_last ⇒ void
private
Navigate to the last slide.
-
#go_to_slide ⇒ void
private
Navigate to a given slide.
-
#hide_cursor ⇒ void
private
Hide cursor.
-
#initialize(reader, renderer, tracker, screen, output, &reloader) ⇒ Presenter
constructor
Create a Presenter.
-
#keyctrl_l ⇒ void
private
Reload presentation.
-
#keyctrl_x ⇒ void
(also: #keyescape)
private
Exit presentation.
-
#keyleft ⇒ void
(also: #keybackspace, #keypage_up)
private
Navigate to the previous slide.
-
#keypress(event) ⇒ void
private
Handle a keypress event.
-
#keyright ⇒ void
(also: #keyspace, #keypage_down)
private
Navigate to the next slide.
-
#reload ⇒ Slideck::Presenter
Reload presentation.
-
#render ⇒ void
Render presentation on cleared screen.
-
#render_slide ⇒ void
private
Render the current slide.
-
#resize ⇒ Slideck::Presenter
private
Resize presentation.
-
#show_cursor ⇒ void
private
Show cursor.
-
#start ⇒ void
Start presentation.
-
#stop ⇒ Slideck::Presenter
Stop presentation.
-
#subscribe_to_screen_resize(&resizer) ⇒ void
private
Subscribe to the terminal screen size change signal.
Constructor Details
#initialize(reader, renderer, tracker, screen, output, &reloader) ⇒ Presenter
Create a Presenter
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
268 269 270 |
# File 'lib/slideck/presenter.rb', line 268 def add_to_buffer(input_key) @buffer += [input_key] end |
#clear_screen ⇒ 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.
Clear terminal screen
110 111 112 |
# File 'lib/slideck/presenter.rb', line 110 def clear_screen @output.print @renderer.clear end |
#go_to_first ⇒ 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.
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_last ⇒ 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.
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_slide ⇒ 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.
Navigate to a given slide
255 256 257 258 |
# File 'lib/slideck/presenter.rb', line 255 def @tracker = @tracker.go_to(@buffer.join.to_i - 1) @buffer.clear end |
#hide_cursor ⇒ 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.
Hide cursor
132 133 134 |
# File 'lib/slideck/presenter.rb', line 132 def hide_cursor @output.print @renderer.cursor.hide end |
#keyctrl_l ⇒ 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.
Reload presentation
217 218 219 |
# File 'lib/slideck/presenter.rb', line 217 def keyctrl_l(*) reload end |
#keyctrl_x ⇒ void 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 |
#keyleft ⇒ void 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
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 when /\d/ then add_to_buffer(event.value) when "r" then keyctrl_l when "q" then keyctrl_x end end |
#keyright ⇒ void 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 |
#reload ⇒ Slideck::Presenter
Reload presentation
51 52 53 54 55 |
# File 'lib/slideck/presenter.rb', line 51 def reload @metadata, @slides = *@reloader.() @tracker = @tracker.resize(@slides.size) self end |
#render ⇒ void
This method returns an undefined value.
Render presentation on cleared screen
100 101 102 103 |
# File 'lib/slideck/presenter.rb', line 100 def render clear_screen end |
#render_slide ⇒ 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.
Render the current slide
119 120 121 122 123 124 125 |
# File 'lib/slideck/presenter.rb', line 119 def @output.print @renderer.render( @metadata, @slides[@tracker.current], @tracker.current + 1, @tracker.total) end |
#resize ⇒ Slideck::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
164 165 166 167 |
# File 'lib/slideck/presenter.rb', line 164 def resize @renderer = @renderer.resize(@screen.width, @screen.height) self end |
#show_cursor ⇒ 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.
Show cursor
141 142 143 |
# File 'lib/slideck/presenter.rb', line 141 def show_cursor @output.print @renderer.cursor.show end |
#start ⇒ void
This method returns an undefined value.
Start presentation
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 |
#stop ⇒ Slideck::Presenter
Stop presentation
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
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 |