class Reply::Reader

Overview

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

Defined in:

reader.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def 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}


[View source]
def 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.


[View source]
def auto_completion_display_selected_entry(io : IO, entry : String) #

Override to customize how the selected entry is displayed.

default: entry bright on dark grey


[View source]
def auto_completion_display_title(io : IO, title : String) #

Override to customize how title is displayed.

default: title underline + ":"


[View source]
def clear_history #

Clear the history and the #history_file.


[View source]
def color=(arg) #

[View source]
def color?(*args, **options) #

[View source]
def color?(*args, **options, &) #

[View source]
def continue?(expression : String) #

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

default: false


[View source]
def editor : ExpressionEditor #

[View source]
def format(expression : String) #

Override to enable reformatting after submitting.

default: unchanged expression


[View source]
def highlight(expression : String) #

Override to enable expression highlighting.

default: uncolored expression


[View source]
def history : Reply::History #

[View source]
def history_file #

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

default: nil


[View source]
def indentation_level(expression_before_cursor : String) #

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

default: 0


[View source]
def line_number : Int32 #

[View source]
def lines(*args, **options) #

[View source]
def lines(*args, **options, &) #

[View source]
def output(*args, **options) #

[View source]
def output(*args, **options, &) #

[View source]
def output=(arg) #

[View source]
def prompt(io : IO, line_number : Int32, color? : Bool) #

Override to customize the prompt.

Toggle the colorization following color?.

default: $:001>


[View source]
def read_loop(& : String -> _) #

[View source]
def read_next(from io : IO = STDIN) : String | Nil #

[View source]
def reindent_line(line : String) #

Override to enable line re-indenting.

This methods is called each time a character is entered.

You should return either:

See example/crystal_repl.

default: nil


[View source]
def reset #

Reset the line number and close auto-completion results.


[View source]
def save_in_history?(expression : String) #

Override to select with expression is saved in history.

default: !expression.blank?


[View source]
def word_delimiters(*args, **options) #

[View source]
def word_delimiters(*args, **options, &) #

[View source]
def word_delimiters=(arg) #

[View source]