class MikePlayer::Display

Constants

INDICATOR_SIZE
PAUSE_INDICATOR

Public Class Methods

new() click to toggle source
# File lib/mikeplayer/display.rb, line 6
def initialize
  @width     = 0
  @indicator = ''
  @changed   = false
end

Public Instance Methods

changed?() click to toggle source
# File lib/mikeplayer/display.rb, line 45
def changed?
  true == @changed
end
display!(elapsed_info, countdown = nil) click to toggle source
# File lib/mikeplayer/display.rb, line 28
def display!(elapsed_info, countdown = nil)
  return unless changed?

  mindicator = "(#{countdown}↓) " if countdown

  print("\r" << ' '.ljust(@width))

  info  = "#{@info_prefix} #{elapsed_info} #{mindicator}#{@indicator}"

  print(info)

  @width   = info.size
  @changed = false

  $stdout.flush
end
elapsed=(v) click to toggle source
# File lib/mikeplayer/display.rb, line 16
def elapsed=(v)
  @indicator = "#{'>' * (v % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE)
  @changed   = true
end
paused() click to toggle source
# File lib/mikeplayer/display.rb, line 21
def paused
  if (false == @indicator.include?(PAUSE_INDICATOR))
    @indicator = PAUSE_INDICATOR.ljust(INDICATOR_SIZE)
    @changed   = true
  end
end
song_info=(v) click to toggle source
# File lib/mikeplayer/display.rb, line 12
def song_info=(v)
  @info_prefix = "\r#{v}".freeze
end