summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-04-27 18:27:19 +0900
committeraycabta <aycabta@gmail.com>2020-04-29 19:13:14 +0900
commit98a346d065cc981d60ec0e45f7f15ba7328b6ad6 (patch)
treeb10b875abbee61fc6b31adad5445b769f56a3041 /lib
parent009092b04cf1fc36feb2e9257d131ec57242984f (diff)
[ruby/irb] Add irb_info command
https://github.com/ruby/irb/commit/a6fe58e916
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/cmd/info.rb25
-rw-r--r--lib/irb/extend-command.rb4
-rw-r--r--lib/irb/input-method.rb33
3 files changed, 62 insertions, 0 deletions
diff --git a/lib/irb/cmd/info.rb b/lib/irb/cmd/info.rb
new file mode 100644
index 0000000000..ddf57b00b4
--- /dev/null
+++ b/lib/irb/cmd/info.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: false
+
+require_relative "nop"
+
+# :stopdoc:
+module IRB
+ module ExtendCommand
+ class Info < Nop
+ def execute
+ Class.new {
+ def inspect
+ <<~EOM.chomp
+ Ruby version: #{RUBY_VERSION}
+ IRB version: #{IRB.version}
+ InputMethod: #{IRB.CurrentContext.io.inspect}
+ .irbrc path: #{IRB.rc_file}
+ EOM
+ end
+ alias_method :to_s, :inspect
+ }.new
+ end
+ end
+ end
+end
+# :startdoc:
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb
index de145e962d..828103ccc9 100644
--- a/lib/irb/extend-command.rb
+++ b/lib/irb/extend-command.rb
@@ -121,6 +121,10 @@ module IRB # :nodoc:
[:help, NO_OVERRIDE],
],
+ [
+ :irb_info, :Info, "irb/cmd/info"
+ ],
+
]
# Installs the default irb commands:
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index 9fbbaeb0f3..47fc5db84f 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -43,6 +43,11 @@ module IRB
def readable_after_eof?
false
end
+
+ # For debug message
+ def inspect
+ 'Abstract InputMethod'
+ end
end
class StdioInputMethod < InputMethod
@@ -93,6 +98,11 @@ module IRB
def encoding
@stdin.external_encoding
end
+
+ # For debug message
+ def inspect
+ 'StdioInputMethod'
+ end
end
# Use a File for IO with irb, see InputMethod
@@ -125,6 +135,11 @@ module IRB
def encoding
@io.external_encoding
end
+
+ # For debug message
+ def inspect
+ 'FileInputMethod'
+ end
end
begin
@@ -202,6 +217,13 @@ module IRB
end
Readline.completion_append_character = nil
Readline.completion_proc = IRB::InputCompletor::CompletionProc
+
+ # For debug message
+ def inspect
+ inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
+ readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
+ "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION} and #{inputrc_path}"
+ end
end
rescue LoadError
end
@@ -297,5 +319,16 @@ module IRB
def encoding
@stdin.external_encoding
end
+
+ # For debug message
+ def inspect
+ config = Reline::Config.new
+ if config.respond_to?(:inputrc_path)
+ inputrc_path = config.inputrc_path
+ else
+ inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
+ end
+ "ReidlineInputMethod with Reline #{Reline::VERSION} and #{inputrc_path}"
+ end
end
end