Class: NCursesUI
- Inherits:
-
Object
- Object
- NCursesUI
- Defined in:
- lib/ncurses_ui.rb
Instance Attribute Summary collapse
-
#audio_backend ⇒ Object
Returns the value of attribute audio_backend.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #close ⇒ Object
- #cloud_update(arg) ⇒ Object
-
#initialize(cloud, options = {}, params = {}) ⇒ NCursesUI
constructor
A new instance of NCursesUI.
- #player_update(arg) ⇒ Object
- #run ⇒ Object
- #status(msg) ⇒ Object
Constructor Details
#initialize(cloud, options = {}, params = {}) ⇒ NCursesUI
Returns a new instance of NCursesUI.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ncurses_ui.rb', line 13 def initialize cloud, = {}, params = {} params.each { |key, value| send "#{key}=", value } if not @audio_backend @audio_backend = Object.new def @audio_backend.version "Audio backend: None" end end defaults = { :colors => { :default => [:cyan, :blue], :playlist => [:cyan, :blue], :playlist_active => [:white, :blue], :progress => [:cyan, :blue], :progress_bar => [:blue, :cyan], :buffer_bar => [:blue, :magenta], :title => [:cyan, :black], :artist => [:cyan, :black], :status => [:magenta, :black] }, :palette => {} }.freeze @options = defaults.deep_merge( || {}) @cloud = cloud @state = :running @frac = 0 @title = "None" @op = " " @time = 0 @timeleft = 0 @playlist = [] end |
Instance Attribute Details
#audio_backend ⇒ Object
Returns the value of attribute audio_backend.
11 12 13 |
# File 'lib/ncurses_ui.rb', line 11 def audio_backend @audio_backend end |
#logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/ncurses_ui.rb', line 11 def logger @logger end |
Instance Method Details
#close ⇒ Object
205 206 207 |
# File 'lib/ncurses_ui.rb', line 205 def close @state = :close end |
#cloud_update(arg) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ncurses_ui.rb', line 132 def cloud_update(arg) case arg[:state] when :error @error = "Error: #{arg[:error]}" when :load @playlist |= arg[:tracks] @l.list = @playlist if @l when :shuffle @playlist = arg[:tracks] @l.list = @playlist if @l when :next, :previous pos = arg[:position] @l.active = pos if @l when :download if arg[:error] @error = "Error: #{arg[:error]}" end if arg[:count] count = arg[:count] if(count > 0) @l.height = -1 @d.visible = true @d.count = count @d.title = arg[:name] if arg[:name] else @l.height = 0 @d.visible = false @d.title = "" end end when :status if arg[:type] status("#{arg[:type]}: #{arg[:value]}") end end end |
#player_update(arg) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ncurses_ui.rb', line 169 def player_update(arg) case arg[:state] when :load track = arg[:track] if track.nil? @error = "Error: Nothing found!" else @error = nil @title = track["title"] @username = track["user"]["username"] @timetotal = track["duration"] @error = "Error: #{track[:error]}" if track[:error] end when :info frame = arg[:frame].to_f frames = frame + arg[:frameleft] @frac = frame/frames @time = arg[:time].to_i when :pause @op = "\u2161" when :resume, :play @op = "\u25B6" when :stop @op = "\u25FC" when :error @error = "Error: #{arg[:error]}" when :buffer @bufferPercentage = arg[:value].to_i || 0 when :status if arg[:type] status("#{arg[:type]}: #{arg[:value]}") end end end |
#run ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ncurses_ui.rb', line 49 def run begin stdscr = Curses.init_screen Curses.start_color Colors.init @options[:colors], @options[:palette] stdscr.keypad true Curses.nonl Curses.cbreak Curses.noecho Curses.curs_set 0 Curses.timeout = 5 @p = NProgress.new stdscr, 0, 0, :progress, :progress_bar, :buffer_bar @l = NPlaylist.new stdscr, 4, 0, :playlist, :playlist_active, 0, 0, @playlist @i = NInfobox.new self, stdscr, 4, 0, :playlist, 0, 9 @d = NDownloadBox.new stdscr, Curses.lines-1, 0, :default, 0, 1 @l.active = 0 last_ch = nil while(@state != :close) ch = Curses.getch last_ch = ch if ch Curses.setpos 3, 0 Curses.clrtoeol # Nutils.print stdscr, 3, 0, "Test %s" % [last_ch], :red case ch when Curses::KEY_RESIZE @p.resize @l.resize @i.resize @d.resize Curses.refresh when 110, 78, 'n', 'N', Curses::KEY_DOWN @cloud.nextTrack when 112, 80, 'p', 'P', Curses::KEY_UP @cloud.prevTrack when 113, 81, 'q', 'Q', 27, Curses::KEY_EXIT @cloud.quit when 61, 43, '=', '+' @cloud.volumeUp when 45, 95, '-', '_' @cloud.volumeDown when 109, 77, 'm', 'M' @cloud.toggleMute when 68, 100, 'd', 'D' @cloud.download when 118, 86, 'v', 'V' @i.visible = !@i.visible @l.dirty = true when 32, ' ' @cloud.pause end statusLine = @status || @error || "" Nutils.print stdscr, 3, 0, "#{statusLine}", :status Curses.refresh tr = " %s " % [Nutils.timestr(@timetotal)] t = " %-#{Curses.cols-tr.size-1}s%s" % [Nutils.timestr(@time), tr] @p.value = @frac @p.subvalue = (@bufferPercentage || 0)/100.0 @p.text = t @p.refresh Nutils.print stdscr, 1, 0, "#{@op} #{@title}", :title Nutils.print stdscr, 2, 0, " by #{@username}", :artist @l.refresh @i.refresh @d.refresh stdscr.refresh end rescue => ex ensure @l.close if @l @p.close if @p stdscr.close if stdscr Curses.echo Curses.nocbreak Curses.nl Curses.close_screen puts ex.inspect if ex puts ex.backtrace if ex # Colors.debug end end |
#status(msg) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/ncurses_ui.rb', line 209 def status msg @status = msg if @statusTimeout @statusTimeout.exit end @statusTimeout = Thread.new do sleep 5 @status = nil @statusTimeout = nil end end |