Skip to content

Commit

Permalink
Added a "default_line" parameter to the readline method, which pre-po…
Browse files Browse the repository at this point in the history
…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 925b91d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/coolline/coolline.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 925b91d

Please sign in to comment.