class

Crab::Prompt

Inherits Reference / Object

A class to better handle the user input It is used to create a prompt with a text

Constructors

new(text : String, is_password : Bool = false, options : Array(String) = [] of String, empty_allow : Bool = false)

Create a new Prompt object It's parameters are: text: The text to be display with the prompt, it can have crab codes is_password: A boolean to set if the prompt is a password, default is false options: An array of strings with the options to be display, default is [], example ["yes", "no"] empty_allow: A boolean to set if the prompt can be empty, default is false

Source

Instance methods

answer
Source
answer=(answer : String)
Source
ask

A method to ask the user for an answer It prints the text and the options if they are set It returns the answer if it is valid It uses the check_answer method to check if the answer is valid

Source
check_answer

A methos to make sure the prompt is valid It checks if the answer is valid, if not it asks again It returns the answer if it is valid

Source
empty_allow
Source
empty_allow=(empty_allow : Bool)
Source
is_password
Source
is_password=(is_password : Bool)
Source
options
Source
options=(options : Array(String))
Source
text
Source
text=(text : String)
Source