Skip to content

Predefined ANSI styles (Style=Spock, Style=Kirk) never apply #4254

Description

@ramanathan1504

%xEx{ansi(Style=Spock)} and %xEx{ansi(Style=Kirk)} render with no styling at all.

Two defects in JAnsiTextRenderer:

  1. JAnsiTextRenderer.java:217 — the predefined map is merged with map.putAll(predefinedMap),
    which keeps its keys as written (Name, Message, …), but lookup at line 247 is
    styleMap.get(toRootUpperCase(styleName)), so nothing ever matches. The name falls through to
    AnsiEscape.createSequence("Name"), which warns and returns an empty ESC[m.
  2. JAnsiTextRenderer.java:97-101entry() builds CSI + code + code with no ; separator
    and no m suffix, so entry("Name", BG_RED, WHITE) yields ESC[4137. merge() at line 263
    then strips a trailing m that was never appended. Masked today by (1).

Reproduced against 2.x HEAD, new JAnsiTextRenderer(new String[] {"ansi", "Style=Spock"}, emptyMap()):

  Name          -> ESC[m XYZ ESC[m                                                                                                                                          
  Name,Message  -> ESC[;m XYZ ESC[m                                                                                                                                         
  bg_red,white  -> ESC[41;37m XYZ ESC[m   (user-supplied styles are fine)                                                                                                   

main has both defects in the renamed AnsiTextRenderer (lines 192, 96-99, 238).

Found while reviewing #4184; unrelated to that PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions