mapEffectsImpl

Replaces mIRC tokens with terminal effect codes, in an alternating fashion so as to support repeated effects toggling behaviour. Now with less regex.

It seems to be the case that a token for bold text will trigger bold text up until the next bold token. If we only naïvely replace all mIRC tokens for bold text then, we'll get lines that start off bold and continue as such until the very end.

Instead we iterate all occurrences of the passed mircToken, toggling the effect on and off.

private @safe pure
string
mapEffectsImpl
(
Flag!"strip" strip
TerminalFormat terminalFormatCode
)
(
const string line
)

Parameters

strip

Whether or not to strip effects or map them.

mircToken

mIRC token for a particular text effect.

terminalFormatCode

Terminal equivalent of the mircToken effect.

line string

The mIRC-formatted string to translate.

Return Value

Type: string

The passed line, now with terminal formatting.

Examples

import kameloso.terminal : TerminalToken;
import lu.conv : toAlpha;

alias I = IRCControlCharacter;
alias TF = TerminalFormat;

enum bBold = TerminalToken.format ~ "[" ~ TF.bold.toAlpha ~ "m";
enum bReset = TerminalToken.format ~ "[22m";

{
    enum line = "derp " ~ I.bold ~ "herp derp" ~ I.bold ~ "der dper";
    immutable mapped = mapEffectsImpl!(No.strip, I.bold, TF.bold)(line);
    assert((mapped == "derp " ~ bBold ~ "herp derp" ~ bReset ~ "der dper"), mapped);
}