Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import shutil
- >>> lines = ['String right here', 'And here', 'Here', 'A-a-a-and here']
- >>> width = shutil.get_terminal_size().columns
- >>> position = (width - max(map(len, lines))) // 2
- >>> for line in lines: # left justtified
- ... print(' '*position + line)
- ...
- String right here
- And here
- Here
- A-a-a-and here
- >>> for line in lines: # right justified
- ... print(line.rjust(width // 2))
- ...
- String right here
- And here
- Here
- A-a-a-and here
- >>> for line in lines: # center
- ... print(line.center(width))
- ...
- String right here
- And here
- Here
- A-a-a-and here
- #!/usr/bin/env python
- from blessings import Terminal # $ pip install blessings
- lines = ['String right here', 'And here', 'Here', 'A-a-a-and here']
- term = Terminal()
- with term.hidden_cursor(), term.fullscreen():
- for i, line in enumerate(lines):
- x = (term.width - max(map(len, lines))) // 2
- y = (term.height - len(lines)) // 2 + i
- with term.location(x, y):
- print(term.bold_white_on_black(line))
- with term.location(0, term.height - 1):
- input('press <Enter> to exit..')
- colorama
- #!/usr/bin/env python
- from asciimatics.effects import Print # $ pip install asciimatics
- from asciimatics.renderers import FigletText, SpeechBubble, Rainbow
- from asciimatics.scene import Scene
- from asciimatics.screen import Screen
- from asciimatics.exceptions import ResizeScreenError
- def demo(screen):
- lines = ['String right here', 'And here', 'Here', 'A-a-a-and here']
- renderers = [Rainbow(screen, FigletText(line, font='small'))
- for line in lines]
- x = (screen.width - max(r.max_width for r in renderers)) // 2
- H = max(r.max_height for r in renderers) - 1 # text height
- effects = [Print(screen, renderer,
- y=(screen.height - H * len(renderers)) // 2 + i * H, x=x)
- for i, renderer in enumerate(renderers)]
- effects.append(Print(screen,
- SpeechBubble("Press X to exit"),
- screen.height - 5,
- speed=1, transparent=False,
- start_frame=100))
- screen.play([Scene(effects, -1)], stop_on_resize=True)
- if __name__ == "__main__":
- while True:
- try:
- Screen.wrapper(demo)
- except ResizeScreenError:
- continue
- else:
- break
Add Comment
Please, Sign In to add comment