Module: Cape::XTerm Private

Defined in:
lib/cape/xterm.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.

Formats output for an xterm console.

Convenience class methods are made available dynamically that permit multiple formats to be applied.

Examples:

Apply bold and red-foreground formatting to a string

Cape::XTerm.bold_and_foreground_red 'foo'

Constant Summary

FORMATS =

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

The xterm formatting codes.

{:bold               =>  '1',
:underlined         =>  '4',
:blinking           =>  '5',
:inverse            =>  '7',
:foreground_black   => '30',
:foreground_red     => '31',
:foreground_green   => '32',
:foreground_yellow  => '33',
:foreground_blue    => '34',
:foreground_magenta => '35',
:foreground_cyan    => '36',
:foreground_gray    => '37',
:foreground_default => '39',
:background_black   => '40',
:background_red     => '41',
:background_green   => '42',
:background_yellow  => '43',
:background_blue    => '44',
:background_magenta => '45',
:background_cyan    => '46',
:background_gray    => '47',
:background_default => '49'}

Class Method Summary collapse

Class Method Details

.background_black(string) ⇒ String

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

Formats the specified string with a black background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 181

.background_blue(string) ⇒ String

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

Formats the specified string with a blue background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 225

.background_cyan(string) ⇒ String

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

Formats the specified string with a cyan background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 247

.background_default(string) ⇒ String

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

Formats the specified string in the default background color.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 269

.background_gray(string) ⇒ String

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

Formats the specified string with a gray background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 258

.background_green(string) ⇒ String

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

Formats the specified string with a green background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 203

.background_magenta(string) ⇒ String

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

Formats the specified string with a magenta background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 236

.background_red(string) ⇒ String

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

Formats the specified string with a red background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 192

.background_yellow(string) ⇒ String

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

Formats the specified string with a yellow background.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 214

.blinking(string) ⇒ String

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

Formats the specified string in blinking type.

Parameters:

  • string (String)

    the string to blink

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 60

.bold(string) ⇒ String

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

Formats the specified string in bold type.

Parameters:

  • string (String)

    the string to format in bold type

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 38

.foreground_black(string) ⇒ String

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

Formats the specified string in black.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 82

.foreground_blue(string) ⇒ String

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

Formats the specified string in blue.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 126

.foreground_cyan(string) ⇒ String

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

Formats the specified string in cyan.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 148

.foreground_default(string) ⇒ String

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

Formats the specified string in the default foreground color.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 170

.foreground_gray(string) ⇒ String

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

Formats the specified string in gray.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 159

.foreground_green(string) ⇒ String

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

Formats the specified string in green.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 104

.foreground_magenta(string) ⇒ String

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

Formats the specified string in magenta.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 137

.foreground_red(string) ⇒ String

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

Formats the specified string in red.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 93

.foreground_yellow(string) ⇒ String

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

Formats the specified string in yellow.

Parameters:

  • string (String)

    the string to color

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 115

.format(string, *formats) ⇒ String

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

Applies the specified formats to string.

Parameters:

  • string (String)

    the string to format

  • formats (Array of Symbol)

    the formats to apply

Returns:

  • (String)

    the formatted string



286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/cape/xterm.rb', line 286

def self.format(string, *formats)
  formatting_codes = formats.collect do |f|
    unless FORMATS.key?(f)
      raise ::ArgumentError, "Unrecognized format #{f.inspect}"
    end

    FORMATS[f]
  end

  return string if formatting_codes.empty? || string.nil?

  "\e[#{formatting_codes.join ';'}m#{string}\e[0m"
end

.inverse(string) ⇒ String

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

Formats the specified string in inverse colors.

Parameters:

  • string (String)

    the string whose colors are to be inverted

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 71

.underlined(string) ⇒ String

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

Formats the specified string in underlined type.

Parameters:

  • string (String)

    the string to underline

Returns:

  • (String)

    the formatted string



# File 'lib/cape/xterm.rb', line 49