Class: Wavesync::UI
- Inherits:
-
Object
- Object
- Wavesync::UI
- Defined in:
- lib/wavesync/ui.rb
Constant Summary collapse
- THEME =
{ primary: :lightgray, secondary: :darkgray, tertiary: :dimgray, highlight: :orangered, surface: :hotpink, extra: :deepskyblue }.freeze
Instance Method Summary collapse
- #analyze_progress(index, total_count) ⇒ Object
- #analyze_result(file, bpm) ⇒ Object
- #analyze_skip(file, bpm) ⇒ Object
- #bpm(tbpm, original_bars: nil, target_bars: nil) ⇒ Object
- #clear ⇒ Object
- #color(text, key) ⇒ Object
- #confirm(message) ⇒ Object
- #conversion_progress(source_format, target_format) ⇒ Object
- #copy(source_format) ⇒ Object
- #file_progress(filename) ⇒ Object
-
#initialize ⇒ UI
constructor
A new instance of UI.
- #select(label, options) ⇒ Object
- #skip ⇒ Object
- #sync_progress(index, total_count, device) ⇒ Object
Constructor Details
#initialize ⇒ UI
Returns a new instance of UI.
18 19 20 21 22 |
# File 'lib/wavesync/ui.rb', line 18 def initialize @cursor = TTY::Cursor @sticky_lines = [] @prompt = TTY::Prompt.new(interrupt: :exit, active_color: :red) end |
Instance Method Details
#analyze_progress(index, total_count) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/wavesync/ui.rb', line 74 def analyze_progress(index, total_count) parts = [ in_color('wavesync analyze', :primary), in_color("#{index + 1}/#{total_count}", :extra) ] sticky(parts.join(' '), 0) end |
#analyze_result(file, bpm) ⇒ Object
86 87 88 89 |
# File 'lib/wavesync/ui.rb', line 86 def analyze_result(file, bpm) label = bpm ? in_color("#{bpm} BPM", :highlight) : in_color('No BPM detected', :highlight) set_analyze_file_stickies(file, label) end |
#analyze_skip(file, bpm) ⇒ Object
82 83 84 |
# File 'lib/wavesync/ui.rb', line 82 def analyze_skip(file, bpm) set_analyze_file_stickies(file, in_color("↷ #{bpm} BPM already set", :highlight)) end |
#bpm(tbpm, original_bars: nil, target_bars: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wavesync/ui.rb', line 63 def bpm(tbpm, original_bars: nil, target_bars: nil) if tbpm.nil? sticky('', 4) elsif && = == ? "#{} bars" : "#{} → #{} bars" sticky("#{tbpm} bpm · #{}", 4) else sticky("#{tbpm} bpm", 4) end end |
#clear ⇒ Object
105 106 107 108 |
# File 'lib/wavesync/ui.rb', line 105 def clear print @cursor.clear_screen print @cursor.move_to(0, 0) end |
#color(text, key) ⇒ Object
101 102 103 |
# File 'lib/wavesync/ui.rb', line 101 def color(text, key) in_color(text, key) end |
#confirm(message) ⇒ Object
91 92 93 94 95 |
# File 'lib/wavesync/ui.rb', line 91 def confirm() print in_color(, :secondary) response = $stdin.gets.to_s.strip.downcase response == 'y' end |
#conversion_progress(source_format, target_format) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wavesync/ui.rb', line 41 def conversion_progress(source_format, target_format) effective = source_format.merge(target_format) source_info = audio_info(source_format.sample_rate, source_format.bit_depth) target_info = audio_info(effective.sample_rate, effective.bit_depth) formatted_line = in_color( "Converting #{source_format.file_type} (#{source_info}) ⇢ #{effective.file_type} (#{target_info})", :highlight ) sticky(formatted_line, 3) end |
#copy(source_format) ⇒ Object
53 54 55 56 57 |
# File 'lib/wavesync/ui.rb', line 53 def copy(source_format) info = audio_info(source_format.sample_rate, source_format.bit_depth) sticky(in_color("Copying #{source_format.file_type} (#{info})", :highlight), 3) end |
#file_progress(filename) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/wavesync/ui.rb', line 24 def file_progress(filename) path = Pathname.new(filename) file_stem = path.basename(path.extname).to_s parent_name = path.parent.basename.to_s sticky(in_color(parent_name, :secondary), 1) sticky(in_color(file_stem, :tertiary), 2) end |
#select(label, options) ⇒ Object
97 98 99 |
# File 'lib/wavesync/ui.rb', line 97 def select(label, ) @prompt.select(label, , cycle: true) end |
#skip ⇒ Object
59 60 61 |
# File 'lib/wavesync/ui.rb', line 59 def skip sticky(in_color('↷ Skipping, already synced', :highlight), 3) end |
#sync_progress(index, total_count, device) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/wavesync/ui.rb', line 32 def sync_progress(index, total_count, device) parts = [ in_color("wavesync #{device.name}", :primary), in_color("#{index + 1}/#{total_count}", :extra) ] sticky(parts.join(' '), 0) end |