Module: Sai::Decorator::ColorManipulations Abstract Private

Included in:
Sai::Decorator
Defined in:
lib/sai/decorator/color_manipulations.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

This module is abstract.

This module is meant to be included in the Sai::Decorator class to provide color manipulation methods

Color manipulation methods for the Sai::Decorator class

Author:

Since:

  • 0.3.1

Instance Method Summary collapse

Instance Method Details

#darken_background(amount) ⇒ Decorator Also known as: darken_bg

Darken the background color by a percentage

Examples:

decorator.on_blue.darken_text(0.5).decorate('Hello, world!').to_s #=> "\e[48;2;0;0;238mHello, world!\e[0m"

Parameters:

  • amount (Float) —

    the amount to darken the background color (0.0...1.0)

Returns:

  • (Decorator) —

    a new instance of Decorator with the darkened background color

Raises:

  • (ArgumentError) —

    if the percentage is out of range

Author:

Since:

  • 0.3.1



28
29
30
31
32
# File 'lib/sai/decorator/color_manipulations.rb', line 28

def darken_background(amount)
  raise ArgumentError, "Invalid percentage: #{amount}" unless amount >= 0.0 && amount <= 1.0

  darken(amount, :background)
end

#darken_text(amount) ⇒ Decorator Also known as: darken_fg, darken_foreground

Darken the text color by a percentage

Examples:

decorator.blue.darken_text(0.5).decorate('Hello, world!').to_s #=> "\e[38;2;0;0;119mHello, world!\e[0m"

Parameters:

  • amount (Float) —

    the amount to darken the text color (0.0...1.0)

Returns:

  • (Decorator) —

    a new instance of Decorator with the darkened text color

Raises:

  • (ArgumentError) —

    if the percentage is out of range

Author:

Since:

  • 0.3.1



50
51
52
53
54
# File 'lib/sai/decorator/color_manipulations.rb', line 50

def darken_text(amount)
  raise ArgumentError, "Invalid percentage: #{amount}" unless amount >= 0.0 && amount <= 1.0

  darken(amount, :foreground)
end

#lighten_background(amount) ⇒ Decorator Also known as: lighten_bg

Lighten the background color by a percentage

Examples:

decorator.on_blue.lighten_background(0.5).decorate('Hello, world!').to_s
#=> "\e[48;2;0;0;255mHello, world!\e[0m"

Parameters:

  • amount (Float) —

    the amount to lighten the background color (0.0...1.0)

Returns:

  • (Decorator) —

    a new instance of Decorator with the lightened background color

Raises:

  • (ArgumentError) —

    if the percentage is out of range

Author:

Since:

  • 0.3.1



74
75
76
77
78
# File 'lib/sai/decorator/color_manipulations.rb', line 74

def lighten_background(amount)
  raise ArgumentError, "Invalid percentage: #{amount}" unless amount >= 0.0 && amount <= 1.0

  lighten(amount, :background)
end

#lighten_text(amount) ⇒ Decorator Also known as: lighten_fg, lighten_foreground

Lighten the text color by a percentage

Examples:

decorator.blue.lighten_text(0.5).decorate('Hello, world!').to_s #=> "\e[38;2;0;0;127mHello, world!\e[0m"

Parameters:

  • amount (Float) —

    the amount to lighten the text color (0.0...1.0)

Returns:

  • (Decorator) —

    a new instance of Decorator with the lightened text color

Raises:

  • (ArgumentError) —

    if the percentage is out of range

Author:

Since:

  • 0.3.1



96
97
98
99
100
# File 'lib/sai/decorator/color_manipulations.rb', line 96

def lighten_text(amount)
  raise ArgumentError, "Invalid percentage: #{amount}" unless amount >= 0.0 && amount <= 1.0

  lighten(amount, :foreground)
end