Class: MikePlayer::Display
- Inherits:
-
Object
- Object
- MikePlayer::Display
- Defined in:
- lib/mikeplayer/display.rb
Constant Summary collapse
- PAUSE_INDICATOR =
'||'.freeze
- INDICATOR_SIZE =
4- PROGRESS_WIDTH =
40- TITLE_ROW =
4- BAR_ROW =
5- HINT_ROW =
7- HINT_TEXT =
'c: pause/play v: next z: previous t: set timer q: quit'.freeze
- RESET =
"\e[0m".freeze
- TITLE_COLOR =
bold cyan
"\e[1;36m".freeze
- DIM_COLOR =
dim gray
"\e[2m".freeze
- BANNER_COLOR =
bold white
"\e[1;37m".freeze
- ELAPSED_COLOR =
white
"\e[37m".freeze
- COUNTDOWN_COLOR =
yellow
"\e[33m".freeze
- PLAY_COLOR =
green
"\e[32m".freeze
- PAUSE_COLOR =
bold red
"\e[1;31m".freeze
- ENTER_ALT_SCREEN =
"\e[?1049h\e[2J\e[H\e[?25l".freeze
- EXIT_ALT_SCREEN =
"\e[?25h\e[?1049l".freeze
Class Method Summary collapse
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #display!(elapsed_info, countdown = nil) ⇒ Object
- #elapsed=(v) ⇒ Object
-
#initialize(fullscreen: false) ⇒ Display
constructor
A new instance of Display.
- #paused ⇒ Object
- #song_info=(v) ⇒ Object
Constructor Details
#initialize(fullscreen: false) ⇒ Display
Returns a new instance of Display.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mikeplayer/display.rb', line 41 def initialize(fullscreen: false) @width = 0 @indicator = '' @paused = false @changed = false @color = $stdout.tty? @fullscreen = fullscreen @elapsed_seconds = 0 @length = 0 end |
Class Method Details
.colorize(text, color) ⇒ Object
25 26 27 28 29 |
# File 'lib/mikeplayer/display.rb', line 25 def self.colorize(text, color) return text unless $stdout.tty? "#{color}#{text}#{RESET}" end |
.enter_fullscreen ⇒ Object
31 32 33 34 |
# File 'lib/mikeplayer/display.rb', line 31 def self.enter_fullscreen print(ENTER_ALT_SCREEN) $stdout.flush end |
.exit_fullscreen ⇒ Object
36 37 38 39 |
# File 'lib/mikeplayer/display.rb', line 36 def self.exit_fullscreen print(EXIT_ALT_SCREEN) $stdout.flush end |
Instance Method Details
#changed? ⇒ Boolean
83 84 85 |
# File 'lib/mikeplayer/display.rb', line 83 def changed? true == @changed end |
#display!(elapsed_info, countdown = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/mikeplayer/display.rb', line 73 def display!(elapsed_info, countdown = nil) return unless changed? if @fullscreen display_panel!(elapsed_info, countdown) else display_line!(elapsed_info, countdown) end end |
#elapsed=(v) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/mikeplayer/display.rb', line 58 def elapsed=(v) @elapsed_seconds = v @indicator = "#{'>' * (v % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE) @paused = false @changed = true end |
#paused ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/mikeplayer/display.rb', line 65 def paused if (false == @paused) @indicator = PAUSE_INDICATOR.ljust(INDICATOR_SIZE) @paused = true @changed = true end end |
#song_info=(v) ⇒ Object
52 53 54 55 56 |
# File 'lib/mikeplayer/display.rb', line 52 def song_info=(v) @position = v[:position].freeze @title = v[:title].freeze @length = v[:length].to_f end |