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
- PUSH_TITLE =
"\e[22;0t".freeze
- POP_TITLE =
"\e[23;0t".freeze
- PLAY_GLYPH =
'▶'.freeze
- PAUSE_GLYPH =
'⏸'.freeze
Class Method Summary collapse
- .colorize(text, color) ⇒ Object
- .enter_fullscreen ⇒ Object
- .exit_fullscreen ⇒ Object
- .pop_title ⇒ Object
- .push_title ⇒ Object
- .set_title(text) ⇒ Object
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.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mikeplayer/display.rb', line 68 def initialize(fullscreen: false) @width = 0 @indicator = '' @paused = false @changed = false @color = $stdout.tty? @fullscreen = fullscreen @elapsed_seconds = 0 @length = 0 @last_title = nil end |
Class Method Details
.colorize(text, color) ⇒ Object
31 32 33 34 35 |
# File 'lib/mikeplayer/display.rb', line 31 def self.colorize(text, color) return text unless $stdout.tty? "#{color}#{text}#{RESET}" end |
.enter_fullscreen ⇒ Object
37 38 39 40 |
# File 'lib/mikeplayer/display.rb', line 37 def self.enter_fullscreen print(ENTER_ALT_SCREEN) $stdout.flush end |
.exit_fullscreen ⇒ Object
42 43 44 45 |
# File 'lib/mikeplayer/display.rb', line 42 def self.exit_fullscreen print(EXIT_ALT_SCREEN) $stdout.flush end |
.pop_title ⇒ Object
61 62 63 64 65 66 |
# File 'lib/mikeplayer/display.rb', line 61 def self.pop_title return unless $stdout.tty? print(POP_TITLE) $stdout.flush end |
.push_title ⇒ Object
54 55 56 57 58 59 |
# File 'lib/mikeplayer/display.rb', line 54 def self.push_title return unless $stdout.tty? print(PUSH_TITLE) $stdout.flush end |
.set_title(text) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/mikeplayer/display.rb', line 47 def self.set_title(text) return unless $stdout.tty? print("\e]0;#{text}\a") $stdout.flush end |
Instance Method Details
#changed? ⇒ Boolean
117 118 119 |
# File 'lib/mikeplayer/display.rb', line 117 def changed? true == @changed end |
#display!(elapsed_info, countdown = nil) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/mikeplayer/display.rb', line 107 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
88 89 90 91 92 93 94 95 |
# File 'lib/mikeplayer/display.rb', line 88 def elapsed=(v) @elapsed_seconds = v @indicator = "#{'>' * (v % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE) @paused = false @changed = true update_terminal_title end |
#paused ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/mikeplayer/display.rb', line 97 def paused if (false == @paused) @indicator = PAUSE_INDICATOR.ljust(INDICATOR_SIZE) @paused = true @changed = true update_terminal_title end end |
#song_info=(v) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/mikeplayer/display.rb', line 80 def song_info=(v) @position = v[:position].freeze @title = v[:title].freeze @length = v[:length].to_f update_terminal_title end |