Class: Brut::TUI::AnsiEscapeCode

Inherits:
Object
  • Object
show all
Extended by:
Mod
Defined in:
lib/brut/tui/ansi_escape_code.rb

Overview

Maps ANSI escape codes to logical names to make it easier to use in code. This is not intended to be exhaustive, but could grow over time as needed.

Defined Under Namespace

Modules: Mod

Constant Summary

Constants included from Mod

Mod::CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mod

ansi, object

Constructor Details

#initialize(name, code) ⇒ AnsiEscapeCode

Create a new AnsiEscapeCode with the given name and code.

Parameters:

  • name (String, Symbol)

    The logical name of the escape code. This should not have spaces and generally be able to be used as a Ruby identifier.

  • code (String)

    The actual ANSI escape code (without the leading \e[ and trailing m).



12
13
14
15
# File 'lib/brut/tui/ansi_escape_code.rb', line 12

def initialize(name, code)
  @name = name.to_sym
  @code = code
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/brut/tui/ansi_escape_code.rb', line 5

def name
  @name
end

Instance Method Details

#to_sObject

Returns the code suitable for sending to the terminal.



18
# File 'lib/brut/tui/ansi_escape_code.rb', line 18

def to_s = "\e[#{@code}m"