Module: Elasticsearch::API::Response::ColorHelper

Included in:
ExplainRenderer
Defined in:
lib/elasticsearch/api/response/color_helper.rb

Instance Method Summary collapse

Instance Method Details

#ansi(str, *codes) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/elasticsearch/api/response/color_helper.rb', line 25

def ansi(str, *codes)
  if colorized?
    str.to_s.ansi(*codes)
  else
    str.to_s
  end
end

#colorized?Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# File 'lib/elasticsearch/api/response/color_helper.rb', line 5

def colorized?
  unless @ansi_loaded
    @colorized = load_ansi
  else
    !!@colorized
  end
end

#disable_colorizationObject



13
14
15
16
# File 'lib/elasticsearch/api/response/color_helper.rb', line 13

def disable_colorization
  @ansi_loaded = true
  @colorized = false
end

#load_ansiObject



18
19
20
21
22
23
# File 'lib/elasticsearch/api/response/color_helper.rb', line 18

def load_ansi
  require "ansi/core"
  true
rescue LoadError
  false
end