-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathexample.py
executable file
·71 lines (56 loc) · 2.26 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /usr/bin/env python3
"""Example script demonstrating usage of beaupy.
"""
import time
from beaupy import *
from beaupy.spinners import *
# Confirm a dialog
if confirm("Will you take the ring to Mordor?"):
names = [
"Frodo Baggins",
"Samwise Gamgee",
"Legolas",
"Aragorn",
"[red]Sauron[/red]",
]
console.print("Who are you?")
# Choose one item from a list
name = select(names, cursor="🢧", cursor_style="cyan")
console.print(f"Alámenë, {name}")
item_options = [
"The One Ring",
"Dagger",
"Po-tae-toes",
"Lightsaber (Wrong franchise! Nevermind, roll with it!)",
]
console.print("What do you bring with you?")
# Choose multiple options from a list
items = select_multiple(item_options, tick_character='🎒', ticked_indices=[0], maximal_count=3)
potato_count = 0
if "Po-tae-toes" in items:
# Prompt with type conversion and validation
potato_count = prompt('How many potatoes?', target_type=int, validator=lambda count: count > 0)
# Spinner to show while doing some work
spinner = Spinner(DOTS, "Packing things...")
spinner.start()
time.sleep(2)
spinner.stop()
# Get input without showing it being typed
if "friend" == prompt("Speak, [blue bold underline]friend[/blue bold underline], and enter", secure=True).lower():
# Custom spinner animation
spinner_animation = ['▉▉', '▌▐', ' ', '▌▐', '▉▉']
spinner = Spinner(spinner_animation, "Opening the Door of Durin...")
spinner.start()
time.sleep(2)
spinner.stop()
else:
spinner_animation = ['🐙🌊 ⚔️ ', '🐙 🌊 ⚔️ ', '🐙 🌊 ⚔️ ', '🐙 🌊 ⚔️ ', '🐙 🌊⚔️ ']
spinner = Spinner(spinner_animation, "Getting attacked by an octopus...")
spinner.start()
time.sleep(2)
spinner.stop()
if 'The One Ring' in items:
console.print("[green]You throw The One Ring to a lava from an eagle![/green]")
else:
console.print("[red]You forgot the ring and brought Middle-Earth to its knees![/red]")
console.print(f"And you brought {potato_count} taters!")