Module: Sai::ModeSelector

Defined in:
lib/sai/mode_selector.rb

Overview

Color mode selection methods

Author:

Since:

  • 0.2.0

API:

  • public

Class Method Summary collapse

Class Method Details

.advanced ⇒ Integer Also known as: color256, colour256, eight_bit, two_hundred_fifty_six_color, two_hundred_fifty_six_colour

Set the color mode to 256 color (8-bit) mode

Examples:

Sai.mode.advanced  #=> 3
Sai.mode.eight_bit #=> 3
Sai.mode.color256  #=> 3

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



29
30
31
# File 'lib/sai/mode_selector.rb', line 29

def advanced
  Terminal::ColorMode::ADVANCED
end

.advanced_auto ⇒ Integer Also known as: color256_auto, colour256_auto, eight_bit_auto, two_hundred_fifty_six_color_auto, two_hundred_fifty_six_colour_auto

Automatically set the color mode to advanced (8-bit) or lower

Sets the terminal color mode to advanced (8-bit) support, which provides 256 colors The mode will automatically downgrade to 4-bit, 3-bit, or NO_COLOR if the terminal doesn't support advanced colors

Examples:

With color support enabled

ENV['COLORTERM']        #=> nil
ENV['TERM']             #=> 'xterm-256color'
Sai.mode.advanced_auto  #=> 3
Sai.mode.eight_bit_auto #=> 3
Sai.mode.color256_auto  #=> 3

With only 4-bit color support

ENV['NO_COLOR']         #=> nil
ENV['TERM']             #=> 'ansi'
Sai.mode.advanced_auto  #=> 2
Sai.mode.eight_bit_auto #=> 2
Sai.mode.color256_auto  #=> 2

With only 3-bit color support

ENV['TERM']             #=> nil
ENV['NO_COLOR']         #=> nil
Sai.mode.advanced_auto  #=> 1
Sai.mode.eight_bit_auto #=> 1
Sai.mode.color256_auto  #=> 1

With color support disabled

ENV['NO_COLOR']         #=> 'true'
Sai.mode.advanced_auto  #=> 0
Sai.mode.eight_bit_auto #=> 0
Sai.mode.color256_auto  #=> 0

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



78
79
80
# File 'lib/sai/mode_selector.rb', line 78

def advanced_auto
  [Terminal::Capabilities.detect_color_support, Terminal::ColorMode::ADVANCED].min
end

.ansi ⇒ Integer Also known as: color16, colour16, four_bit, sixteen_color, sixteen_colour

Set the color mode to 16 color (4-bit) mode

Examples:

Sai.mode.ansi     #=> 2
Sai.mode.color16 #=> 2
Sai.mode.four_bit #=> 2

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



101
102
103
# File 'lib/sai/mode_selector.rb', line 101

def ansi
  Terminal::ColorMode::ANSI
end

.ansi_auto ⇒ Integer Also known as: color16_auto, colour16_auto, four_bit_auto, sixteen_color_auto, sixteen_colour_auto

Automatically set the color mode to ansi (4-bit) or lower

Sets the terminal color mode to ansi (4-bit) support, which provides 8 colors The mode will automatically downgrade to 3-bit or NO_COLOR if the terminal doesn't support ansi colors

Examples:

With color support enabled

ENV['NO_COLOR'] #=> nil
ENV['TERM'] #=> 'ansi'
Sai.mode.ansi_auto     #=> 2
Sai.mode.four_bit_auto #=> 2
Sai.mode.color16_auto  #=> 2

With only 3-bit color support

ENV['TERM']             #=> nil
ENV['NO_COLOR']         #=> nil
Sai.mode.ansi_auto      #=> 1
Sai.mode.four_bit_auto  #=> 1
Sai.mode.color16_auto   #=> 1

With color support disabled

ENV['NO_COLOR']         #=> 'true'
Sai.mode.ansi_auto      #=> 0
Sai.mode.four_bit_auto  #=> 0
Sai.mode.color16_auto   #=> 0

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



143
144
145
# File 'lib/sai/mode_selector.rb', line 143

def ansi_auto
  [Terminal::Capabilities.detect_color_support, Terminal::ColorMode::ANSI].min
end

.auto ⇒ Integer Also known as: color16m_auto, colour16m_auto, enabled, sixteen_million_color_auto, sixteen_million_colour_auto, twenty_for_bit_auto

Set the color mode based on the current Terminal's capabilities

This is the default color mode for Sai

Examples:

With 24-bit color support enabled

ENV['COLORTERM'] #=> 'truecolor'
Sai.node.auto    #=> 4

With only 8-bit color support enabled

ENV['COLORTERM'] #=> nil
ENV['TERM']      #=> 'xterm-256color'
Sai.mode.auto    #=> 3

With only 4-bit color support

ENV['NO_COLOR'] #=> nil
ENV['TERM']     #=> 'ansi'
Sai.mode.auto   #=> 2

With only 3-bit color support

ENV['TERM']     #=> nil
ENV['NO_COLOR'] #=> nil
Sai.mode.auto   #=> 1

With color support disabled

ENV['NO_COLOR'] #=> 'true'
Sai.mode.auto   #=> 0

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



186
187
188
# File 'lib/sai/mode_selector.rb', line 186

def auto
  Terminal::Capabilities.detect_color_support
end

.basic ⇒ Integer Also known as: color8, colour8, eight_color, eight_colour, three_bit

Set the color mode to 8 color (3-bit) mode

Examples:

Sai.mode.basic     #=> 1
Sai.mode.color8    #=> 1
Sai.mode.three_bit #=> 1

Returns:

  • the 4 color (3-bit) mode

Author:

Since:

  • 0.2.0

API:

  • public



210
211
212
# File 'lib/sai/mode_selector.rb', line 210

def basic
  Terminal::ColorMode::BASIC
end

.basic_auto ⇒ Integer Also known as: color8_auto, colour8_auto, eight_color_auto, eight_colour_auto, three_bit_auto

Automatically set the color mode to basic (3-bit) or lower

Sets the terminal color mode to basic (3-bit) support, which provides 8 colors The mode will automatically downgrade to NO_COLOR if the terminal doesn't support basic colors

Examples:

With color support enabled

ENV['NO_COLOR']         #=> nil
Sai.mode.basic_auto     #=> 1
Sai.mode.three_bit_auto #=> 1
Sai.mode.color8_auto    #=> 1

With color support disabled

ENV['NO_COLOR']         #=> 'true'
Sai.mode.basic_auto     #=> 0
Sai.mode.three_bit_auto #=> 0
Sai.mode.color8_auto    #=> 0

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



244
245
246
# File 'lib/sai/mode_selector.rb', line 244

def basic_auto
  [Terminal::Capabilities.detect_color_support, Terminal::ColorMode::BASIC].min
end

.no_color ⇒ Integer Also known as: disabled, mono, no_colour

Set the color mode to disable all color and styling

Examples:

Sai.mode.no_color #=> 0
Sai.mode.disabled #=> 0
Sai.mode.mono     #=> 0

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



267
268
269
# File 'lib/sai/mode_selector.rb', line 267

def no_color
  Terminal::ColorMode::NO_COLOR
end

.true_color ⇒ Integer Also known as: color16m, colour16m, sixteen_million_color, sixteen_million_colour, twenty_for_bit

Set the color mode to 16-million color (24-bit) mode

Examples:

Sai.mode.true_color      #=> 4
Sai.mode.twenty_four_bit #=> 4
Sai.mode.color_16m       #=> 4

Returns:

  • the color mode

Author:

Since:

  • 0.2.0

API:

  • public



288
289
290
# File 'lib/sai/mode_selector.rb', line 288

def true_color
  Terminal::ColorMode::TRUE_COLOR
end