[macruby-changes] [4854] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sun Oct 31 15:51:27 PDT 2010
Revision: 4854
http://trac.macosforge.org/projects/ruby/changeset/4854
Author: eloy.de.enige at gmail.com
Date: 2010-10-31 15:51:25 -0700 (Sun, 31 Oct 2010)
Log Message:
-----------
If process a new input line changes the indentation, update the previously printed version and indent the prompt.
Modified Paths:
--------------
DietRB/trunk/lib/irb/driver/readline.rb
DietRB/trunk/lib/irb/driver/tty.rb
DietRB/trunk/spec/driver/readline_spec.rb
DietRB/trunk/spec/driver/tty_spec.rb
Modified: DietRB/trunk/lib/irb/driver/readline.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/readline.rb 2010-10-31 22:51:16 UTC (rev 4853)
+++ DietRB/trunk/lib/irb/driver/readline.rb 2010-10-31 22:51:25 UTC (rev 4854)
@@ -15,7 +15,7 @@
end
def readline
- source = ::Readline.readline(context.prompt, true)
+ source = ::Readline.readline(prompt, true)
IRB::History.input(source)
source
end
Modified: DietRB/trunk/lib/irb/driver/tty.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/tty.rb 2010-10-31 22:51:16 UTC (rev 4853)
+++ DietRB/trunk/lib/irb/driver/tty.rb 2010-10-31 22:51:25 UTC (rev 4854)
@@ -4,6 +4,7 @@
module Driver
class TTY
attr_reader :input, :output, :context_stack
+ attr_accessor :auto_indent # TODO: this should probably go to a more global config, which means we shouldn't completely deprecate the CONF
def initialize(input = $stdin, output = $stdout)
@input = input
@@ -14,9 +15,13 @@
def context
@context_stack.last
end
+
+ def prompt
+ context.prompt(@auto_indent)
+ end
def readline
- @output.print(context.prompt)
+ @output.print(prompt)
@input.gets
end
@@ -36,6 +41,10 @@
@output.print clear_last_line
@output.puts(context.prompt + reformatted_line)
end
+
+ def process_input(line)
+ context.process_line(line) { |new_line| last_line_decreased_indentation_level(new_line) }
+ end
# Feeds input into a given context.
#
@@ -44,7 +53,8 @@
def run(context)
@context_stack << context
while line = consume
- break unless context.process_line(line)
+ continue = process_input(line)
+ break unless continue
end
ensure
@context_stack.pop
Modified: DietRB/trunk/spec/driver/readline_spec.rb
===================================================================
--- DietRB/trunk/spec/driver/readline_spec.rb 2010-10-31 22:51:16 UTC (rev 4853)
+++ DietRB/trunk/spec/driver/readline_spec.rb 2010-10-31 22:51:25 UTC (rev 4854)
@@ -41,6 +41,7 @@
@driver = IRB::Driver::Readline.new(InputStub.new, OutputStub.new)
@context = IRB::Context.new(Object.new)
@driver.context_stack << @context
+ Readline.clear_printed!
end
it "is a subclass of IRB::Driver::TTY" do
@@ -61,6 +62,21 @@
@driver.readline.should == "nom nom nom"
end
+ it "prints a prompt" do
+ @context.source << "def foo"
+ Readline.stub_input "nom nom nom"
+ @driver.readline
+ Readline.printed.should == @context.prompt
+ end
+
+ it "prints a prompt with indentation if it's configured" do
+ @driver.auto_indent = true
+ @context.source << "def foo"
+ Readline.stub_input "nom nom nom"
+ @driver.readline
+ Readline.printed.should == @context.prompt(true)
+ end
+
it "tells the Readline module to use the history" do
Readline.use_history = false
Readline.stub_input "nom nom nom"
Modified: DietRB/trunk/spec/driver/tty_spec.rb
===================================================================
--- DietRB/trunk/spec/driver/tty_spec.rb 2010-10-31 22:51:16 UTC (rev 4853)
+++ DietRB/trunk/spec/driver/tty_spec.rb 2010-10-31 22:51:25 UTC (rev 4854)
@@ -9,10 +9,19 @@
end
it "prints the prompt and reads a line of input" do
+ @context.source << "def foo"
@driver.input.stub_input "calzone"
@driver.readline.should == "calzone"
@driver.output.printed.should == @context.prompt
end
+
+ it "prints a prompt with indentation if it's configured" do
+ @driver.auto_indent = true
+ @context.source << "def foo"
+ @driver.input.stub_input "calzone"
+ @driver.readline
+ @driver.output.printed.should == @context.prompt(true)
+ end
it "consumes input" do
@driver.input.stub_input "calzone"
@@ -67,4 +76,4 @@
# irb(o)
# IRBRan.should == o
# end
-# end
\ No newline at end of file
+# end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101031/d288b3c6/attachment.html>
More information about the macruby-changes
mailing list