File: demo.rb

package info (click to toggle)
ruby-tty-prompt 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,452 kB
  • sloc: ruby: 8,847; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 717 bytes parent folder | download
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
# frozen_string_literal: true

require "json"
require_relative "../lib/tty-prompt"

prompt = TTY::Prompt.new
envs = %w[local development test staging production]
platforms = %w[Debian Ubuntu Fedora Windows macOS]

puts TTY::Cursor.save

result = prompt.collect do
  key(:username).ask("Username:")
  key(:password).mask("Password:")
  key(:env).select("Environment:", envs)
  key(:version).ask("Version (1-10)?", convert: :int, in: (1..10))
  key(:verbose).yes?("Verbose?")
  key(:platforms).multi_select("Platforms?", platforms)
  key(:nodes).slider("Number of nodes?", max: 20, step: 1)
end

print TTY::Cursor.clear_screen_up
print TTY::Cursor.restore + TTY::Cursor.show
puts
puts JSON.pretty_generate(result)
puts