Permalink
Browse files

Added a "default_line" parameter to the readline method, which pre-po…

…pulates the input line with the string of your choice. Also added a "replace_line" method, for use in callbacks that replace the entire line.
  • Loading branch information...
epitron committed Mar 11, 2013
1 parent 533d4f7 commit 925b91d8ddc109c09b62cff90c1a276901a5ea86
Showing with 9 additions and 5 deletions.
  1. +9 −5 lib/coolline/coolline.rb
View
@@ -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)

0 comments on commit 925b91d

Please sign in to comment.