Module: RubyTUI::Modifier

Defined in:
lib/rubytui/modifier.rb

Overview

Text modifier flags stored as a bitmask on Style#modifiers.

Examples:

Check if bold is set

Modifier.contains?(style.modifiers, Modifier::BOLD)

Or use Style query methods

style.bold?

Constant Summary collapse

BOLD =

Bold text (SGR 1, cleared by SGR 22).

0b000001
DIM =

Dim / faint text (SGR 2, cleared by SGR 22).

0b000010
ITALIC =

Italic text (SGR 3, cleared by SGR 23).

0b000100
UNDERLINED =

Underlined text (SGR 4, cleared by SGR 24).

0b001000
REVERSED =

Reverse video: swap foreground and background (SGR 7, cleared by SGR 27).

0b010000
STRIKETHROUGH =

Strikethrough text (SGR 9, cleared by SGR 29).

0b100000
NONE =

No modifiers set.

0
ALL =

Map of flag => human-readable name.

{
  BOLD => "bold",
  DIM => "dim",
  ITALIC => "italic",
  UNDERLINED => "underlined",
  REVERSED => "reversed",
  STRIKETHROUGH => "strikethrough"
}.freeze
SGR_ON =

ANSI SGR codes for enabling modifiers.

{
  BOLD => "1",
  DIM => "2",
  ITALIC => "3",
  UNDERLINED => "4",
  REVERSED => "7",
  STRIKETHROUGH => "9"
}.freeze
SGR_OFF =

ANSI SGR codes for disabling modifiers.

{
  BOLD => "22",
  DIM => "22",
  ITALIC => "23",
  UNDERLINED => "24",
  REVERSED => "27",
  STRIKETHROUGH => "29"
}.freeze

Class Method Summary collapse

Class Method Details

.contains?(modifiers, flag) ⇒ Boolean

Check if a modifier flag is set in a bitmask.

Parameters:

  • modifiers (Integer) —

    the bitmask to check

  • flag (Integer) —

    the modifier constant (e.g., BOLD)

Returns:

  • (Boolean)


64
# File 'lib/rubytui/modifier.rb', line 64

def contains?(modifiers, flag) = modifiers.anybits?(flag)