summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2011-08-19 03:09:35 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2011-08-19 03:09:35 +0200
commit75bc5455af8c3c3381066aac3d5fff42264cac6f (patch)
tree589d2c912ddd94c517eb794bcdf3257f8348f3c0 /bin
parentfdd17b6a09efb275238a3baef275465d31452f2a (diff)
downloadcoderay-75bc5455af8c3c3381066aac3d5fff42264cac6f.tar.gz
Major rewrite of encoders to support IO output; fixed some minor scanner bugs; cleanups; dropped NitroXHTML scanner; improved tests
Diffstat (limited to 'bin')
-rwxr-xr-xbin/coderay40
1 files changed, 31 insertions, 9 deletions
diff --git a/bin/coderay b/bin/coderay
index fa87fa9..acb05ed 100755
--- a/bin/coderay
+++ b/bin/coderay
@@ -105,23 +105,38 @@ when 'highlight', nil
if output_file
output_filetype ||= CodeRay::FileType[output_file]
else
- output_filetype ||= tty? ? :term : :page
+ output_filetype ||= :term
end
+ output_filetype = :page if output_filetype.to_s == 'html'
+
if input_file
input = File.read input_file
else
input = $stdin.read
end
- output = CodeRay.scan(input, input_filetype).encode(output_filetype)
-
- if output_file
- File.open output_file, 'w' do |file|
- file.puts output
+ begin
+ file =
+ if output_file
+ File.open output_file, 'w'
+ else
+ $stdout.sync = true
+ $stdout
+ end
+ CodeRay.encode(input, input_filetype, output_filetype, :out => file)
+ file.puts
+ rescue CodeRay::PluginHost::PluginNotFound => boom
+ if boom.message[/CodeRay::(\w+)s could not load plugin :?(.*?): /]
+ puts "I don't know the #$1 \"#$2\"."
+ else
+ puts boom.message
end
- else
- puts output
+ # puts "I don't know this plugin: #{boom.message[/Could not load plugin (.*?): /, 1]}."
+ rescue CodeRay::Scanners::Scanner::ScanError # FIXME: rescue Errno::EPIPE
+ # ignore
+ ensure
+ file.close
end
end
when 'list'
@@ -151,6 +166,13 @@ when 'commands'
when 'help'
help
else
- puts "Unknown command: #{subcommand}"
+ $stdout = $stderr
help
+ puts
+ if subcommand[/\A\w+\z/]
+ puts "Unknown command: #{subcommand}"
+ else
+ puts "File not found: #{subcommand}"
+ end
+ exit 1
end