Skip to content

Commit

Permalink
Correctly escape text, fixes #123
Browse files Browse the repository at this point in the history
  • Loading branch information
si618 committed Feb 9, 2025
1 parent 8e0700d commit c4b65cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/Lolcat/Rainbow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ internal Rainbow(IConsole console, RainbowStyle? rainbowStyle = null) : this(rai
/// </summary>
public string Markup(string text, double seed)
{
var lines = Spectre.Console.Markup
.Escape(text)
.ReplaceLineEndings()
.Split(Environment.NewLine);

Lines.Clear();
Lines.AddRange(lines);
Lines.AddRange(text.ReplaceLineEndings().Split(Environment.NewLine));

BuildLines(seed);

Expand Down Expand Up @@ -79,7 +74,7 @@ public string Markup(string text, double seed)
public void WriteLineWithMarkup(string text, double seed) =>
Console.WriteLine(Markup(text, seed));

internal List<string> Lines { get; } = new();
internal List<string> Lines { get; } = [];
private StringBuilder Line { get; } = new();

internal double GetStartingSeed()
Expand Down Expand Up @@ -119,6 +114,11 @@ private void BuildLine(string line, double seed)
var pair = i + 1 < line.Length && char.IsSurrogatePair(line[i], line[i + 1]);
var @char = pair ? line[i] + line[++i].ToString() : line[i].ToString();

if (RainbowStyle.EscapeSequence == EscapeSequence.Spectre)
{
@char = @char.EscapeMarkup();
}

Line.AppendFormat(Console.Format, red, green, blue, @char);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Lolcat.Tests/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Lolcat.Tests/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The lovers, the dreamers and me
<value>[rgb(254,68,60)]S[/][rgb(254,64,64)]p[/][rgb(254,61,67)]e[/][rgb(254,57,71)]c[/][rgb(254,54,75)]t[/][rgb(253,50,79)]r[/][rgb(253,47,83)]e[/][rgb(252,44,87)]R[/][rgb(251,41,91)]a[/][rgb(250,38,95)]i[/][rgb(249,35,99)]n[/][rgb(248,32,103)]b[/][rgb(246,29,107)]o[/][rgb(245,26,111)]w[/]</value>
</data>
<data name="SpectreMarkupWithEscapeCharacters" xml:space="preserve">
<value>[rgb(254,68,60)][[/][rgb(254,64,64)][[/][rgb(254,61,67)]L[/][rgb(254,57,71)]e[/][rgb(254,54,75)]f[/][rgb(253,50,79)]t[/][rgb(253,47,83)][[/][rgb(252,44,87)][[/][rgb(251,41,91)][[/][rgb(250,38,95)][[/][rgb(249,35,99)]M[/][rgb(248,32,103)]i[/][rgb(246,29,107)]d[/][rgb(245,26,111)]d[/][rgb(243,24,116)]l[/][rgb(241,22,120)]e[/][rgb(239,19,124)]][/][rgb(237,17,128)]][/][rgb(235,15,132)]][/][rgb(233,13,137)]][/][rgb(230,11,141)]R[/][rgb(228,10,145)]i[/][rgb(225,8,149)]g[/][rgb(222,7,153)]h[/][rgb(219,6,158)]t[/][rgb(216,4,162)]][/][rgb(213,4,166)]][/]</value>
<value>[rgb(254,68,60)][[[/][rgb(254,64,64)]L[/][rgb(254,61,67)]e[/][rgb(254,57,71)]f[/][rgb(254,54,75)]t[/][rgb(253,50,79)][[[/][rgb(253,47,83)][[[/][rgb(252,44,87)]M[/][rgb(251,41,91)]i[/][rgb(250,38,95)]d[/][rgb(249,35,99)]d[/][rgb(248,32,103)]l[/][rgb(246,29,107)]e[/][rgb(245,26,111)]]][/][rgb(243,24,116)]]][/][rgb(241,22,120)]R[/][rgb(239,19,124)]i[/][rgb(237,17,128)]g[/][rgb(235,15,132)]h[/][rgb(233,13,137)]t[/][rgb(230,11,141)]]][/]</value>
</data>
<data name="SpectreMarkupSeed1" xml:space="preserve">
<value>[rgb(254,68,60)]S[/][rgb(254,64,64)]o[/][rgb(254,61,67)]m[/][rgb(254,57,71)]e[/][rgb(254,54,75)]d[/][rgb(253,50,79)]a[/][rgb(253,47,83)]y[/][rgb(252,44,87)] [/][rgb(251,41,91)]w[/][rgb(250,38,95)]e[/][rgb(249,35,99)]'[/][rgb(248,32,103)]l[/][rgb(246,29,107)]l[/][rgb(245,26,111)] [/][rgb(243,24,116)]f[/][rgb(241,22,120)]i[/][rgb(239,19,124)]n[/][rgb(237,17,128)]d[/][rgb(235,15,132)] [/][rgb(233,13,137)]i[/][rgb(230,11,141)]t[/][rgb(228,10,145)],[/][rgb(225,8,149)] [/][rgb(222,7,153)]t[/][rgb(219,6,158)]h[/][rgb(216,4,162)]e[/][rgb(213,4,166)] [/][rgb(210,3,170)]r[/][rgb(207,2,174)]a[/][rgb(204,1,178)]i[/][rgb(200,1,181)]n[/][rgb(197,1,185)]b[/][rgb(193,1,189)]o[/][rgb(189,1,193)]w[/][rgb(186,1,196)] [/][rgb(182,1,200)]c[/][rgb(178,1,203)]o[/][rgb(174,2,207)]n[/][rgb(170,3,210)]n[/][rgb(166,3,213)]e[/][rgb(162,4,216)]c[/][rgb(158,6,219)]t[/][rgb(154,7,222)]i[/][rgb(150,8,225)]o[/][rgb(145,10,227)]n[/]
Expand Down

0 comments on commit c4b65cf

Please sign in to comment.