Module: Herb::Colors

Included in:
AST::CDATANode, AST::DocumentNode, AST::ERBBeginNode, AST::ERBBlockNode, AST::ERBCaseMatchNode, AST::ERBCaseNode, AST::ERBContentNode, AST::ERBElseNode, AST::ERBEndNode, AST::ERBEnsureNode, AST::ERBForNode, AST::ERBIfNode, AST::ERBInNode, AST::ERBOpenTagNode, AST::ERBRenderNode, AST::ERBRescueNode, AST::ERBStrictLocalsNode, AST::ERBUnlessNode, AST::ERBUntilNode, AST::ERBWhenNode, AST::ERBWhileNode, AST::ERBYieldNode, AST::HTMLAttributeNameNode, AST::HTMLAttributeNode, AST::HTMLAttributeValueNode, AST::HTMLCloseTagNode, AST::HTMLCommentNode, AST::HTMLConditionalElementNode, AST::HTMLConditionalOpenTagNode, AST::HTMLDoctypeNode, AST::HTMLElementNode, AST::HTMLOmittedCloseTagNode, AST::HTMLOpenTagNode, AST::HTMLTextNode, AST::HTMLVirtualCloseTagNode, AST::LiteralNode, AST::RubyHTMLAttributesSplatNode, AST::RubyLiteralNode, AST::RubyParameterNode, AST::RubyRenderKeywordsNode, AST::RubyRenderLocalNode, AST::WhitespaceNode, AST::XMLDeclarationNode, ActionView::RenderAnalyzer, CLI, Dev::Runner, Errors::ConditionalElementConditionMismatchError, Errors::ConditionalElementMultipleTagsError, Errors::DotNotationCasingError, Errors::ERBCaseWithConditionsError, Errors::ERBControlFlowScopeError, Errors::ERBMultipleBlocksInTagError, Errors::InvalidCommentClosingTagError, Errors::MissingAttributeValueError, Errors::MissingClosingTagError, Errors::MissingERBEndTagError, Errors::MissingOpeningTagError, Errors::NestedERBTagError, Errors::OmittedClosingTagError, Errors::RenderAmbiguousLocalsError, Errors::RenderConflictingPartialError, Errors::RenderInvalidAsOptionError, Errors::RenderLayoutWithoutBlockError, Errors::RenderMissingLocalsError, Errors::RenderNoArgumentsError, Errors::RenderObjectAndCollectionError, Errors::RubyParseError, Errors::StrayERBClosingTagError, Errors::StrictLocalsBlockArgumentError, Errors::StrictLocalsDuplicateDeclarationError, Errors::StrictLocalsMissingParenthesisError, Errors::StrictLocalsPositionalArgumentError, Errors::StrictLocalsSplatArgumentError, Errors::TagNamesMismatchError, Errors::TimeoutError, Errors::UnclosedCloseTagError, Errors::UnclosedERBTagError, Errors::UnclosedElementError, Errors::UnclosedOpenTagError, Errors::UnclosedQuoteError, Errors::UnexpectedError, Errors::UnexpectedTokenError, Errors::VoidElementClosingTagError, Errors::VoidElementContentError, Project, Token
Defined in:
lib/herb/colors.rb,
sig/herb/colors.rbs

Constant Summary collapse

HIDE_CURSOR =

Returns:

  • (::String)
"\e[?25l"
SHOW_CURSOR =

Returns:

  • (::String)
"\e[?25h"
CLEAR_SCREEN =

Returns:

  • (::String)
"\e[2J\e[H"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bold(string) ⇒ Object

: (String) -> String



80
81
82
83
84
# File 'lib/herb/colors.rb', line 80

def bold(string)
  return string unless enabled?

  "\e[1m#{string}\e[0m"
end

.bright_magenta(string) ⇒ Object

: (String) -> String



66
67
68
69
70
# File 'lib/herb/colors.rb', line 66

def bright_magenta(string)
  return string unless enabled?

  "\e[95m#{string}\e[0m"
end

.cyan(string) ⇒ Object

: (String) -> String



59
60
61
62
63
# File 'lib/herb/colors.rb', line 59

def cyan(string)
  return string unless enabled?

  "\e[36m#{string}\e[0m"
end

.dimmed(string) ⇒ Object

: (String) -> String



73
74
75
76
77
# File 'lib/herb/colors.rb', line 73

def dimmed(string)
  return string unless enabled?

  "\e[2m#{string}\e[0m"
end

.enabled?Boolean

: () -> bool

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/herb/colors.rb', line 15

def enabled?
  return false if ENV["NO_COLOR"]
  return false if defined?(IRB)
  return false if defined?(Minitest)

  $stdout.tty?
end

.fg(string, color) ⇒ Object

: (String, Integer) -> String



87
88
89
90
91
# File 'lib/herb/colors.rb', line 87

def fg(string, color)
  return string unless enabled?

  "\e[38;5;#{color}m#{string}\e[0m"
end

.fg_bg(string, foreground, background) ⇒ Object

: (String, Integer, Integer) -> String



94
95
96
97
98
# File 'lib/herb/colors.rb', line 94

def fg_bg(string, foreground, background)
  return string unless enabled?

  "\e[38;5;#{foreground};48;5;#{background}m#{string}\e[0m"
end

.green(string) ⇒ Object

: (String) -> String



38
39
40
41
42
# File 'lib/herb/colors.rb', line 38

def green(string)
  return string unless enabled?

  "\e[32m#{string}\e[0m"
end

.magenta(string) ⇒ Object

: (String) -> String



52
53
54
55
56
# File 'lib/herb/colors.rb', line 52

def magenta(string)
  return string unless enabled?

  "\e[35m#{string}\e[0m"
end

.red(string) ⇒ Object

: (String) -> String



45
46
47
48
49
# File 'lib/herb/colors.rb', line 45

def red(string)
  return string unless enabled?

  "\e[31m#{string}\e[0m"
end

.white(string) ⇒ Object

: (String) -> String



24
25
26
27
28
# File 'lib/herb/colors.rb', line 24

def white(string)
  return string unless enabled?

  "\e[37m#{string}\e[0m"
end

.yellow(string) ⇒ Object

: (String) -> String



31
32
33
34
35
# File 'lib/herb/colors.rb', line 31

def yellow(string)
  return string unless enabled?

  "\e[33m#{string}\e[0m"
end

Instance Method Details

#self?.boldString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


39
# File 'sig/herb/colors.rbs', line 39

def self?.bold: (String) -> String

#self?.bright_magentaString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


33
# File 'sig/herb/colors.rbs', line 33

def self?.bright_magenta: (String) -> String

#self?.cyanString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


30
# File 'sig/herb/colors.rbs', line 30

def self?.cyan: (String) -> String

#self?.dimmedString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


36
# File 'sig/herb/colors.rbs', line 36

def self?.dimmed: (String) -> String

#self?.enabled?Boolean

: () -> bool

Returns:

  • (Boolean)


12
# File 'sig/herb/colors.rbs', line 12

def self?.enabled?: () -> bool

#self?.fgString

: (String, Integer) -> String

Parameters:

  • (String)
  • (Integer)

Returns:

  • (String)


42
# File 'sig/herb/colors.rbs', line 42

def self?.fg: (String, Integer) -> String

#self?.fg_bgString

: (String, Integer, Integer) -> String

Parameters:

  • (String)
  • (Integer)
  • (Integer)

Returns:

  • (String)


45
# File 'sig/herb/colors.rbs', line 45

def self?.fg_bg: (String, Integer, Integer) -> String

#self?.greenString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


21
# File 'sig/herb/colors.rbs', line 21

def self?.green: (String) -> String

#self?.magentaString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


27
# File 'sig/herb/colors.rbs', line 27

def self?.magenta: (String) -> String

#self?.redString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


24
# File 'sig/herb/colors.rbs', line 24

def self?.red: (String) -> String

#self?.whiteString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


15
# File 'sig/herb/colors.rbs', line 15

def self?.white: (String) -> String

#self?.yellowString

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


18
# File 'sig/herb/colors.rbs', line 18

def self?.yellow: (String) -> String