Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colorize command #1

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
```

Expand Down
24 changes: 24 additions & 0 deletions lib/un.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -354,6 +355,29 @@ 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, |
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
end
end

##
# Display help message.
#
Expand Down