Module: Ronin::Support::CLI::ANSI
- Defined in:
- lib/ronin/support/cli/ansi.rb
Overview
Defines ANSI colors.
Constant Summary collapse
- RESET =
ANSI reset code
"\e[0m"
- BOLD_ON =
ANSI code for bold text
"\e[1m"
- BOLD_OFF =
ANSI code to disable boldness
"\e[22m"
- BLACK =
ANSI color code for black
"\e[30m"
- RED =
ANSI color code for red
"\e[31m"
- GREEN =
ANSI color code for green
"\e[32m"
- YELLOW =
ANSI color code for yellow
"\e[33m"
- BLUE =
ANSI color code for blue
"\e[34m"
- MAGENTA =
ANSI color code for magenta
"\e[35m"
- CYAN =
ANSI color code for cyan
"\e[36m"
- WHITE =
ANSI color code for white
"\e[37m"
- RESET_COLOR =
ANSI color for the default foreground color
"\e[39m"
Foreground Color Methods collapse
-
.black(string = nil) ⇒ String
Sets the text color to black.
-
.blue(string = nil) ⇒ String
Sets the text color to blue.
-
.cyan(string = nil) ⇒ String
Sets the text color to cyan.
-
.green(string = nil) ⇒ String
Sets the text color to green.
-
.magenta(string = nil) ⇒ String
Sets the text color to magenta.
-
.red(string = nil) ⇒ String
Sets the text color to red.
-
.white(string = nil) ⇒ String
Sets the text color to white.
-
.yellow(string = nil) ⇒ String
Sets the text color to yellow.
Class Method Summary collapse
-
.bold(string = nil) ⇒ String
Bolds the text.
-
.clear ⇒ String?
Alias for ANSI.reset.
-
.reset ⇒ String?
Resets text formatting.
Class Method Details
.black(string = nil) ⇒ String
Sets the text color to black.
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ronin/support/cli/ansi.rb', line 140 def black(string=nil) if string if $stdout.tty? then "#{BLACK}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then BLACK else '' end end end |
.blue(string = nil) ⇒ String
Sets the text color to blue.
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/ronin/support/cli/ansi.rb', line 240 def blue(string=nil) if string if $stdout.tty? then "#{BLUE}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then BLUE else '' end end end |
.bold(string = nil) ⇒ String
Bolds the text.
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ronin/support/cli/ansi.rb', line 111 def bold(string=nil) if string if $stdout.tty? then "#{BOLD_ON}#{string}#{BOLD_OFF}" else string end else if $stdout.tty? then BOLD_ON else '' end end end |
.clear ⇒ String?
Alias for reset.
94 95 96 |
# File 'lib/ronin/support/cli/ansi.rb', line 94 def clear reset end |
.cyan(string = nil) ⇒ String
Sets the text color to cyan.
290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/ronin/support/cli/ansi.rb', line 290 def cyan(string=nil) if string if $stdout.tty? then "#{CYAN}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then CYAN else '' end end end |
.green(string = nil) ⇒ String
Sets the text color to green.
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ronin/support/cli/ansi.rb', line 190 def green(string=nil) if string if $stdout.tty? then "#{GREEN}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then GREEN else '' end end end |
.magenta(string = nil) ⇒ String
Sets the text color to magenta.
265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/ronin/support/cli/ansi.rb', line 265 def magenta(string=nil) if string if $stdout.tty? then "#{MAGENTA}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then MAGENTA else '' end end end |
.red(string = nil) ⇒ String
Sets the text color to red.
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/ronin/support/cli/ansi.rb', line 165 def red(string=nil) if string if $stdout.tty? then "#{RED}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then RED else '' end end end |
.reset ⇒ String?
Resets text formatting.
78 79 80 81 82 |
# File 'lib/ronin/support/cli/ansi.rb', line 78 def reset if $stdout.tty? then RESET else '' end end |
.white(string = nil) ⇒ String
Sets the text color to white.
315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/ronin/support/cli/ansi.rb', line 315 def white(string=nil) if string if $stdout.tty? then "#{WHITE}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then WHITE else '' end end end |
.yellow(string = nil) ⇒ String
Sets the text color to yellow.
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/ronin/support/cli/ansi.rb', line 215 def yellow(string=nil) if string if $stdout.tty? then "#{YELLOW}#{string}#{RESET_COLOR}" else string end else if $stdout.tty? then YELLOW else '' end end end |