Class: Diamante::Scene::Slides

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#update

Constructor Details

#initialize(config) ⇒ Slides

Returns a new instance of Slides.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/diamante/scenes/slides.rb', line 12

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

  @files = Dir.glob(@config[:files])
  if @files.empty?
    ANSI.set_cooked_mode
    warn "[ERROR] No slides! Revise config.yaml"
    exit 1
  end
  @index = 0
  load_slide
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

Instance Method Details

#countObject



29
30
31
# File 'lib/diamante/scenes/slides.rb', line 29

def count
  @files.count
end

#nextObject



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

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

#prevObject



51
52
53
54
55
# File 'lib/diamante/scenes/slides.rb', line 51

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

#renderObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/diamante/scenes/slides.rb', line 33

def render
  lines = @slide
  row = (@height / 2) - (lines.size / 2)
  max_with = lines.map(&:length).max || 0
  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