Guest User

Untitled

a guest
Feb 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. >>> import shutil
  2. >>> lines = ['String right here', 'And here', 'Here', 'A-a-a-and here']
  3. >>> width = shutil.get_terminal_size().columns
  4. >>> position = (width - max(map(len, lines))) // 2
  5. >>> for line in lines: # left justtified
  6. ... print(' '*position + line)
  7. ...
  8. String right here
  9. And here
  10. Here
  11. A-a-a-and here
  12. >>> for line in lines: # right justified
  13. ... print(line.rjust(width // 2))
  14. ...
  15. String right here
  16. And here
  17. Here
  18. A-a-a-and here
  19. >>> for line in lines: # center
  20. ... print(line.center(width))
  21. ...
  22. String right here
  23. And here
  24. Here
  25. A-a-a-and here
  26.  
  27. #!/usr/bin/env python
  28. from blessings import Terminal # $ pip install blessings
  29.  
  30. lines = ['String right here', 'And here', 'Here', 'A-a-a-and here']
  31. term = Terminal()
  32. with term.hidden_cursor(), term.fullscreen():
  33. for i, line in enumerate(lines):
  34. x = (term.width - max(map(len, lines))) // 2
  35. y = (term.height - len(lines)) // 2 + i
  36. with term.location(x, y):
  37. print(term.bold_white_on_black(line))
  38.  
  39. with term.location(0, term.height - 1):
  40. input('press <Enter> to exit..')
  41.  
  42. colorama
  43.  
  44. #!/usr/bin/env python
  45. from asciimatics.effects import Print # $ pip install asciimatics
  46. from asciimatics.renderers import FigletText, SpeechBubble, Rainbow
  47. from asciimatics.scene import Scene
  48. from asciimatics.screen import Screen
  49. from asciimatics.exceptions import ResizeScreenError
  50.  
  51.  
  52. def demo(screen):
  53. lines = ['String right here', 'And here', 'Here', 'A-a-a-and here']
  54. renderers = [Rainbow(screen, FigletText(line, font='small'))
  55. for line in lines]
  56. x = (screen.width - max(r.max_width for r in renderers)) // 2
  57. H = max(r.max_height for r in renderers) - 1 # text height
  58. effects = [Print(screen, renderer,
  59. y=(screen.height - H * len(renderers)) // 2 + i * H, x=x)
  60. for i, renderer in enumerate(renderers)]
  61. effects.append(Print(screen,
  62. SpeechBubble("Press X to exit"),
  63. screen.height - 5,
  64. speed=1, transparent=False,
  65. start_frame=100))
  66. screen.play([Scene(effects, -1)], stop_on_resize=True)
  67.  
  68. if __name__ == "__main__":
  69. while True:
  70. try:
  71. Screen.wrapper(demo)
  72. except ResizeScreenError:
  73. continue
  74. else:
  75. break
Add Comment
Please, Sign In to add comment