Module: CultomePlayer::Command::Reader

Included in:
CultomePlayer::Command
Defined in:
lib/cultome_player/command/reader.rb

Instance Method Summary collapse

Instance Method Details

#command_readerReadline

Lazy getter for readline object.

Returns:

  • (Readline)

    The readline object



26
27
28
29
30
31
32
33
34
# File 'lib/cultome_player/command/reader.rb', line 26

def command_reader
  return Readline if @command_reader_initialized

  Readline.completion_append_character = ""
  Readline.basic_word_break_characters = Readline.basic_word_break_characters.delete("@")
  Readline.completion_proc = completion_proc
  @command_reader_initialized = true
  return Readline
end

#read_command(prompt) ⇒ String

Display a prompt and read user input.

Parameters:

  • prompt (String)

    The message to display to user for arcking for input.

Returns:

  • (String)

    The user input readed.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cultome_player/command/reader.rb', line 10

def read_command(prompt)
  input = command_reader.readline(c5(prompt), true)

  # evitamos que comando consecutivos repetidos o vacios queden en el historial
  if input.empty?
    command_reader::HISTORY.pop
  elsif command_reader::HISTORY.to_a.reverse[1] == input
    command_reader::HISTORY.pop
  end

  return input
end