Skip to content

Commit

Permalink
Document how to colorize dry-cli output
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavothecoder committed Dec 2, 2024
1 parent 4e70dd8 commit 1b8e035
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions docsite/source/colorizing-your-output.html.md
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
```
1 change: 1 addition & 0 deletions docsite/source/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sections:
- variadic-arguments
- commands-with-subcommands-and-params
- callbacks
- colorizing-your-output
---

`dry-cli` is a general-purpose framework for developing Command Line Interface (CLI) applications. It represents commands as objects that can be registered and offers support for arguments, options and forwarding variadic arguments to a sub-command.
Expand Down

0 comments on commit 1b8e035

Please sign in to comment.