class NyanCat::UI

Public Class Methods

new(cat) click to toggle source
# File lib/nyan-cat/ui.rb, line 3
def initialize(cat)
  @cat = cat
end

Public Instance Methods

render() click to toggle source
# File lib/nyan-cat/ui.rb, line 7
def render
  loop do
    render_frame(@cat.tick)
  end
end

Private Instance Methods

clear_screen(frame) click to toggle source
# File lib/nyan-cat/ui.rb, line 25
def clear_screen(frame)
  length = (frame.split("\n").length - 1)
  printf "\e[1A" * length + "\r"
end
delay_next_render() click to toggle source
# File lib/nyan-cat/ui.rb, line 21
def delay_next_render
  sleep (1.0/8.0)
end
render_frame(frame) click to toggle source
# File lib/nyan-cat/ui.rb, line 15
def render_frame(frame)
  printf frame
  delay_next_render
  clear_screen(frame)
end