-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document how to colorize
dry-cli
output
- Loading branch information
1 parent
4e70dd8
commit 1b8e035
Showing
2 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: Colorizing your output | ||
layout: gem-single | ||
name: dry-cli | ||
--- | ||
|
||
`dry-cli` comes with some functions to help you print colored text in the terminal. The program bellow demonstrate all available functions: | ||
|
||
```ruby | ||
#!/usr/bin/env ruby | ||
require "bundler/setup" | ||
require "dry/cli" | ||
|
||
module ColorsDemo | ||
extend Dry::CLI::Registry | ||
|
||
class Print < Dry::CLI::Command | ||
desc "Demonstrate all available colors" | ||
|
||
def call | ||
demo = <<~DEMO | ||
# Style ############################################################### | ||
Bold: #{bold("This is bold")} | ||
# Foreground ########################################################## | ||
Black: #{black("This is black")} | ||
Red: #{red("This is red")} | ||
Green: #{green("This is green")} | ||
Yellow: #{yellow("This is yellow")} | ||
Blue: #{blue("This is blue")} | ||
Magenta: #{magenta("This is magenta")} | ||
Cyan: #{cyan("This is cyan")} | ||
White: #{white("This is white")} | ||
# Background ########################################################## | ||
Black: #{on_black("This is black")} | ||
Red: #{on_red("This is red")} | ||
Green: #{on_green("This is green")} | ||
Yellow: #{on_yellow("This is yellow")} | ||
Blue: #{on_blue("This is blue")} | ||
Magenta: #{on_magenta("This is magenta")} | ||
Cyan: #{on_cyan("This is cyan")} | ||
White: #{on_white("This is white")} | ||
# Combinations ######################################################## | ||
Bold+Foreground: #{bold(red("This is bold red"))} | ||
Bold+Background: #{bold(on_green("This is bold on green"))} | ||
Bold+Foreground+Background: #{bold(red(on_green("This is bold red on green")))} | ||
DEMO | ||
puts demo | ||
end | ||
end | ||
|
||
register "print", Print | ||
end | ||
|
||
Dry.CLI(ColorsDemo).call | ||
``` |
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