|
| 1 | +# Cloud Foundry Java Buildpack |
| 2 | +# Copyright 2013-2017 the original author or authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +class String |
| 17 | + |
| 18 | + @color_enabled = true |
| 19 | + |
| 20 | + class << self |
| 21 | + attr_accessor :color_enabled |
| 22 | + end |
| 23 | + |
| 24 | + # Sets the string to bold |
| 25 | + def bold |
| 26 | + return self unless @color_enabled |
| 27 | + "\e[1m#{self}\e[22m" |
| 28 | + end |
| 29 | + |
| 30 | + # Sets the string to italic |
| 31 | + def italic |
| 32 | + return self unless @color_enabled |
| 33 | + "\e[3m#{self}\e[23m" |
| 34 | + end |
| 35 | + |
| 36 | + # Sets the string to underlined |
| 37 | + def underline |
| 38 | + return self unless @color_enabled |
| 39 | + "\e[4m#{self}\e[24m" |
| 40 | + end |
| 41 | + |
| 42 | + # Sets the string to blink |
| 43 | + def blink |
| 44 | + return self unless @color_enabled |
| 45 | + "\e[5m#{self}\e[25m" |
| 46 | + end |
| 47 | + |
| 48 | + # Sets the string reverse the current colors |
| 49 | + def reverse_color |
| 50 | + return self unless @color_enabled |
| 51 | + "\e[7m#{self}\e[27m" |
| 52 | + end |
| 53 | + |
| 54 | + # Sets the string to black |
| 55 | + def black |
| 56 | + return self unless @color_enabled |
| 57 | + "\e[30m#{self}\e[0m" |
| 58 | + end |
| 59 | + |
| 60 | + # Sets the string to red |
| 61 | + def red |
| 62 | + return self unless @color_enabled |
| 63 | + "\e[31m#{self}\e[0m" |
| 64 | + end |
| 65 | + |
| 66 | + # Sets the string to green |
| 67 | + def green |
| 68 | + return self unless @color_enabled |
| 69 | + "\e[32m#{self}\e[0m" |
| 70 | + end |
| 71 | + |
| 72 | + # Sets the string to yellow |
| 73 | + def yellow |
| 74 | + return self unless @color_enabled |
| 75 | + "\e[33m#{self}\e[0m" |
| 76 | + end |
| 77 | + |
| 78 | + # Sets the string to blue |
| 79 | + def blue |
| 80 | + return self unless @color_enabled |
| 81 | + "\e[34m#{self}\e[0m" |
| 82 | + end |
| 83 | + |
| 84 | + # Sets the string to magenta |
| 85 | + def magenta |
| 86 | + return self unless @color_enabled |
| 87 | + "\e[35m#{self}\e[0m" |
| 88 | + end |
| 89 | + |
| 90 | + # Sets the string to cyan |
| 91 | + def cyan |
| 92 | + return self unless @color_enabled |
| 93 | + "\e[36m#{self}\e[0m" |
| 94 | + end |
| 95 | + |
| 96 | + # Sets the string to white |
| 97 | + def white |
| 98 | + return self unless @color_enabled |
| 99 | + "\e[37m#{self}\e[0m" |
| 100 | + end |
| 101 | + |
| 102 | + # Sets the string background to black |
| 103 | + def bg_black |
| 104 | + return self unless @color_enabled |
| 105 | + "\e[40m#{self}\e[0m" |
| 106 | + end |
| 107 | + |
| 108 | + # Sets the string background to red |
| 109 | + def bg_red |
| 110 | + return self unless @color_enabled |
| 111 | + "\e[41m#{self}\e[0m" |
| 112 | + end |
| 113 | + |
| 114 | + # Sets the string background to green |
| 115 | + def bg_green |
| 116 | + return self unless @color_enabled |
| 117 | + "\e[42m#{self}\e[0m" |
| 118 | + end |
| 119 | + |
| 120 | + # Sets the string background to yellow |
| 121 | + def bg_yellow |
| 122 | + return self unless @color_enabled |
| 123 | + "\e[43m#{self}\e[0m" |
| 124 | + end |
| 125 | + |
| 126 | + # Sets the string background to blue |
| 127 | + def bg_blue |
| 128 | + return self unless @color_enabled |
| 129 | + "\e[44m#{self}\e[0m" |
| 130 | + end |
| 131 | + |
| 132 | + # Sets the string background to magenta |
| 133 | + def bg_magenta |
| 134 | + return self unless @color_enabled |
| 135 | + "\e[45m#{self}\e[0m" |
| 136 | + end |
| 137 | + |
| 138 | + # Sets the string background to cyan |
| 139 | + def bg_cyan |
| 140 | + return self unless @color_enabled |
| 141 | + "\e[46m#{self}\e[0m" |
| 142 | + end |
| 143 | + |
| 144 | + # Sets the string background to white |
| 145 | + def bg_white |
| 146 | + return self unless @color_enabled |
| 147 | + "\e[47m#{self}\e[0m" |
| 148 | + end |
| 149 | + |
| 150 | +end |
0 commit comments