Class: Slideck::Renderer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slideck/renderer.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 rendering slides

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(converter, ansi, cursor, width: nil, height: nil) ⇒ Renderer

Create a Renderer instance

Parameters:

  • converter (Slideck::Converter)

    the markdown to terminal output converter

  • ansi (Strings::ANSI)

    the ansi codes handler

  • cursor (TTY::Cursor)

    the cursor navigation

  • width (Integer) (defaults to: nil)

    the screen width

  • height (Integer) (defaults to: nil)

    the screen height



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

def initialize(converter, ansi, cursor, width: nil, height: nil)
  @converter = converter
  @ansi = ansi
  @cursor = cursor
  @width = width
  @height = height

  freeze
end

Instance Attribute Details

#cursorTTY::Cursor (readonly)

The terminal cursor

Examples:

renderer.cursor

Returns:

  • (TTY::Cursor)


16
17
18
# File 'lib/slideck/renderer.rb', line 16

def cursor
  @cursor
end

Instance Method Details

#clearString

Clear terminal screen

Examples:

renderer.clear

Returns:

  • (String)


94
95
96
# File 'lib/slideck/renderer.rb', line 94

def clear
  cursor.clear_screen + cursor.move_to(0, 0)
end

#render(metadata, slide, current_num, num_of_slides) ⇒ String

Render a slide

Examples:

renderer.render(, slide, 1, 5)

Parameters:

  • metadata (Slideck::Metadata)

    the global metadata

  • slide (Hash{Symbol => Hash, String}, nil)

    the current slide to render

  • current_num (Integer)

    the current slide number

  • num_of_slides (Integer)

    the number of slides

Returns:

  • (String)


76
77
78
79
80
81
82
83
84
# File 'lib/slideck/renderer.rb', line 76

def render(, slide, current_num, num_of_slides)
   = slide && slide[:metadata]
  [].tap do |out|
    out << render_content(, slide) if slide
    out << render_footer(, )
    out << render_pager(, ,
                        current_num, num_of_slides)
  end.join
end

#resize(width, height) ⇒ Slideck::Renderer

Create a Renderer with a new screen size

Examples:

renderer.resize(200, 50)

Parameters:

  • width (Integer)

    the screen width

  • height (Integer)

    the screen height

Returns:



55
56
57
# File 'lib/slideck/renderer.rb', line 55

def resize(width, height)
  self.class.new(@converter, @ansi, @cursor, width: width, height: height)
end