File: select.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 (20 lines) | stat: -rw-r--r-- 402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

require_relative "../lib/tty-prompt"

prompt = TTY::Prompt.new

warriors = %i[Scorpion Kano Jax Kitana Raiden]

prompt.on(:keypress) do |event|
  prompt.trigger(:keydown) if event.value == "j"
  prompt.trigger(:keyup) if event.value == "k"
end

prompt.on(:keyescape) do |event|
  exit(1)
end

answer = prompt.select("Choose your destiny?", warriors)

puts answer.inspect