diff options
author | murphy <murphy@rubychan.de> | 2010-03-26 04:54:19 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2010-03-26 04:54:19 +0000 |
commit | eb532d6ebd432590f40defbc1ed624d65c4a850a (patch) | |
tree | 0d56c034d7010a9dec219eb7098ff338b4ee6466 /bin/coderay | |
parent | ceb50717fbda4a0a7e1e7cda774da8dc692d49ef (diff) | |
download | coderay-eb532d6ebd432590f40defbc1ed624d65c4a850a.tar.gz |
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).
Diffstat (limited to 'bin/coderay')
-rw-r--r-- | bin/coderay | 25 |
1 files changed, 19 insertions, 6 deletions
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"
|