import math


def text_center(text, width, padchar=" "):
    """
    Center `text` in a string of width `width` padded on both sides by varying
    lengths of `padchar`.
    """
    tlen = len(text)
    out = ""
    if tlen > width:
        # Append "..." to signify a continuation.
        out = "..."+text[(-1*width)+2:-1]
    elif tlen < width:
        # If we need to pad, add characters to both sides.
        remain = (width-tlen)
        clip1 = math.ceil(remain/2)
        clip2 = remain-clip1
        out = (padchar*clip1)+text+(padchar*clip2)
    return out