code: function substrWidth(stringWidth, str, startWidth, width) {
  	var length = width;
  	var start = startWidth;
  	var prefixSpace = 0, suffixSpace;
  	if (stringWidth !== false) {
  		start = indexOfWidth(stringWidth, str, startWidth);
  		if (getWidth(stringWidth, str.substr(0, start)) < startWidth) {
  			start++;
  			prefixSpace = getWidth(stringWidth, str.substr(0, start)) - startWidth;
  		}
  		length = indexOfWidth(stringWidth, str.substr(start), width - prefixSpace);
  		suffixSpace = Math.min(width, getWidth(stringWidth, str.substr(start))) -
  			(prefixSpace + getWidth(stringWidth, str.substr(start, length)));
  	}
  	return repeat(" ", prefixSpace) + str.substr(start, length) + repeat(" ", suffixSpace);
  }
docs: extract parts of string, beginning at the character at the specified position,
  and returns the specified width of characters. if the character is incomplete,
  it will be replaced by space.
  @params {string} str - string to calculate
  @params {number} start - the beginning position of string
  @params {number} width - the width of target string
  @params {boolean} stringWidth - calculate width by wcwidth or String.length