Module: Slk::Support::InteractivePrompt
- Included in:
- Commands::Catchup
- Defined in:
- lib/slk/support/interactive_prompt.rb
Overview
Interactive terminal prompt utilities
Class Method Summary collapse
-
.prompt_for_action(prompt) ⇒ Object
Display a prompt and read a single character.
-
.read_single_char ⇒ Object
Read a single character from the terminal.
Class Method Details
.prompt_for_action(prompt) ⇒ Object
Display a prompt and read a single character
21 22 23 24 25 26 |
# File 'lib/slk/support/interactive_prompt.rb', line 21 def prompt_for_action(prompt) print "\n#{prompt} > " input = read_single_char puts input end |
.read_single_char ⇒ Object
Read a single character from the terminal
10 11 12 13 14 15 16 17 18 |
# File 'lib/slk/support/interactive_prompt.rb', line 10 def read_single_char if $stdin.tty? $stdin.raw(&:readchar) else $stdin.gets&.chomp end rescue Interrupt 'q' end |