aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-08-29 20:48:25 +0900
committeraycabta <aycabta@gmail.com>2020-09-14 02:13:11 +0900
commite468d9f49ca34f713c030c623f655a40370e186d (patch)
treed478651b666f38a917863d6bf78c911e7e5f2eeb /lib/irb
parent5d841f563144a4864f0f60af2935e3eb82ee110a (diff)
downloadruby-e468d9f49ca34f713c030c623f655a40370e186d.tar.gz
[ruby/irb] Add OMIT_ON_ASSIGNMENT
Omit the results evaluated at assignment if they are too long. The behavior of ECHO_ON_ASSIGNMENT being on by default is hard to understand, so I change it to off by default. Instead, we turn OMIT_ON_ASSIGNMENT on by default. The result is displayed on assignment, but it will always be short and within one line of the screen. https://github.com/ruby/irb/commit/c5ea79d5ce
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/context.rb28
-rw-r--r--lib/irb/init.rb5
-rw-r--r--lib/irb/input-method.rb9
3 files changed, 38 insertions, 4 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index 4f5460a84c..4f001729e1 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -131,7 +131,12 @@ module IRB
@echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
if @echo_on_assignment.nil?
- @echo_on_assignment = false
+ @echo_on_assignment = true
+ end
+
+ @omit_on_assignment = IRB.conf[:OMIT_ON_ASSIGNMENT]
+ if @omit_on_assignment.nil?
+ @omit_on_assignment = true
end
@newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
@@ -251,13 +256,27 @@ module IRB
attr_accessor :echo
# Whether to echo for assignment expressions
#
- # Uses <code>IRB.conf[:ECHO_ON_ASSIGNMENT]</code> if available, or defaults to +false+.
+ # Uses <code>IRB.conf[:ECHO_ON_ASSIGNMENT]</code> if available, or defaults to +true+.
#
# a = "omg"
- # IRB.CurrentContext.echo_on_assignment = true
- # a = "omg"
# #=> omg
+ # IRB.CurrentContext.echo_on_assignment = false
+ # a = "omg"
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.
#
# Uses <code>IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]</code> if available,
@@ -306,6 +325,7 @@ module IRB
alias ignore_eof? ignore_eof
alias echo? echo
alias echo_on_assignment? echo_on_assignment
+ alias omit_on_assignment? omit_on_assignment
alias newline_before_multiline_output? newline_before_multiline_output
# Returns whether messages are displayed or not.
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index da40bee5e1..44383609bd 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -52,6 +52,7 @@ module IRB # :nodoc:
@CONF[:IGNORE_EOF] = false
@CONF[:ECHO] = nil
@CONF[:ECHO_ON_ASSIGNMENT] = nil
+ @CONF[:OMIT_ON_ASSIGNMENT] = nil
@CONF[:VERBOSE] = nil
@CONF[:EVAL_HISTORY] = nil
@@ -177,6 +178,10 @@ module IRB # :nodoc:
@CONF[:ECHO_ON_ASSIGNMENT] = true
when "--noecho-on-assignment"
@CONF[:ECHO_ON_ASSIGNMENT] = false
+ when "--omit-on-assignment"
+ @CONF[:OMIT_ON_ASSIGNMENT] = true
+ when "--noomit-on-assignment"
+ @CONF[:OMIT_ON_ASSIGNMENT] = false
when "--verbose"
@CONF[:VERBOSE] = true
when "--noverbose"
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index 7cb211354b..6e87488753 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -12,6 +12,7 @@
require_relative 'src_encoding'
require_relative 'magic-file'
require_relative 'completion'
+require 'io/console'
require 'reline'
module IRB
@@ -36,6 +37,14 @@ module IRB
end
public :gets
+ def winsize
+ if instance_variable_defined?(:@stdout)
+ @stdout.winsize
+ else
+ [24, 80]
+ end
+ end
+
# Whether this input method is still readable when there is no more data to
# read.
#