mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Drop OMIT_ON_ASSIGNMENT and add :truncate option for ECHO_ON_ASSIGNMENT
https://github.com/ruby/irb/commit/4c89b0775b
This commit is contained in:
parent
7d9b4d3c61
commit
555ea83344
4 changed files with 39 additions and 67 deletions
|
@ -542,7 +542,7 @@ module IRB
|
||||||
if @context.echo?
|
if @context.echo?
|
||||||
if assignment_expression?(line)
|
if assignment_expression?(line)
|
||||||
if @context.echo_on_assignment?
|
if @context.echo_on_assignment?
|
||||||
output_value(@context.omit_on_assignment?)
|
output_value(@context.echo_on_assignment? == :truncate)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
output_value
|
output_value
|
||||||
|
|
|
@ -131,12 +131,7 @@ module IRB
|
||||||
|
|
||||||
@echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
|
@echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
|
||||||
if @echo_on_assignment.nil?
|
if @echo_on_assignment.nil?
|
||||||
@echo_on_assignment = true
|
@echo_on_assignment = :truncate
|
||||||
end
|
|
||||||
|
|
||||||
@omit_on_assignment = IRB.conf[:OMIT_ON_ASSIGNMENT]
|
|
||||||
if @omit_on_assignment.nil?
|
|
||||||
@omit_on_assignment = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
|
@newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
|
||||||
|
@ -256,27 +251,24 @@ module IRB
|
||||||
attr_accessor :echo
|
attr_accessor :echo
|
||||||
# Whether to echo for assignment expressions
|
# Whether to echo for assignment expressions
|
||||||
#
|
#
|
||||||
# Uses <code>IRB.conf[:ECHO_ON_ASSIGNMENT]</code> if available, or defaults to +true+.
|
# If set to +false+, the value of assignment will not be shown.
|
||||||
|
#
|
||||||
|
# If set to +true+, the value of assignment will be shown.
|
||||||
|
#
|
||||||
|
# If set to +:truncate+, the value of assignment will be shown and truncated.
|
||||||
|
#
|
||||||
|
# It defaults to +:truncate+.
|
||||||
#
|
#
|
||||||
# a = "omg"
|
# a = "omg"
|
||||||
# #=> omg
|
# #=> omg
|
||||||
|
# a = "omg" * 10
|
||||||
|
# #=> omgomgomgomgomgomgomg...
|
||||||
# IRB.CurrentContext.echo_on_assignment = false
|
# IRB.CurrentContext.echo_on_assignment = false
|
||||||
# a = "omg"
|
# a = "omg"
|
||||||
|
# IRB.CurrentContext.echo_on_assignment = true
|
||||||
|
# a = "omg"
|
||||||
|
# #=> omgomgomgomgomgomgomgomgomgomg
|
||||||
attr_accessor :echo_on_assignment
|
attr_accessor :echo_on_assignment
|
||||||
# Whether to omit echo for assignment expressions
|
|
||||||
#
|
|
||||||
# Uses <code>IRB.conf[:OMIT_ON_ASSIGNMENT]</code> if available, or defaults to +true+.
|
|
||||||
#
|
|
||||||
# a = [1] * 10
|
|
||||||
# #=> [1, 1, 1, 1, 1, 1, 1, 1, ...
|
|
||||||
# [1] * 10
|
|
||||||
# #=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
|
||||||
# IRB.CurrentContext.omit_on_assignment = false
|
|
||||||
# a = [1] * 10
|
|
||||||
# #=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
|
||||||
# [1] * 10
|
|
||||||
# #=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
|
||||||
attr_accessor :omit_on_assignment
|
|
||||||
# Whether a newline is put before multiline output.
|
# Whether a newline is put before multiline output.
|
||||||
#
|
#
|
||||||
# Uses <code>IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]</code> if available,
|
# Uses <code>IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]</code> if available,
|
||||||
|
@ -325,7 +317,6 @@ 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 omit_on_assignment? omit_on_assignment
|
|
||||||
alias newline_before_multiline_output? newline_before_multiline_output
|
alias newline_before_multiline_output? newline_before_multiline_output
|
||||||
|
|
||||||
# Returns whether messages are displayed or not.
|
# Returns whether messages are displayed or not.
|
||||||
|
|
|
@ -52,7 +52,6 @@ module IRB # :nodoc:
|
||||||
@CONF[:IGNORE_EOF] = false
|
@CONF[:IGNORE_EOF] = false
|
||||||
@CONF[:ECHO] = nil
|
@CONF[:ECHO] = nil
|
||||||
@CONF[:ECHO_ON_ASSIGNMENT] = nil
|
@CONF[:ECHO_ON_ASSIGNMENT] = nil
|
||||||
@CONF[:OMIT_ON_ASSIGNMENT] = nil
|
|
||||||
@CONF[:VERBOSE] = nil
|
@CONF[:VERBOSE] = nil
|
||||||
|
|
||||||
@CONF[:EVAL_HISTORY] = nil
|
@CONF[:EVAL_HISTORY] = nil
|
||||||
|
@ -178,10 +177,8 @@ module IRB # :nodoc:
|
||||||
@CONF[:ECHO_ON_ASSIGNMENT] = true
|
@CONF[:ECHO_ON_ASSIGNMENT] = true
|
||||||
when "--noecho-on-assignment"
|
when "--noecho-on-assignment"
|
||||||
@CONF[:ECHO_ON_ASSIGNMENT] = false
|
@CONF[:ECHO_ON_ASSIGNMENT] = false
|
||||||
when "--omit-on-assignment"
|
when "--truncate-echo-on-assignment"
|
||||||
@CONF[:OMIT_ON_ASSIGNMENT] = true
|
@CONF[:ECHO_ON_ASSIGNMENT] = :truncate
|
||||||
when "--noomit-on-assignment"
|
|
||||||
@CONF[:OMIT_ON_ASSIGNMENT] = false
|
|
||||||
when "--verbose"
|
when "--verbose"
|
||||||
@CONF[:VERBOSE] = true
|
@CONF[:VERBOSE] = true
|
||||||
when "--noverbose"
|
when "--noverbose"
|
||||||
|
|
|
@ -228,7 +228,6 @@ module TestIRB
|
||||||
|
|
||||||
irb.context.echo = true
|
irb.context.echo = true
|
||||||
irb.context.echo_on_assignment = false
|
irb.context.echo_on_assignment = false
|
||||||
irb.context.omit_on_assignment = true
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -237,8 +236,7 @@ module TestIRB
|
||||||
|
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = true
|
irb.context.echo = true
|
||||||
irb.context.echo_on_assignment = true
|
irb.context.echo_on_assignment = :truncate
|
||||||
irb.context.omit_on_assignment = true
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -248,7 +246,6 @@ module TestIRB
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = true
|
irb.context.echo = true
|
||||||
irb.context.echo_on_assignment = true
|
irb.context.echo_on_assignment = true
|
||||||
irb.context.omit_on_assignment = false
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -258,7 +255,15 @@ module TestIRB
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = false
|
irb.context.echo = false
|
||||||
irb.context.echo_on_assignment = false
|
irb.context.echo_on_assignment = false
|
||||||
irb.context.omit_on_assignment = true
|
out, err = capture_io do
|
||||||
|
irb.eval_input
|
||||||
|
end
|
||||||
|
assert_empty err
|
||||||
|
assert_equal("", out)
|
||||||
|
|
||||||
|
input.reset
|
||||||
|
irb.context.echo = false
|
||||||
|
irb.context.echo_on_assignment = :truncate
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -268,17 +273,6 @@ module TestIRB
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = false
|
irb.context.echo = false
|
||||||
irb.context.echo_on_assignment = true
|
irb.context.echo_on_assignment = true
|
||||||
irb.context.omit_on_assignment = true
|
|
||||||
out, err = capture_io do
|
|
||||||
irb.eval_input
|
|
||||||
end
|
|
||||||
assert_empty err
|
|
||||||
assert_equal("", out)
|
|
||||||
|
|
||||||
input.reset
|
|
||||||
irb.context.echo = false
|
|
||||||
irb.context.echo_on_assignment = true
|
|
||||||
irb.context.omit_on_assignment = false
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -298,7 +292,6 @@ module TestIRB
|
||||||
|
|
||||||
irb.context.echo = true
|
irb.context.echo = true
|
||||||
irb.context.echo_on_assignment = false
|
irb.context.echo_on_assignment = false
|
||||||
irb.context.omit_on_assignment = true
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -308,8 +301,7 @@ module TestIRB
|
||||||
|
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = true
|
irb.context.echo = true
|
||||||
irb.context.echo_on_assignment = true
|
irb.context.echo_on_assignment = :truncate
|
||||||
irb.context.omit_on_assignment = true
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -320,7 +312,6 @@ module TestIRB
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = true
|
irb.context.echo = true
|
||||||
irb.context.echo_on_assignment = true
|
irb.context.echo_on_assignment = true
|
||||||
irb.context.omit_on_assignment = false
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -331,7 +322,16 @@ module TestIRB
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = false
|
irb.context.echo = false
|
||||||
irb.context.echo_on_assignment = false
|
irb.context.echo_on_assignment = false
|
||||||
irb.context.omit_on_assignment = true
|
out, err = capture_io do
|
||||||
|
irb.eval_input
|
||||||
|
end
|
||||||
|
assert_empty err
|
||||||
|
assert_equal("", out)
|
||||||
|
irb.context.evaluate('A.remove_method(:inspect)', 0)
|
||||||
|
|
||||||
|
input.reset
|
||||||
|
irb.context.echo = false
|
||||||
|
irb.context.echo_on_assignment = :truncate
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -342,18 +342,6 @@ module TestIRB
|
||||||
input.reset
|
input.reset
|
||||||
irb.context.echo = false
|
irb.context.echo = false
|
||||||
irb.context.echo_on_assignment = true
|
irb.context.echo_on_assignment = true
|
||||||
irb.context.omit_on_assignment = true
|
|
||||||
out, err = capture_io do
|
|
||||||
irb.eval_input
|
|
||||||
end
|
|
||||||
assert_empty err
|
|
||||||
assert_equal("", out)
|
|
||||||
irb.context.evaluate('A.remove_method(:inspect)', 0)
|
|
||||||
|
|
||||||
input.reset
|
|
||||||
irb.context.echo = false
|
|
||||||
irb.context.echo_on_assignment = true
|
|
||||||
irb.context.omit_on_assignment = false
|
|
||||||
out, err = capture_io do
|
out, err = capture_io do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
|
@ -370,26 +358,22 @@ module TestIRB
|
||||||
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
||||||
|
|
||||||
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 by default")
|
assert_equal(:truncate, irb.context.echo_on_assignment?, "echo_on_assignment? should be :truncate by default")
|
||||||
assert(irb.context.omit_on_assignment?, "omit_on_assignment? should be true by default")
|
|
||||||
|
|
||||||
# Explicitly set :ECHO to false
|
# Explicitly set :ECHO to false
|
||||||
IRB.conf[:ECHO] = false
|
IRB.conf[:ECHO] = false
|
||||||
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
||||||
|
|
||||||
refute(irb.context.echo?, "echo? should be false when IRB.conf[:ECHO] is set to false")
|
refute(irb.context.echo?, "echo? should be false when IRB.conf[:ECHO] is set to false")
|
||||||
assert(irb.context.echo_on_assignment?, "echo_on_assignment? should be true by default")
|
assert_equal(:truncate, irb.context.echo_on_assignment?, "echo_on_assignment? should be :truncate by default")
|
||||||
assert(irb.context.omit_on_assignment?, "omit_on_assignment? should be true by default")
|
|
||||||
|
|
||||||
# Explicitly set :ECHO_ON_ASSIGNMENT to true
|
# Explicitly set :ECHO_ON_ASSIGNMENT to true
|
||||||
IRB.conf[:ECHO] = nil
|
IRB.conf[:ECHO] = nil
|
||||||
IRB.conf[:ECHO_ON_ASSIGNMENT] = false
|
IRB.conf[:ECHO_ON_ASSIGNMENT] = false
|
||||||
IRB.conf[:OMIT_ON_ASSIGNMENT] = false
|
|
||||||
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
|
||||||
|
|
||||||
assert(irb.context.echo?, "echo? should be true by default")
|
assert(irb.context.echo?, "echo? should be true by default")
|
||||||
refute(irb.context.echo_on_assignment?, "echo_on_assignment? should be false when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to false")
|
refute(irb.context.echo_on_assignment?, "echo_on_assignment? should be false when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to false")
|
||||||
refute(irb.context.omit_on_assignment?, "omit_on_assignment? should be false when IRB.conf[:OMIT_ON_ASSIGNMENT] is set to false")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multiline_output_on_default_inspector
|
def test_multiline_output_on_default_inspector
|
||||||
|
|
Loading…
Reference in a new issue