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::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

Constant Summary collapse

HIDE_CURSOR =
"\e[?25l"
SHOW_CURSOR =
"\e[?25h"
CLEAR_SCREEN =
"\e[2J\e[H"

Class 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