[macruby-changes] [4848] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Oct 31 15:50:44 PDT 2010


Revision: 4848
          http://trac.macosforge.org/projects/ruby/changeset/4848
Author:   eloy.de.enige at gmail.com
Date:     2010-10-31 15:50:41 -0700 (Sun, 31 Oct 2010)
Log Message:
-----------
IRB::Formatter#prompt can optionally pad the prompt with indentation whitespace.

Modified Paths:
--------------
    DietRB/trunk/lib/irb/context.rb
    DietRB/trunk/lib/irb/formatter.rb
    DietRB/trunk/spec/formatter_spec.rb

Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb	2010-10-29 16:47:33 UTC (rev 4847)
+++ DietRB/trunk/lib/irb/context.rb	2010-10-31 22:50:41 UTC (rev 4848)
@@ -61,9 +61,9 @@
     #   process_line("quit") # => false
     def process_line(line)
       reindented = formatter.add_input_to_context(self, line)
-      if reindented
-        driver.last_line_decreased_indentation_level(line)
-      end
+      #if reindented
+        #driver.last_line_decreased_indentation_level(line)
+      #end
 
       return false if @source.terminate?
 

Modified: DietRB/trunk/lib/irb/formatter.rb
===================================================================
--- DietRB/trunk/lib/irb/formatter.rb	2010-10-29 16:47:33 UTC (rev 4847)
+++ DietRB/trunk/lib/irb/formatter.rb	2010-10-31 22:50:41 UTC (rev 4848)
@@ -31,14 +31,14 @@
       '  ' * context.source.level
     end
     
-    def prompt(context)
+    def prompt(context, indent = false)
       prompt = case @prompt
       when :default then DEFAULT_PROMPT % [context.object.inspect, context.line, context.source.level]
       when :simple  then SIMPLE_PROMPT
       else
         NO_PROMPT
       end
-      prompt + indentation(context)
+      indent ? (prompt + indentation(context)) : prompt
     end
     
     def inspect_object(object)
@@ -47,12 +47,16 @@
         result.strip!
         result
       else
-        address = object.__id__ * 2
-        address += 0x100000000 if address < 0
-        "#<#{object.class}:0x%x>" % address
+        minimal_inspect_object(object)
       end
     end
 
+    def minimal_inspect_object(object)
+      address = object.__id__ * 2
+      address += 0x100000000 if address < 0
+      "#<#{object.class}:0x%x>" % address
+    end
+
     # Returns +true+ if adding the +line+ to the context’s source decreases the indentation level.
     def add_input_to_context(context, line)
       source = context.source

Modified: DietRB/trunk/spec/formatter_spec.rb
===================================================================
--- DietRB/trunk/spec/formatter_spec.rb	2010-10-29 16:47:33 UTC (rev 4847)
+++ DietRB/trunk/spec/formatter_spec.rb	2010-10-31 22:50:41 UTC (rev 4848)
@@ -15,6 +15,18 @@
     @context.source << "def foo"
     @formatter.prompt(@context).should == "irb(main):023:1> "
   end
+
+  it "also auto-indents the prompt, based on the source level, if requested" do
+    @formatter.prompt(@context, true).should == "irb(main):001:0> "
+
+    @context.process_line("class A")
+    @formatter.prompt(@context, true).should == "irb(main):002:1>   "
+    @formatter.prompt(@context).should       == "irb(main):002:1> "
+
+    @context.process_line("def foo")
+    @formatter.prompt(@context, true).should == "irb(main):003:2>     "
+    @formatter.prompt(@context).should       == "irb(main):003:2> "
+  end
   
   it "describes the context's object in the prompt" do
     o = Object.new
@@ -77,4 +89,4 @@
     @formatter.syntax_error(2, "syntax error, unexpected '}'").should ==
       "SyntaxError: compile error\n(irb):2: syntax error, unexpected '}'"
   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/ee1af11c/attachment.html>


More information about the macruby-changes mailing list