Class: Hackmac::Graph::Display::Cell
- Inherits:
-
Struct
- Object
- Struct
- Hackmac::Graph::Display::Cell
- Defined in:
- lib/hackmac/graph/display.rb
Overview
A cell representation for terminal display with character, color, background color, and styling attributes
The Cell class encapsulates the properties of a single character cell in a terminal display, including its visual characteristics such as the displayed character, text color, background color, and styling attributes. It provides methods to compare cells and convert them to their string representation with ANSI escape codes for terminal rendering.
Instance Attribute Summary collapse
-
#char ⇒ Object
Returns the value of attribute char.
-
#color ⇒ Object
Returns the value of attribute color.
-
#on_color ⇒ Object
Returns the value of attribute on_color.
-
#styles ⇒ Object
Returns the value of attribute styles.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
The == method compares two Cell objects for equality by their internal array representation.
-
#to_s ⇒ String
The to_s method converts a Cell object into its string representation with ANSI styling.
Instance Attribute Details
#char ⇒ Object
Returns the value of attribute char
27 28 29 |
# File 'lib/hackmac/graph/display.rb', line 27 def char @char end |
#color ⇒ Object
Returns the value of attribute color
27 28 29 |
# File 'lib/hackmac/graph/display.rb', line 27 def color @color end |
#on_color ⇒ Object
Returns the value of attribute on_color
27 28 29 |
# File 'lib/hackmac/graph/display.rb', line 27 def on_color @on_color end |
#styles ⇒ Object
Returns the value of attribute styles
27 28 29 |
# File 'lib/hackmac/graph/display.rb', line 27 def styles @styles end |
Instance Method Details
#==(other) ⇒ Boolean
The == method compares two Cell objects for equality by their internal array representation
This method checks if the current Cell instance is equal to another Cell instance by comparing their underlying array representations returned by to_a
40 41 42 |
# File 'lib/hackmac/graph/display.rb', line 40 def ==(other) to_a == other.to_a end |
#to_s ⇒ String
The to_s method converts a Cell object into its string representation with ANSI styling
This method constructs a formatted string that includes the cell’s character along with its color, background color, and text style attributes using ANSI escape sequences. The resulting string is suitable for display in terminal environments that support ANSI colors.
54 55 56 57 58 59 60 61 |
# File 'lib/hackmac/graph/display.rb', line 54 def to_s result = +'' result << ANSI.color(color) result << ANSI.on_color(on_color) styles.each { |s| result << ANSI.send(s) } result << char result << ANSI.reset end |