Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def header(text, width=80, palette=_DefaultPalette, nonewline=False):
- # Calculate the length of the filler, accounting for padding
- # and the brackets.
- flen = width - len(text)-6
- # Format the output. Ideally we would have a global palette defined
- # and we'd pull colors from that but for now, they're hardcoded.
- out = "|%s--[|n |%s%s|n |%s]%s|n" % (palette['header'], palette['headertxt'], text, palette['header'], flen * "-")
- # Append a newline if desired.
- if nonewline:
- return out
- else:
- return "%s\n" % out
- def subheader(text, width=80, palette=_DefaultPalette, nonewline=False):
- if not text or len(text) == 0:
- return "|R%s|n" % ("-" * width)
- # Determine the width of the text, accounting for padding.
- l = len(text) + 2
- # Calculate the length of each segment.
- lsp = rsp = (width - l) / 2
- # If the length of the string is not evenly divisible by 2,
- # our header will be one character off. Fix that.
- rsp += (width - l) % 2
- # Format the output.
- out = "|R%s|n |530%s|n |R%s|n" % (lsp * "-", text, rsp * "-")
- # Add a trailing newline, if desired.
- if nonewline:
- return out
- else:
- return "%s\n" % out
- # ---------------------------------------------------------------------------
- #
- # ---------------------------------------------------------------------------
- def footer(text, width=80, palette=_DefaultPalette, nonewline=False):
- # Calculate the length of the filler, accounting for padding and the
- # static parts. This means 2 spaces for padding, and 4
- # for the static parts ie the '[]--' characters. 6 total.
- flen = width - len(text) - 6
- # Format the output.
- out = "|R%s[|n |530%s|n |R]--|n" % (flen * '-', text)
- # Append a newline if desired.
- if nonewline:
- return out
- else:
- return "%s\n" % out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement