def text_extend(text, width, padchar=" "):
    """
    Pad string `text` to width `width` using char `padchar`.

    Extend a string 'smartly', that is, don't extend, reduce, if it's already
    too long.
    """
    out = text.ljust(width, padchar)
    if len(out) > width:
        return "..."+out[(-1*width)+2:-1]
    return out