Class: RubyRich::Live

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/live.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layout, refresh_rate) ⇒ Live

Returns a new instance of Live.



61
62
63
64
65
66
67
68
# File 'lib/ruby_rich/live.rb', line 61

def initialize(layout, refresh_rate)
  @layout = layout
  @refresh_rate = refresh_rate
  @running = true
  @last_frame = Time.now
  @cursor = TTY::Cursor
  @render = CacheRender.new
end

Class Method Details

.start(layout, refresh_rate: 30, full_screen: false, &proc) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ruby_rich/live.rb', line 38

def start(layout, refresh_rate: 30, full_screen: false, &proc)
  setup_terminal
  live = new(layout, refresh_rate)
  live.run(proc)
rescue => e
  puts e.message
ensure
  restore_terminal
end

Instance Method Details

#move_cursor(x, y) ⇒ Object



82
83
84
# File 'lib/ruby_rich/live.rb', line 82

def move_cursor(x,y)
  print @cursor.move_to(x, y)
end

#run(proc = nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/ruby_rich/live.rb', line 70

def run(proc = nil)
  while @running
    render_frame
    proc.call(self) if proc
    sleep 1.0 / @refresh_rate
  end
end

#stopObject



78
79
80
# File 'lib/ruby_rich/live.rb', line 78

def stop
  @running = false
end