Skip to content

Commit

Permalink
Add the --simple-prompt option.
Browse files Browse the repository at this point in the history
From: Eloy Duran <eloy.de.enige@gmail.com>

git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@4646 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
alloy committed Oct 8, 2010
1 parent 68ddb7c commit 17ba18d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/dietrb
@@ -1,5 +1,7 @@
#!/usr/bin/env ruby

require 'irb'

unless ARGV.empty?
require 'optparse'

Expand All @@ -9,12 +11,12 @@ unless ARGV.empty?
opt.on("-r load-lib", "Loads the given library (same as `ruby -r')") { |lib| require lib }
opt.on("-d", "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
opt.on("-I path", "Add path to $LOAD_PATH") { |path| $LOAD_PATH.unshift(path) }
opt.on("--simple-prompt", "Simple prompt mode") { IRB.formatter = IRB::Formatter::SimplePrompt.new }
opt.on("-v", "--version", "Print the version of #{bin}") do
puts File.read(File.expand_path('../../VERSION', __FILE__))
exit
end
end.parse!(ARGV)
end

require 'irb'
irb(self, TOPLEVEL_BINDING)
10 changes: 10 additions & 0 deletions lib/irb/formatter.rb
@@ -1,5 +1,7 @@
module IRB
class << self
attr_writer :formatter

def formatter
@formatter ||= Formatter::Default.new
end
Expand Down Expand Up @@ -27,5 +29,13 @@ def syntax_error(line, message)
SYNTAX_ERROR % [line, message]
end
end

class SimplePrompt < Default
PROMPT = ">> "

def prompt(_)
PROMPT
end
end
end
end
10 changes: 10 additions & 0 deletions spec/formatter_spec.rb
Expand Up @@ -35,4 +35,14 @@
@formatter.syntax_error(2, "syntax error, unexpected '}'").should ==
"SyntaxError: compile error\n(irb):2: syntax error, unexpected '}'"
end
end

describe "IRB::Formatter::SimplePrompt" do
before do
@formatter = IRB::Formatter::SimplePrompt.new
end

it "returns a very simple prompt" do
@formatter.prompt(nil).should == ">> "
end
end

0 comments on commit 17ba18d

Please sign in to comment.