code: func Ellipsis(s string, maxDisplayWidth int) string {
  	if maxDisplayWidth <= 0 {
  		return ""
  	}
  	rs := []rune(s)
  	if maxDisplayWidth == 1 {
  		return string(rs[0])
  	}
  
  	byteLen := len(s)
  	if byteLen == utf8.RuneCountInString(s) {
  		if byteLen <= maxDisplayWidth {
  			return s
  		}
  		return string(rs[:maxDisplayWidth-1]) + "…"
  	}
  
  	var (
  		display      []int
  		displayWidth int
  	)
  	for _, r := range rs {
  		cw := charWidth(r)
  		displayWidth += cw
  		display = append(display, displayWidth)
  	}
  	if displayWidth <= maxDisplayWidth {
  		return s
  	}
  	for i := range display {
  		if display[i] <= maxDisplayWidth-1 && display[i+1] > maxDisplayWidth-1 {
  			return string(rs[:i+1]) + "…"
  		}
  	}
  	return s
  }
docs: // Ellipsis truncates a string to fit within maxDisplayWidth, and appends ellipsis (…).
  // For maxDisplayWidth of 1 and lower, no ellipsis is appended.
  // For maxDisplayWidth of 1, first char of string will return even if its width > 1.