-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfdabda
commit c973837
Showing
4 changed files
with
346 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Hanami | ||
module Utils | ||
# Shellcode helper for colorizing STDOUT | ||
# | ||
# It doesn't check if you're writing to a file or anything, so you have to | ||
# check that yourself before using this module. | ||
module ShellColor | ||
# Escape codes for terminals to output strings in colors | ||
# | ||
# @since x.x.x | ||
# @api private | ||
COLORS = ::Hash[ | ||
black: 30, | ||
red: 31, | ||
green: 32, | ||
yellow: 33, | ||
blue: 34, | ||
magenta: 35, | ||
cyan: 36, | ||
gray: 37, | ||
].freeze | ||
|
||
# Colorize output | ||
# 8 colors available: black, red, green, yellow, blue, magenta, cyan, and gray | ||
# | ||
# @api public | ||
# @since x.x.x | ||
def self.colorize(input, color:) | ||
"\e[#{color_code(color)}m#{input}\e[0m" | ||
end | ||
|
||
# Helper method to translate between color names and terminal escape codes | ||
# | ||
# @api private | ||
# @since x.x.x | ||
def self.color_code(name) | ||
COLORS.fetch(name) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.