summaryrefslogtreecommitdiff
path: root/lib/irb/context.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r--lib/irb/context.rb29
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index 836b8d2625..aafce7aade 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -73,11 +73,12 @@ module IRB
self.prompt_mode = IRB.conf[:PROMPT_MODE]
- if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
- @irb_name = IRB.conf[:IRB_NAME]
- else
- @irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
+ @irb_name = IRB.conf[:IRB_NAME]
+
+ unless IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
+ @irb_name = @irb_name + "#" + IRB.JobManager.n_jobs.to_s
end
+
self.irb_path = "(" + @irb_name + ")"
case input_method
@@ -85,7 +86,7 @@ module IRB
@io = nil
case use_multiline?
when nil
- if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
+ if term_interactive? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
# Both of multiline mode and singleline mode aren't specified.
@io = RelineInputMethod.new(build_completor)
else
@@ -99,7 +100,7 @@ module IRB
unless @io
case use_singleline?
when nil
- if (defined?(ReadlineInputMethod) && STDIN.tty? &&
+ if (defined?(ReadlineInputMethod) && term_interactive? &&
IRB.conf[:PROMPT_MODE] != :INF_RUBY)
@io = ReadlineInputMethod.new
else
@@ -151,6 +152,11 @@ module IRB
@command_aliases = @user_aliases.merge(KEYWORD_ALIASES)
end
+ private def term_interactive?
+ return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
+ STDIN.tty? && ENV['TERM'] != 'dumb'
+ end
+
# because all input will eventually be evaluated as Ruby code,
# command names that conflict with Ruby keywords need special workaround
# we can remove them once we implemented a better command system for IRB
@@ -587,18 +593,23 @@ module IRB
def evaluate(statement, line_no) # :nodoc:
@line_no = line_no
- result = nil
case statement
when Statement::EmptyInput
return
when Statement::Expression
result = evaluate_expression(statement.code, line_no)
+ set_last_value(result)
when Statement::Command
- result = statement.command_class.execute(self, statement.arg)
+ statement.command_class.execute(self, statement.arg)
+ set_last_value(nil)
end
- set_last_value(result)
+ nil
+ end
+
+ def from_binding?
+ @irb.from_binding
end
def evaluate_expression(code, line_no) # :nodoc: