Class: Diamante::Scene::Slides

Inherits:
Object
  • Object
show all
Defined in:
lib/diamante/scenes/slides.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Slides

Returns a new instance of Slides.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/diamante/scenes/slides.rb', line 11

def initialize(config)
  @config = config
  @pastel = Pastel.new
  @term = ANSI.new
  @height = @term.height
  @width = @term.width

  @files = Dir.glob(@config[:files])
  @index = 0
  load_slide
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



9
10
11
# File 'lib/diamante/scenes/slides.rb', line 9

def index
  @index
end

Instance Method Details

#countObject



23
24
25
# File 'lib/diamante/scenes/slides.rb', line 23

def count
  @files.count
end

#nextObject



39
40
41
42
43
# File 'lib/diamante/scenes/slides.rb', line 39

def next
  return unless @index + 1 < @files.size
  @index += 1
  load_slide
end

#prevObject



45
46
47
48
49
# File 'lib/diamante/scenes/slides.rb', line 45

def prev
  return unless @index > 0
  @index -= 1
  load_slide
end

#renderObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/diamante/scenes/slides.rb', line 27

def render
  lines = @slide
  row = (@height / 2) - (lines.size / 2)
  max_with = lines.map(&:length).max
  col = (@width / 2) - (max_with / 2)

  lines.each_with_index do |text, index|
    text = @pastel.white.bold(text)
    ANSI.print_text_at(row + 1 + index, col,text)
  end
end