Class: Unmagic::Color::Console::Help

Inherits:
Object
  • Object
show all
Defined in:
lib/unmagic/color/console/help.rb

Overview

Renders the help text for the console.

Examples:

puts Unmagic::Color::Console::Help.new.render

Instance Method Summary collapse

Instance Method Details

#renderString

Render the help text with syntax highlighting.

Returns:

  • (String)

    The formatted help text



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/unmagic/color/console/help.rb', line 16

def render
  link = highlighter.link("https://github.com/unreasonable-magic/unmagic-color")

  code = highlighter.highlight(<<~RUBY)
    # Parse a color (hex, rgb, hsl, oklch, ansi, css named, x11)
    parse("#ff5733")
    parse("goldenrod")

    # Manually create colors
    rgb(255, 87, 51, alpha: percentage(50))
    hsl(9, 100, 60)
    oklch(0.65, 0.22, 30)

    # Show a color card
    show("#ff5733")

    # Make a rainbow
    puts gradient(:linear, %w[red orange yellow green blue purple], direction: "to right").rasterize(width: 60).to_ansi

    # Generate Tailwind color scales
    puts gradient(:linear, parse("#3b82f6").scale(steps: 11, anchor: 5), direction: "to right").rasterize(width: 60).to_ansi
  RUBY

  "#{link}\n\n#{code}"
end

#to_sString

Returns The rendered help text.

Returns:

  • (String)

    The rendered help text



43
44
45
# File 'lib/unmagic/color/console/help.rb', line 43

def to_s
  render
end