module Bovem::ConsoleMethods::Interactions
Methods to interact with the user and other processes.
Public Instance Methods
Reads a string from the console.
@param prompt [String|Boolean] A prompt to show. If `true`, `Please insert a value:` will be used, if `nil` or `false` no prompt will be shown. @param default_value [String] Default value if user simply pressed the enter key. @param validator [Array|Regexp] An array of values or a Regexp to match the submitted value against. @param echo [Boolean] If to show submitted text to the user. **Not supported and thus ignored on Rubinius.**
# File lib/bovem/console.rb, line 564 def read(prompt: true, default_value: nil, validator: nil, echo: true) prompt = sanitize_prompt(prompt) validator = sanitize_validator(validator) begin catch(:reply) do loop do reply = validate_input_value(read_input_value(prompt, echo, default_value), validator) handle_reply(reply) end end rescue Interrupt default_value end end
Executes a block of code in a indentation region and then prints out and ending status message.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param indented_banner [Boolean] If also the banner should be indented. @param full_colored [Boolean] If the banner should be fully colored. @param block_indentation [Fixnum] The new width for the indented region. @param block_indentation_absolute [Boolean] If the new width should not be added to the current one but rather replace it. @return [Symbol] The exit status for the block.
# File lib/bovem/console.rb, line 593 def task( message = nil, suffix: "\n", indented: true, wrap: false, plain: false, indented_banner: false, full_colored: false, block_indentation: 2, block_indentation_absolute: false ) status = nil if message.present? self.begin(message, suffix: suffix, indented: indented, wrap: wrap, plain: plain, indented_banner: indented_banner, full_colored: full_colored) end with_indentation(block_indentation, block_indentation_absolute) do rv = block_given? ? yield.ensure_array : [:ok] # Execute block exit_task(message, rv, plain) # Handle task exit status = rv[0] # Return value end status end