import shutil


def center_text(msg: str, *, pad: str = ' ') -> str:
    """Centers text horizontally for display within the current terminal, optionally padding both sides.

    :param msg: message to display in the center
    :param pad: if provided, the first character will be used to pad both sides of the message
    :return: centered message, optionally padded on both sides with pad_char
    """
    term_width = shutil.get_terminal_size().columns
    surrounded_msg = ' {} '.format(msg)
    if not pad:
        pad = ' '
    fill_char = pad[:1]
    return surrounded_msg.center(term_width, fill_char)