From 4d080eeec0f368bc78c8a92b5ca66278c4408ed6 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Tue, 6 Apr 2021 18:37:09 +0900 Subject: [PATCH 1/2] Add colorize command --- README.md | 1 + lib/un.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index adaf066..a43ac8e 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ ruby -run -e touch -- [OPTION] FILE ruby -run -e wait_writable -- [OPTION] FILE ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION] ruby -run -e httpd -- [OPTION] [DocumentRoot] +ruby -run -e colorize -- FILE ruby -run -e help [COMMAND] ``` diff --git a/lib/un.rb b/lib/un.rb index a759328..4b51f76 100644 --- a/lib/un.rb +++ b/lib/un.rb @@ -23,6 +23,7 @@ # ruby -run -e wait_writable -- [OPTION] FILE # ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION] # ruby -run -e httpd -- [OPTION] [DocumentRoot] +# ruby -run -e colorize -- FILE # ruby -run -e help [COMMAND] require "fileutils" @@ -354,6 +355,25 @@ def httpd end end +## +# Colorize ruby code. +# +# ruby -run -e colorize -- FILE +# + +def colorize + begin + require "irb/color" + rescue LoadError + raise "colorize requires irb 1.1.0 or later" + end + setup do |argv, | + argv.each do |file| + puts IRB::Color.colorize_code File.read(file) + end + end +end + ## # Display help message. # From 8e0d6f62cbd9d45edb728cbc8507897a35e1ee20 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Wed, 7 Apr 2021 10:35:37 +0900 Subject: [PATCH 2/2] Use STDIN if no arguments --- README.md | 2 +- lib/un.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a43ac8e..359365e 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ ruby -run -e touch -- [OPTION] FILE ruby -run -e wait_writable -- [OPTION] FILE ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION] ruby -run -e httpd -- [OPTION] [DocumentRoot] -ruby -run -e colorize -- FILE +ruby -run -e colorize -- [FILE] ruby -run -e help [COMMAND] ``` diff --git a/lib/un.rb b/lib/un.rb index 4b51f76..7f58300 100644 --- a/lib/un.rb +++ b/lib/un.rb @@ -23,7 +23,7 @@ # ruby -run -e wait_writable -- [OPTION] FILE # ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION] # ruby -run -e httpd -- [OPTION] [DocumentRoot] -# ruby -run -e colorize -- FILE +# ruby -run -e colorize -- [FILE] # ruby -run -e help [COMMAND] require "fileutils" @@ -358,7 +358,7 @@ def httpd ## # Colorize ruby code. # -# ruby -run -e colorize -- FILE +# ruby -run -e colorize -- [FILE] # def colorize @@ -368,6 +368,10 @@ def colorize raise "colorize requires irb 1.1.0 or later" end setup do |argv, | + if argv.empty? + puts IRB::Color.colorize_code STDIN.read + return + end argv.each do |file| puts IRB::Color.colorize_code File.read(file) end