docs: function attachSelectionMethods(box) {
    box.selected = 0;
  
    var nextTop = 0;
    var items = {};
  
    box.layout = function() {
      nextTop = 1;
      box.children.forEach(function(child) {
        child.top = nextTop;
        child.height = child.getScreenLines().length;
        nextTop += child.height;
      })
    }
  
    box.addItem = function(text, itemKey, itemData) {
      var node = blessed.text({
          left: 0,
          right: 0,
          top: nextTop,
          height: 1,
          tags: true,
          content: text
      });
      node.itemData = itemData;
      items[itemKey] = node;
      box.append(node);
      node.height = node.getScreenLines().length;
      nextTop += node.height;
    }
  
    box.getItem = function(itemKey) {
      return items[itemKey];
    }
  
    box.selectItem = function(itemKey) {
      var item = box.getItem(itemKey);
      if (!item) {
        return;
      }
      var i = box.children.indexOf(item);
      if (i == -1) {
        return;
      }
      box.select(i);
    }
  
    box.removeItem = function(itemKey) {
      var item = items[itemKey];
      if (!item) {
        return;
      }
      delete items[itemKey];
      item.detach();
      box.layout();
    }
  
    box.clearItems = function() {
      box.children.slice().forEach(function(child) {
        child.detach();
      });
      box.selected = -1;
      nextTop = 0;
      items = {};
    }
  
    box.up = function(n) {
      if (box.selected == -1) {
        box.select(box.children.length - 1);
      } else {
        n = n === undefined ? 1 : n;
        box.select(box.selected - n);
      }
    }
  
    box.down = function(n) {
      if (box.selected == -1) {
        box.select(box.children.length - 1);
      } else {
        n = n === undefined ? 1 : n;
        box.select(box.selected + n);
      }
    }
  
    box.select = function(n) {
      highlight(box.selected, false);
      n = Math.max(0, Math.min(box.children.length - 1, n));
      if (n == -1) {
        return;
      }
      box.selected = n;
      highlight(n, true);
    }
  
    box.getSelectedItem = function() {
      return box.children[box.selected];
    }
  
    function highlight(n, on) {
      var item = box.children[n];
      if (!item) {
        return;
      }
      item.style.inverse = on;
    }
  }