docs: show how to embed gum in python and ruby scripts

This commit is contained in:
Maas Lalani 2022-07-21 17:49:47 -04:00
parent da961b423b
commit a6a02289f0
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
2 changed files with 36 additions and 0 deletions

7
examples/gum.py Normal file
View 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
View 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