* Intern a style and return its ID. Bit 0 of the ID encodes whether the * style has a visible effect on space characters (background, inverse, * underline, etc.). Foreground-only styles get even IDs; styles visible * on spaces get odd IDs. This lets the renderer skip invisible spaces * w
(styles: AnsiCode[])
| 127 | * with a single bitmask check on the packed word. |
| 128 | */ |
| 129 | intern(styles: AnsiCode[]): number { |
| 130 | const key = styles.length === 0 ? '' : styles.map(s => s.code).join('\0') |
| 131 | let id = this.ids.get(key) |
| 132 | if (id === undefined) { |
| 133 | const rawId = this.styles.length |
| 134 | this.styles.push(styles.length === 0 ? [] : styles) |
| 135 | id = |
| 136 | (rawId << 1) | |
| 137 | (styles.length > 0 && hasVisibleSpaceEffect(styles) ? 1 : 0) |
| 138 | this.ids.set(key, id) |
| 139 | } |
| 140 | return id |
| 141 | } |
| 142 | |
| 143 | /** Recover styles from an encoded ID. Strips the bit-0 flag via >>> 1. */ |
| 144 | get(id: number): AnsiCode[] { |
no test coverage detected