Class: Shellfie::AnimationFrameBuilder
- Inherits:
-
Object
- Object
- Shellfie::AnimationFrameBuilder
- Defined in:
- lib/shellfie/animation_frame_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
- #cursor_text ⇒ Object
-
#initialize(config) ⇒ AnimationFrameBuilder
constructor
A new instance of AnimationFrameBuilder.
Constructor Details
#initialize(config) ⇒ AnimationFrameBuilder
Returns a new instance of AnimationFrameBuilder.
8 9 10 11 12 |
# File 'lib/shellfie/animation_frame_builder.rb', line 8 def initialize(config) @config = config @random = Random.new(0) @scroll_easing = AnimationScrollEasing.new(config) end |
Instance Method Details
#build ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/shellfie/animation_frame_builder.rb', line 14 def build return [{ lines: @config.lines, delay: @config.animation[:final_delay] }] if @config.frames.empty? frames = [] current_lines = [] AnimationTimeline.new(@config).each do |event| case event.kind when :command frames.concat(command_frames(current_lines, event.frame)) when :output frames.concat(output_frames(current_lines, event.frame)) when :pause frames << { lines: build_display_lines(current_lines), delay: event.frame.delay } end end if @config.animation[:final_delay].positive? frames << { lines: build_display_lines(current_lines), delay: @config.animation[:final_delay] } end frames end |
#cursor_text ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shellfie/animation_frame_builder.rb', line 36 def cursor_text glyph = case @config.cursor[:style] when "bar" "|" when "underline" "_" else "█" end color = @config.cursor[:color] return glyph unless color "#{ansi_color(color)}#{glyph}\e[0m" end |