Class: NPlaylist

Inherits:
Object
  • Object
show all
Defined in:
lib/ncurses_ui.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scr, row, col, color, active_color, w, h, l) ⇒ NPlaylist

Returns a new instance of NPlaylist.



406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/ncurses_ui.rb', line 406

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

#dirtyObject

Returns the value of attribute dirty.



405
406
407
# File 'lib/ncurses_ui.rb', line 405

def dirty
  @dirty
end

#list=(value) ⇒ Object (writeonly)

Sets the attribute list

Parameters:

  • value

    the value to set the attribute list to.



404
405
406
# File 'lib/ncurses_ui.rb', line 404

def list=(value)
  @list = value
end

Instance Method Details

#active=(pos) ⇒ Object



450
451
452
453
# File 'lib/ncurses_ui.rb', line 450

def active=(pos)
  @apos = pos
  @dirty = true
end

#closeObject



502
503
504
# File 'lib/ncurses_ui.rb', line 502

def close
  @win.close
end

#heightObject



429
430
431
432
433
434
435
436
# File 'lib/ncurses_ui.rb', line 429

def height
  h = [@row + @height, Curses.lines].min - @row
  if h <= 0
    Curses.lines - @row + h
  else
    h
  end
end

#height=(val) ⇒ Object



444
445
446
447
448
# File 'lib/ncurses_ui.rb', line 444

def height=(val)
  @height = val
  resize
  refresh
end

#refreshObject



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/ncurses_ui.rb', line 460

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
  while r < height
    Nutils.print @win, r, 0, "", @color
    r += 1
  end
  @win.attron(Colors.pairMap(@color)) if @color
  @win.box 0, 0
  @win.attroff(Colors.pairMap(@color)) if @color
  @win.refresh
  @dirty = false
end

#resizeObject



455
456
457
458
# File 'lib/ncurses_ui.rb', line 455

def resize
  @win.resize height, width
  @dirty = true
end

#widthObject



420
421
422
423
424
425
426
427
# File 'lib/ncurses_ui.rb', line 420

def width
  w = [@col + @width, Curses.cols].min - @col
  if w <= 0
    Curses.cols - @col + w
  else
    w
  end
end

#width=(val) ⇒ Object



438
439
440
441
442
# File 'lib/ncurses_ui.rb', line 438

def width=(val)
  @width = val
  resize
  refresh
end