class Reply::Reader
- Reply::Reader
- Reference
- Object
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.crConstructors
Instance Method Summary
-
#auto_complete(current_word : String, expression_before : String)
Override to integrate auto-completion.
-
#auto_completion_display_entry(io : IO, entry_matched : String, entry_remaining : String)
Override to customize how entry is displayed.
-
#auto_completion_display_selected_entry(io : IO, entry : String)
Override to customize how the selected entry is displayed.
-
#auto_completion_display_title(io : IO, title : String)
Override to customize how title is displayed.
-
#clear_history
Clear the history and the
#history_file
. - #color=(arg)
- #color?(*args, **options)
- #color?(*args, **options, &)
-
#continue?(expression : String)
Override this method to makes the interface continue on multiline, depending of the expression.
- #editor : ExpressionEditor
-
#format(expression : String)
Override to enable reformatting after submitting.
-
#highlight(expression : String)
Override to enable expression highlighting.
- #history : Reply::History
-
#history_file
Override to indicate the
Path|String|IO
where the history is saved. -
#indentation_level(expression_before_cursor : String)
Override to return the expected indentation level in function of expression before cursor.
- #line_number : Int32
- #lines(*args, **options)
- #lines(*args, **options, &)
- #output(*args, **options)
- #output(*args, **options, &)
- #output=(arg)
-
#prompt(io : IO, line_number : Int32, color? : Bool)
Override to customize the prompt.
- #read_loop(& : String -> _)
- #read_next(from io : IO = STDIN) : String | Nil
-
#reindent_line(line : String)
Override to enable line re-indenting.
-
#reset
Reset the line number and close auto-completion results.
-
#save_in_history?(expression : String)
Override to select with expression is saved in history.
- #word_delimiters(*args, **options)
- #word_delimiters(*args, **options, &)
- #word_delimiters=(arg)
Constructor Detail
Instance Method Detail
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}
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.
Override to customize how the selected entry is displayed.
default: entry
bright on dark grey
Override to customize how title is displayed.
default: title
underline + ":"
Override this method to makes the interface continue on multiline, depending of the expression.
default: false
Override to enable reformatting after submitting.
default: unchanged expression
Override to enable expression highlighting.
default: uncolored expression
Override to indicate the Path|String|IO
where the history is saved. If nil
, the history is not persistent.
default: nil
Override to return the expected indentation level in function of expression before cursor.
default: 0
Override to customize the prompt.
Toggle the colorization following color?.
default: $:001>
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 itInt32
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
Override to select with expression is saved in history.
default: !expression.blank?