Class: AsciinemaWin::AnsiParser::StyleState

Inherits:
Object
  • Object
show all
Defined in:
lib/asciinema_win/ansi_parser.rb

Overview

Current text style state

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStyleState

Returns a new instance of StyleState.



58
59
60
# File 'lib/asciinema_win/ansi_parser.rb', line 58

def initialize
  reset
end

Instance Attribute Details

#bgInteger?

Returns Background color (ANSI code or 256-color index).

Returns:

  • (Integer, nil)

    Background color (ANSI code or 256-color index)



38
39
40
# File 'lib/asciinema_win/ansi_parser.rb', line 38

def bg
  @bg
end

#bg_rgbString?

Returns RGB background (#rrggbb).

Returns:

  • (String, nil)

    RGB background (#rrggbb)



56
57
58
# File 'lib/asciinema_win/ansi_parser.rb', line 56

def bg_rgb
  @bg_rgb
end

#boldBoolean

Returns Bold/bright text.

Returns:

  • (Boolean)

    Bold/bright text



41
42
43
# File 'lib/asciinema_win/ansi_parser.rb', line 41

def bold
  @bold
end

#fgInteger?

Returns Foreground color (ANSI code or 256-color index).

Returns:

  • (Integer, nil)

    Foreground color (ANSI code or 256-color index)



35
36
37
# File 'lib/asciinema_win/ansi_parser.rb', line 35

def fg
  @fg
end

#fg_rgbString?

Returns RGB foreground (#rrggbb).

Returns:

  • (String, nil)

    RGB foreground (#rrggbb)



53
54
55
# File 'lib/asciinema_win/ansi_parser.rb', line 53

def fg_rgb
  @fg_rgb
end

#italicBoolean

Returns Italic text.

Returns:

  • (Boolean)

    Italic text



44
45
46
# File 'lib/asciinema_win/ansi_parser.rb', line 44

def italic
  @italic
end

#strikethroughBoolean

Returns Strikethrough text.

Returns:

  • (Boolean)

    Strikethrough text



50
51
52
# File 'lib/asciinema_win/ansi_parser.rb', line 50

def strikethrough
  @strikethrough
end

#underlineBoolean

Returns Underlined text.

Returns:

  • (Boolean)

    Underlined text



47
48
49
# File 'lib/asciinema_win/ansi_parser.rb', line 47

def underline
  @underline
end

Instance Method Details

#effective_bgInteger, ...

Get effective background color

Returns:

  • (Integer, String, nil)

    Color value



86
87
88
# File 'lib/asciinema_win/ansi_parser.rb', line 86

def effective_bg
  bg_rgb || bg
end

#effective_fgInteger, ...

Get effective foreground color

Returns:

  • (Integer, String, nil)

    Color value



79
80
81
# File 'lib/asciinema_win/ansi_parser.rb', line 79

def effective_fg
  fg_rgb || fg
end

#resetvoid

This method returns an undefined value.

Reset all attributes to default



65
66
67
68
69
70
71
72
73
74
# File 'lib/asciinema_win/ansi_parser.rb', line 65

def reset
  @fg = nil
  @bg = nil
  @bold = false
  @italic = false
  @underline = false
  @strikethrough = false
  @fg_rgb = nil
  @bg_rgb = nil
end

#to_styled_char(char) ⇒ StyledChar

Create a StyledChar from current state

Parameters:

  • char (String)

    Character

Returns:



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/asciinema_win/ansi_parser.rb', line 94

def to_styled_char(char)
  StyledChar.new(
    char: char,
    fg: effective_fg,
    bg: effective_bg,
    bold: @bold,
    italic: @italic,
    underline: @underline,
    strikethrough: @strikethrough
  )
end