mirror of
https://github.com/charmbracelet/gum
synced 2024-06-10 09:42:16 +02:00
docs: show how to embed gum
in python and ruby scripts
This commit is contained in:
parent
da961b423b
commit
a6a02289f0
7
examples/gum.py
Normal file
7
examples/gum.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
import subprocess
|
||||
|
||||
print("What's your favorite language?")
|
||||
|
||||
result = subprocess.run(["gum", "choose", "Go", "Python"], stdout=subprocess.PIPE, text=True)
|
||||
|
||||
print(f"I like {result.stdout.strip()}, too!")
|
29
examples/gum.rb
Normal file
29
examples/gum.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
puts 'What is your name?'
|
||||
name = `gum input --placeholder "Your name"`.chomp
|
||||
|
||||
puts "Hello #{name}!"
|
||||
|
||||
puts 'Pick your 2 favorite colors'
|
||||
|
||||
COLORS = {
|
||||
'Red' => '#FF0000',
|
||||
'Blue' => '#0000FF',
|
||||
'Green' => '#00FF00',
|
||||
'Yellow' => '#FFFF00',
|
||||
'Orange' => '#FFA500',
|
||||
'Purple' => '#800080',
|
||||
'Pink' => '#FF00FF'
|
||||
}.freeze
|
||||
|
||||
colors = `gum choose #{COLORS.keys.join(' ')} --limit 2`.chomp.split("\n")
|
||||
|
||||
if colors.length == 2
|
||||
first = `gum style --foreground '#{COLORS[colors[0]]}' '#{colors[0]}'`.chomp
|
||||
second = `gum style --foreground '#{COLORS[colors[1]]}' '#{colors[1]}'`.chomp
|
||||
puts "You chose #{first} and #{second}."
|
||||
elsif colors.length == 1
|
||||
first = `gum style --foreground '#{COLORS[colors[0]]}' '#{colors[0]}'`.chomp
|
||||
puts "You chose #{first}."
|
||||
else
|
||||
puts "You didn't pick any colors!"
|
||||
end
|
Loading…
Reference in a new issue