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.
9 10 11 12 13 |
# File 'lib/shellfie/animation_frame_builder.rb', line 9 def initialize(config) @config = config @random = Random.new(config.animation[:seed]) @scroll_easing = AnimationScrollEasing.new(config) end |
Instance Method Details
#build ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/shellfie/animation_frame_builder.rb', line 15 def build return [{ lines: @config.lines, delay: @config.animation[:final_delay] }] if @config.frames.empty? frames = [] current_lines = @config.lines.flat_map { |line| line_data(line) } AnimationTimeline.new(@config).each do |event| case event.kind when :screen current_lines.replace(event.frame.screen.map { |line| { output: line } }) frames << { lines: build_display_lines(current_lines), delay: [event.frame.delay, 1].max } 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shellfie/animation_frame_builder.rb', line 40 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 |