Skip to content
Browse files

IRB::Formatter#prompt can optionally pad the prompt with indentation …

…whitespace.

git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@4848 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent c02693d commit 4470106550014fae1a394db17ace2bf76b0f5dc8 @alloy alloy committed Oct 31, 2010
Showing with 25 additions and 9 deletions.
  1. +3 −3 lib/irb/context.rb
  2. +9 −5 lib/irb/formatter.rb
  3. +13 −1 spec/formatter_spec.rb
View
6 lib/irb/context.rb
@@ -61,9 +61,9 @@ def evaluate(source)
# 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?
View
14 lib/irb/formatter.rb
@@ -31,14 +31,14 @@ def indentation(context)
' ' * 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 @@ def inspect_object(object)
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
View
14 spec/formatter_spec.rb
@@ -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 @@ def object.__id__; 2158110700; end
@formatter.syntax_error(2, "syntax error, unexpected '}'").should ==
"SyntaxError: compile error\n(irb):2: syntax error, unexpected '}'"
end
-end
+end

0 comments on commit 4470106

Please sign in to comment.
Something went wrong with that request. Please try again.