[macruby-changes] [4857] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sun Oct 31 15:51:53 PDT 2010
Revision: 4857
http://trac.macosforge.org/projects/ruby/changeset/4857
Author: eloy.de.enige at gmail.com
Date: 2010-10-31 15:51:51 -0700 (Sun, 31 Oct 2010)
Log Message:
-----------
>From the TTY and Readline drivers, rewrite the last line if it was changed.
Modified Paths:
--------------
DietRB/trunk/lib/irb/driver/tty.rb
DietRB/trunk/spec/driver/tty_spec.rb
Modified: DietRB/trunk/lib/irb/driver/tty.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/tty.rb 2010-10-31 22:51:43 UTC (rev 4856)
+++ DietRB/trunk/lib/irb/driver/tty.rb 2010-10-31 22:51:51 UTC (rev 4857)
@@ -3,6 +3,11 @@
module IRB
module Driver
class TTY
+ move_one_line_up = "\e[1A"
+ move_to_begin_of_line = "\r"
+ clear_to_end_of_line = "\e[0K"
+ CLEAR_LAST_LINE = move_one_line_up + move_to_begin_of_line + clear_to_end_of_line
+
attr_reader :input, :output, :context_stack
def initialize(input = $stdin, output = $stdout)
@@ -28,17 +33,13 @@
""
end
- def last_line_decreased_indentation_level(reformatted_line)
- move_one_line_up = "\e[1A"
- move_to_begin_of_line = "\r"
- clear_to_end_of_line = "\e[0K"
- clear_last_line = move_one_line_up + move_to_begin_of_line + clear_to_end_of_line
- @output.print clear_last_line
- @output.puts(context.prompt + reformatted_line)
+ def update_last_line(reformatted_line)
+ @output.print CLEAR_LAST_LINE
+ @output.puts(context.prompt(true) + reformatted_line)
end
def process_input(line)
- context.process_line(line) { |new_line| last_line_decreased_indentation_level(new_line) }
+ context.process_line(line) { |reformatted_line| update_last_line(reformatted_line) }
end
# Feeds input into a given context.
Modified: DietRB/trunk/spec/driver/tty_spec.rb
===================================================================
--- DietRB/trunk/spec/driver/tty_spec.rb 2010-10-31 22:51:43 UTC (rev 4856)
+++ DietRB/trunk/spec/driver/tty_spec.rb 2010-10-31 22:51:51 UTC (rev 4857)
@@ -1,10 +1,12 @@
require File.expand_path('../../spec_helper', __FILE__)
require 'irb/driver/tty'
+main = self
+
describe "IRB::Driver::TTY" do
before do
@driver = IRB::Driver::TTY.new(InputStub.new, OutputStub.new)
- @context = IRB::Context.new(Object.new)
+ @context = IRB::Context.new(main)
@driver.context_stack << @context
end
@@ -38,6 +40,22 @@
@driver.consume.should == ""
@context.source.to_s.should == ""
end
+
+ it "feeds the input into the context" do
+ @driver.process_input("def foo")
+ @context.source.to_s.should == "def foo"
+ end
+
+ it "updates the previously printed line on the console, if a change to the input occurs (such as re-indenting)" do
+ @context.formatter.auto_indent = true
+ @driver.process_input("def foo")
+ @driver.process_input("p :ok")
+ @driver.process_input(" end")
+ @driver.output.printed.strip.should == [
+ IRB::Driver::TTY::CLEAR_LAST_LINE + "irb(main):002:1> p :ok",
+ IRB::Driver::TTY::CLEAR_LAST_LINE + "irb(main):003:1> end"
+ ].join("\n")
+ end
end
describe "IRB::Driver::TTY, when starting the runloop" do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101031/b393515f/attachment-0001.html>
More information about the macruby-changes
mailing list