Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. def header(text, width=80, palette=_DefaultPalette, nonewline=False):
  2.  
  3. # Calculate the length of the filler, accounting for padding
  4. # and the brackets.
  5. flen = width - len(text)-6
  6.  
  7. # Format the output. Ideally we would have a global palette defined
  8. # and we'd pull colors from that but for now, they're hardcoded.
  9. out = "|%s--[|n |%s%s|n |%s]%s|n" % (palette['header'], palette['headertxt'], text, palette['header'], flen * "-")
  10.  
  11. # Append a newline if desired.
  12. if nonewline:
  13. return out
  14. else:
  15. return "%s\n" % out
  16.  
  17. def subheader(text, width=80, palette=_DefaultPalette, nonewline=False):
  18.  
  19. if not text or len(text) == 0:
  20. return "|R%s|n" % ("-" * width)
  21.  
  22. # Determine the width of the text, accounting for padding.
  23. l = len(text) + 2
  24.  
  25. # Calculate the length of each segment.
  26. lsp = rsp = (width - l) / 2
  27.  
  28. # If the length of the string is not evenly divisible by 2,
  29. # our header will be one character off. Fix that.
  30. rsp += (width - l) % 2
  31.  
  32. # Format the output.
  33. out = "|R%s|n |530%s|n |R%s|n" % (lsp * "-", text, rsp * "-")
  34.  
  35. # Add a trailing newline, if desired.
  36. if nonewline:
  37. return out
  38. else:
  39. return "%s\n" % out
  40.  
  41.  
  42. # ---------------------------------------------------------------------------
  43. #
  44. # ---------------------------------------------------------------------------
  45. def footer(text, width=80, palette=_DefaultPalette, nonewline=False):
  46.  
  47. # Calculate the length of the filler, accounting for padding and the
  48. # static parts. This means 2 spaces for padding, and 4
  49. # for the static parts ie the '[]--' characters. 6 total.
  50. flen = width - len(text) - 6
  51.  
  52. # Format the output.
  53. out = "|R%s[|n |530%s|n |R]--|n" % (flen * '-', text)
  54.  
  55. # Append a newline if desired.
  56. if nonewline:
  57. return out
  58. else:
  59. return "%s\n" % out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement