Class: NPlaylist
- Inherits:
-
Object
- Object
- NPlaylist
- Defined in:
- lib/ncurses_ui.rb
Instance Attribute Summary collapse
-
#dirty ⇒ Object
Returns the value of attribute dirty.
-
#list ⇒ Object
writeonly
Sets the attribute list.
Instance Method Summary collapse
- #active=(pos) ⇒ Object
- #close ⇒ Object
- #height ⇒ Object
- #height=(val) ⇒ Object
-
#initialize(scr, row, col, color, active_color, w, h, l) ⇒ NPlaylist
constructor
A new instance of NPlaylist.
- #refresh ⇒ Object
- #resize ⇒ Object
- #width ⇒ Object
- #width=(val) ⇒ Object
Constructor Details
#initialize(scr, row, col, color, active_color, w, h, l) ⇒ NPlaylist
Returns a new instance of NPlaylist.
317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/ncurses_ui.rb', line 317 def initialize scr, row, col, color, active_color, w, h, l @list = l @row = row @col = col @width = w @height = h @color = color @active_color = active_color @apos = -1 @win = Curses::Window.new height, width, @row, @col @dirty = true refresh end |
Instance Attribute Details
#dirty ⇒ Object
Returns the value of attribute dirty.
316 317 318 |
# File 'lib/ncurses_ui.rb', line 316 def dirty @dirty end |
#list=(value) ⇒ Object (writeonly)
Sets the attribute list
315 316 317 |
# File 'lib/ncurses_ui.rb', line 315 def list=(value) @list = value end |
Instance Method Details
#active=(pos) ⇒ Object
361 362 363 364 |
# File 'lib/ncurses_ui.rb', line 361 def active=(pos) @apos = pos @dirty = true end |
#close ⇒ Object
409 410 411 |
# File 'lib/ncurses_ui.rb', line 409 def close @win.close end |
#height ⇒ Object
340 341 342 343 344 345 346 347 |
# File 'lib/ncurses_ui.rb', line 340 def height h = [@row + @height, Curses.lines].min - @row if h <= 0 Curses.lines - @row + h else h end end |
#height=(val) ⇒ Object
355 356 357 358 359 |
# File 'lib/ncurses_ui.rb', line 355 def height=(val) @height = val resize refresh end |
#refresh ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/ncurses_ui.rb', line 371 def refresh return unless @dirty if !@list.is_a?(Array) || @list.empty? Nutils.print @win, 1, 2, "Empty playlist", @color, width - 3 else r = 1 size = height - 2 offset = ([[size/2.0, @apos].max, [@list.size, size].max-(size/2.0)].min - size/2.0).ceil @list[offset..@list.size].each do |t| tl = t["title"] if @apos == r - 1 + offset tl = ">#{tl}" color = @active_color else tl = " #{tl}" color = @color end tr = "[%6s]" % Nutils.timestr(t["duration"]) tr = "[D]#{tr}" if t["downloadable"] wr = tr.size wl = width - 3- wr Nutils.print @win, r, 1, tl, color, wl+1 Nutils.print @win, r, 2+wl, tr, color, wr r += 1 if(r >= height - 1) # print arrow down break end end end @win.attron(Colors.map(@color)) if @color @win.box 0, 0 @win.attroff(Colors.map(@color)) if @color @win.refresh @dirty = false end |
#resize ⇒ Object
366 367 368 369 |
# File 'lib/ncurses_ui.rb', line 366 def resize @win.resize height, width @dirty = true end |
#width ⇒ Object
331 332 333 334 335 336 337 338 |
# File 'lib/ncurses_ui.rb', line 331 def width w = [@col + @width, Curses.cols].min - @col if w <= 0 Curses.cols - @col + w else w end end |
#width=(val) ⇒ Object
349 350 351 352 353 |
# File 'lib/ncurses_ui.rb', line 349 def width=(val) @width = val resize refresh end |