class

Reply::Reader

Inherits Reference < Object

Reader for your REPL.

Create a subclass of it and override methods to customize behavior.

class MyReader < Reply::Reader
  def prompt(io, line_number, color)
    io << "reply> "
  end
end

Run the REPL with run:

reader = MyReader.new

reader.run do |expression|
  # Eval expression here
  puts " => #{expression}"
end

Or with read_next:

loop do
  expression = reader.read_next
  break unless expression

  # Eval expression here
  puts " => #{expression}"
end

Constructors

Instance methods

auto_complete(current_word : String, expression_before : String)

Override to integrate auto-completion.

current_word is picked following word_delimiters. It expects to return Tuple with:

  • a title : String
  • the auto-completion results : Array(String)

default: {"", [] of String}

Source
auto_completion_display_entry(io : IO, entry_matched : String, entry_remaining : String)

Override to customize how entry is displayed.

Entry is split in two (entry_matched + entry_remaining). entry_matched correspond to the part already typed when auto-completion was triggered.

default: entry_matched bright + entry_remaining normal.

Source
auto_completion_display_selected_entry(io : IO, entry : String)

Override to customize how the selected entry is displayed.

default: entry bright on dark grey

Source
auto_completion_display_title(io : IO, title : String)

Override to customize how title is displayed.

default: title underline + ":"

Source
auto_completion_retrigger_when(current_word : String) : Bool

Override to retrigger auto completion when condition is met.

default: false

Source
clear_history

Clear the history and the history_file.

Source
color=(arg)
Source
color?(*args, **options)
Source
color?(*args, **options, &)
Source
continue?(expression : String)

Override this method to makes the interface continue on multiline, depending of the expression.

default: false

Source
disable_search?

Override with true to disable the reverse i-search (ctrl-r).

default: true (disabled) if history_file not set.

Source
documentation(entry : String)

Override to set the entire documentation for an autocompletion entry.

If not nil, the documentation is shown in its own alternate screen when alt-d is pressed.

default: nil

Source
documentation_summary(entry : String)

Override to set the documentation summary for an autocompletion entry.

If not nil, the summary is shown below the prompt, only one line is currently supported

default: first line of documentation.

Source
editor
Source
format(expression : String)

Override to enable reformatting after submitting.

default: unchanged expression

Source
highlight(expression : String)

Override to enable expression highlighting.

default: uncolored expression

Source
history
Source
history_file

Override to indicate the Path|String|IO where the history is saved. If nil, the history is not persistent.

default: nil

Source
indentation_level(expression_before_cursor : String)

Override to return the expected indentation level in function of expression before cursor.

default: 0

Source
line_number
Source
lines(*args, **options)
Source
lines(*args, **options, &)
Source
output(*args, **options)
Source
output(*args, **options, &)
Source
output=(arg)
Source
prompt(io : IO, line_number : Int32, color : Bool)

Override to customize the prompt.

Toggle the colorization following color.

default: $:001>

Source
read_loop
Source
read_next(from io : IO = STDIN) : String | Nil
Source
reindent_line(line : String)

Override to enable line re-indenting.

This methods is called each time a character is entered.

You should return either:

  • nil: keep the line as it
  • Int32 value: re-indent the line by an amount equal to the returned value, relatively to indentation_level. (0 to follow indentation_level)

See example/crystal_repl.

default: nil

Source
reset

Reset the line number and close auto-completion results.

Source
save_in_history?(expression : String)

Override to select which expression is saved in history.

default: !expression.blank?

Source
word_delimiters(*args, **options)
Source
word_delimiters(*args, **options, &)
Source
word_delimiters=(arg)
Source

Nested types