mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Add newline_before_multiline_output
https://github.com/ruby/irb/commit/9eb1801a66
This commit is contained in:
parent
f451bb5406
commit
51a8055d7d
3 changed files with 58 additions and 1 deletions
|
@ -736,7 +736,13 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_value # :nodoc:
|
def output_value # :nodoc:
|
||||||
printf @context.return_format, @context.inspect_last_value
|
str = @context.inspect_last_value
|
||||||
|
multiline_p = str.each_line.take(2).length > 1
|
||||||
|
if multiline_p && @context.newline_before_multiline_output?
|
||||||
|
printf @context.return_format, "\n#{str}"
|
||||||
|
else
|
||||||
|
printf @context.return_format, str
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Outputs the local variables to this current session, including
|
# Outputs the local variables to this current session, including
|
||||||
|
|
|
@ -133,6 +133,11 @@ module IRB
|
||||||
if @echo_on_assignment.nil?
|
if @echo_on_assignment.nil?
|
||||||
@echo_on_assignment = false
|
@echo_on_assignment = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
|
||||||
|
if @newline_before_multiline_output.nil?
|
||||||
|
@newline_before_multiline_output = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The top-level workspace, see WorkSpace#main
|
# The top-level workspace, see WorkSpace#main
|
||||||
|
@ -253,6 +258,20 @@ module IRB
|
||||||
# a = "omg"
|
# a = "omg"
|
||||||
# #=> omg
|
# #=> omg
|
||||||
attr_accessor :echo_on_assignment
|
attr_accessor :echo_on_assignment
|
||||||
|
# Whether a newline is put before multiline output.
|
||||||
|
#
|
||||||
|
# Uses IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT] if available,
|
||||||
|
# or defaults to +true+.
|
||||||
|
#
|
||||||
|
# "abc\ndef"
|
||||||
|
# #=>
|
||||||
|
# abc
|
||||||
|
# def
|
||||||
|
# IRB.CurrentContext.newline_before_multiline_output = false
|
||||||
|
# "abc\ndef"
|
||||||
|
# #=> abc
|
||||||
|
# def
|
||||||
|
attr_accessor :newline_before_multiline_output
|
||||||
# Whether verbose messages are displayed or not.
|
# Whether verbose messages are displayed or not.
|
||||||
#
|
#
|
||||||
# A copy of the default <code>IRB.conf[:VERBOSE]</code>
|
# A copy of the default <code>IRB.conf[:VERBOSE]</code>
|
||||||
|
@ -287,6 +306,7 @@ module IRB
|
||||||
alias ignore_eof? ignore_eof
|
alias ignore_eof? ignore_eof
|
||||||
alias echo? echo
|
alias echo? echo
|
||||||
alias echo_on_assignment? echo_on_assignment
|
alias echo_on_assignment? echo_on_assignment
|
||||||
|
alias newline_before_multiline_output? newline_before_multiline_output
|
||||||
|
|
||||||
# Returns whether messages are displayed or not.
|
# Returns whether messages are displayed or not.
|
||||||
def verbose?
|
def verbose?
|
||||||
|
|
|
@ -216,5 +216,36 @@ module TestIRB
|
||||||
assert(irb.context.echo?, "echo? should be true by default")
|
assert(irb.context.echo?, "echo? should be true by default")
|
||||||
assert(irb.context.echo_on_assignment?, "echo_on_assignment? should be true when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to true")
|
assert(irb.context.echo_on_assignment?, "echo_on_assignment? should be true when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to true")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_multiline_output_on_default_inspector
|
||||||
|
main = Object.new
|
||||||
|
def main.inspect
|
||||||
|
"abc\ndef"
|
||||||
|
end
|
||||||
|
input = TestInputMethod.new([
|
||||||
|
"self"
|
||||||
|
])
|
||||||
|
irb = IRB::Irb.new(IRB::WorkSpace.new(main), input)
|
||||||
|
irb.context.return_format = "=> %s\n"
|
||||||
|
|
||||||
|
# The default
|
||||||
|
irb.context.newline_before_multiline_output = true
|
||||||
|
out, err = capture_io do
|
||||||
|
irb.eval_input
|
||||||
|
end
|
||||||
|
assert_empty err
|
||||||
|
assert_equal("=> \nabc\ndef\n",
|
||||||
|
out)
|
||||||
|
|
||||||
|
# No newline before multiline output
|
||||||
|
input.reset
|
||||||
|
irb.context.newline_before_multiline_output = false
|
||||||
|
out, err = capture_io do
|
||||||
|
irb.eval_input
|
||||||
|
end
|
||||||
|
assert_empty err
|
||||||
|
assert_equal("=> abc\ndef\n",
|
||||||
|
out)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue