diff --git a/lib/coolline/coolline.rb b/lib/coolline/coolline.rb index c9346ee..fde3c3f 100644 --- a/lib/coolline/coolline.rb +++ b/lib/coolline/coolline.rb @@ -183,21 +183,20 @@ def word_boundaries=(array) # Reads a line from the terminal # @param [String] prompt Characters to print before each line - def readline(prompt = ">> ") + def readline(prompt = ">> ", default_line = "") @prompt = prompt @history.delete_empty - @line = "" - @pos = 0 + @line = default_line + @pos = @line.size @accumulator = nil @history_moved = false @should_exit = false - reset_line - print @prompt + render @history.index = @history.size - 1 @history << @line @@ -407,6 +406,11 @@ def word_boundary?(char) char =~ word_boundaries_regexp end + def replace_line(new_line) + @line = new_line + @pos = new_line.size + end + private def transform(line) @transform_proc.call(line)