File: multi_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 (28 lines) | stat: -rw-r--r-- 481 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
27
28
# frozen_string_literal: true

require "benchmark/ips"

require_relative "../lib/tty/test_prompt"

prompt = TTY::TestPrompt.new

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

100.times do
  prompt.input << " " << "j"
end

prompt.input << "\r"

choices = (1..10_000).to_a

Benchmark.ips do |bench|
  bench.config(time: 10, warmup: 4)

  bench.report("selecting") do
    prompt.input.rewind
    prompt.multi_select("Which number?", choices)
  end
end