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
: (Integer index, Integer total_count) -> void.
-
#analyze_result(file, bpm) ⇒ Object
: (String file, Integer? bpm) -> void.
-
#analyze_skip(file, bpm) ⇒ Object
: (String file, (String | Integer)? bpm) -> void.
-
#bpm(tbpm, original_bars: nil, target_bars: nil) ⇒ Object
: ((String | Integer)? tbpm, ?original_bars: Integer?, ?target_bars: Integer?) -> void.
-
#clear ⇒ Object
: () -> void.
-
#color(text, key) ⇒ Object
: (String text, Symbol key) -> String.
-
#confirm(message) ⇒ Object
: (String message) -> bool.
-
#conversion_progress(source_format, target_format) ⇒ Object
: (AudioFormat source_format, AudioFormat target_format) -> void.
-
#copy(source_format) ⇒ Object
: (AudioFormat source_format) -> void.
-
#file_progress(filename) ⇒ Object
: (String filename) -> void.
-
#initialize ⇒ UI
constructor
: () -> void.
-
#select(label, options) ⇒ Object
: (String label, Array options) -> String.
-
#skip ⇒ Object
: () -> void.
-
#sync_progress(index, total_count, device) ⇒ Object
: (Integer index, Integer total_count, Device device) -> void.
Constructor Details
#initialize ⇒ UI
: () -> void
20 21 22 23 24 |
# File 'lib/wavesync/ui.rb', line 20 def initialize @cursor = TTY::Cursor #: untyped @sticky_lines = [] #: Array[String] @prompt = TTY::Prompt.new(interrupt: :exit, active_color: :red) #: untyped end |
Instance Method Details
#analyze_progress(index, total_count) ⇒ Object
: (Integer index, Integer total_count) -> void
83 84 85 86 87 88 89 |
# File 'lib/wavesync/ui.rb', line 83 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
: (String file, Integer? bpm) -> void
97 98 99 100 |
# File 'lib/wavesync/ui.rb', line 97 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
: (String file, (String | Integer)? bpm) -> void
92 93 94 |
# File 'lib/wavesync/ui.rb', line 92 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
: ((String | Integer)? tbpm, ?original_bars: Integer?, ?target_bars: Integer?) -> void
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/wavesync/ui.rb', line 71 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
: () -> void
120 121 122 123 |
# File 'lib/wavesync/ui.rb', line 120 def clear print @cursor.clear_screen print @cursor.move_to(0, 0) end |
#color(text, key) ⇒ Object
: (String text, Symbol key) -> String
115 116 117 |
# File 'lib/wavesync/ui.rb', line 115 def color(text, key) in_color(text, key) end |
#confirm(message) ⇒ Object
: (String message) -> bool
103 104 105 106 107 |
# File 'lib/wavesync/ui.rb', line 103 def confirm() print in_color(, :secondary) response = $stdin.gets.to_s.strip.downcase response == 'y' end |
#conversion_progress(source_format, target_format) ⇒ Object
: (AudioFormat source_format, AudioFormat target_format) -> void
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/wavesync/ui.rb', line 46 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
: (AudioFormat source_format) -> void
59 60 61 62 63 |
# File 'lib/wavesync/ui.rb', line 59 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
: (String filename) -> void
27 28 29 30 31 32 33 |
# File 'lib/wavesync/ui.rb', line 27 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
: (String label, Array options) -> String
110 111 112 |
# File 'lib/wavesync/ui.rb', line 110 def select(label, ) @prompt.select(label, , cycle: true) end |
#skip ⇒ Object
: () -> void
66 67 68 |
# File 'lib/wavesync/ui.rb', line 66 def skip sticky(in_color('↷ Skipping, already synced', :highlight), 3) end |
#sync_progress(index, total_count, device) ⇒ Object
: (Integer index, Integer total_count, Device device) -> void
36 37 38 39 40 41 42 43 |
# File 'lib/wavesync/ui.rb', line 36 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 |