From eb532d6ebd432590f40defbc1ed624d65c4a850a Mon Sep 17 00:00:00 2001 From: murphy Date: Fri, 26 Mar 2010 04:54:19 +0000 Subject: Long overdue updates for the coderay executable - yay! * *NEW* automatic TTY detection, uses @Terminal@ encoder. * *NEW* optional 3rd parameter for the filename. * *FIXED*: Warn about generated files. * *FIXED*: Ensure linebreak after the output (was problematic for LoC counter). --- bin/coderay | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'bin/coderay') diff --git a/bin/coderay b/bin/coderay index 82d4eca..c938ecf 100644 --- a/bin/coderay +++ b/bin/coderay @@ -8,6 +8,14 @@ def err msg $stderr.puts msg end +def read + if file = ARGV[2] + File.read file + else + $stdin.read + end +end + begin require 'coderay' @@ -28,11 +36,11 @@ Example: if first if first[/-(\w+)/] == first lang = $1 - input = $stdin.read + input = read tokens = :scan elsif first == '-' lang = $1 - input = $stdin.read + input = read tokens = :scan else file = first @@ -48,11 +56,15 @@ Example: if second[/-(\w+)/] == second format = $1 else - raise 'Invalid format (must be -xxx).' + raise 'invalid format (must be -xxx)' end else - $stderr.puts 'No format given; setting to default (HTML Page)' - format = :page + if $stdout.tty? + format = :term + else + $stderr.puts 'No format given; setting to default (HTML Page).' + format = :page + end end # TODO: allow streaming @@ -69,9 +81,10 @@ Example: exit else out = File.open output_filename, 'w' + puts "Writing to #{output_filename}..." end end - out.print output + out.puts output rescue => boom err "Error: #{boom.message}\n" -- cgit v1.2.1