def _align_center(to_align: str, length: int) -> str:
    """
    Aligns a string so that it has a certain length and is center-justified.
    :param to_align: The string to align.
    :param length: The target length of the string. We will pad the string
    on either side with spaces to reach this length.
    :return: The padded string.
    """
    assert length >= len(to_align), "Length cannot be shorter than string."

    per_side_padding_length = (length - len(to_align)) // 2
    padding = " " * per_side_padding_length
    padded = f"{padding}{to_align}{padding}"

    # Because of integer division, we could have an off-by-one error.
    if len(padded) != length:
        padded += " "

    return padded