Skip to content

Commit 582c116

Browse files
committed
Feat: Underline
1 parent cfd19b4 commit 582c116

18 files changed

+234
-214
lines changed

src/CodeOfChaos.Ansi.Generators/AnsiStringBuilderGenerator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ public void Initialize(IncrementalGeneratorInitializationContext context) {
3636
private static void GenerateCode(SourceProductionContext context, ImmutableArray<AdditionalText> files) {
3737
IEnumerable<ColorEntry> colors = files.SelectMany(file => ParseColorFile(context, file)).ToArray();
3838
var builder = new GeneratorStringBuilder();
39-
39+
4040
#region Fore & Background
41-
foreach (string section in new[] {"Foreground", "Background"}) {
41+
foreach (string section in new[] { "Foreground", "Background", "Underline" }) {
4242
context.AddSource($"Ansi{section}Builder.g.cs", builder
4343
.AppendUsings("System")
4444
.AppendAutoGenerated()
4545
.AppendNamespace("CodeOfChaos.Ansi")
4646
.AppendLine($"public partial class Ansi{section}Builder {{")
47-
.ForEach(colors, (stringBuilder, entry) => stringBuilder
47+
.ForEach(colors, itemFormatter: (stringBuilder, entry) => stringBuilder
4848
.AppendBodyIndented($$"""
4949
#region {{entry.Name}}
5050
private static CodeOfChaos.Ansi.ByteVector3 _{{entry.Name}} = new({{entry.Colors}});
51-
51+
5252
public string {{entry.Name}}(string text) => $"{CodeOfChaos.Ansi.AnsiCodes.Rgb{{section}}Color(_{{entry.Name}})}{text}{CodeOfChaos.Ansi.AnsiCodes.ResetGraphicsModes}";
53-
53+
5454
public Ansi{{section}}Builder Append{{entry.Name}}(string text) => BuilderAction(() => {
5555
Builder
5656
.Append(CodeOfChaos.Ansi.AnsiCodes.Rgb{{section}}Color(_{{entry.Name}}))
@@ -70,21 +70,21 @@ private static void GenerateCode(SourceProductionContext context, ImmutableArray
7070
action(this);
7171
Builder.Append(CodeOfChaos.Ansi.AnsiCodes.ResetGraphicsModes);
7272
});
73-
73+
7474
public Ansi{{section}}Builder Append{{entry.Name}}Line(string text) => BuilderAction(() => {
7575
Builder
7676
.Append(CodeOfChaos.Ansi.AnsiCodes.Rgb{{section}}Color(_{{entry.Name}}))
7777
.Append(text)
7878
.AppendLine(CodeOfChaos.Ansi.AnsiCodes.ResetGraphicsModes);
7979
});
80-
80+
8181
public Ansi{{section}}Builder Append{{entry.Name}}Line(Func<string> action) => BuilderAction(() => {
8282
Builder
8383
.Append(CodeOfChaos.Ansi.AnsiCodes.Rgb{{section}}Color(_{{entry.Name}}))
8484
.Append(action())
8585
.AppendLine(CodeOfChaos.Ansi.AnsiCodes.ResetGraphicsModes);
8686
});
87-
87+
8888
public Ansi{{section}}Builder Append{{entry.Name}}Line(Action<Ansi{{section}}Builder> action) => BuilderAction(() => {
8989
Builder.Append(CodeOfChaos.Ansi.AnsiCodes.Rgb{{section}}Color(_{{entry.Name}}));
9090
action(this);
@@ -97,7 +97,7 @@ private static void GenerateCode(SourceProductionContext context, ImmutableArray
9797
)
9898
.AppendLine("}")
9999
.ToStringAndClear()
100-
);
100+
);
101101
}
102102
#endregion
103103
}

src/CodeOfChaos.Ansi.Generators/CodeOfChaos.Ansi.Generators.csproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@
3131
</PropertyGroup>
3232

3333
<ItemGroup>
34-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
35-
<None Include="../../README.md" Pack="true" PackagePath="" />
36-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
34+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
35+
<None Include="../../README.md" Pack="true" PackagePath=""/>
36+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
3737
</ItemGroup>
3838

3939
<!-- Package dependencies -->
4040
<ItemGroup>
41-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
42-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" PrivateAssets="all" />
43-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
44-
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.2.0" Pack="true" GeneratePathProperty="true" PrivateAssets="all" />
41+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all"/>
42+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" PrivateAssets="all"/>
43+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all"/>
44+
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.2.0" Pack="true" GeneratePathProperty="true" PrivateAssets="all"/>
4545
</ItemGroup>
4646

4747
<ItemGroup>
48-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
49-
<None Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
48+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
49+
<None Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
5050
</ItemGroup>
5151

5252
</Project>

src/CodeOfChaos.Ansi.Generators/Xml/ColorEntryContainer.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@ public class ColorEntryContainer {
1818
}
1919

2020
public class XmlColorEntry {
21+
22+
private readonly Regex _regexCommaSeparated = new(@"^(\d+)[,.;:](\d+)[,.;:](\d+)$", RegexOptions.Compiled);
23+
private readonly Regex _regexHexFormat = new(@"^#?([A-Fa-f0-9]{6})$", RegexOptions.Compiled);
2124
[XmlAttribute("Name")]
2225
public string Name { get; set; } = string.Empty;// Name attribute for the color
2326

2427
[XmlAttribute("Color")]
2528
public string Color { get; set; } = string.Empty;// RGB values as a comma-separated string
26-
27-
private readonly Regex _regexCommaSeparated = new(@"^(\d+)[,.;:](\d+)[,.;:](\d+)$", RegexOptions.Compiled);
28-
private readonly Regex _regexHexFormat = new(@"^#?([A-Fa-f0-9]{6})$", RegexOptions.Compiled);
2929

3030
public ColorEntry ToColorEntry() {
31-
if (_regexCommaSeparated.Match(Color) is {Success : true } match) return new ColorEntry {
32-
Name = Name,
33-
Codes = [
34-
int.Parse(match.Groups[1].Value),
35-
int.Parse(match.Groups[2].Value),
36-
int.Parse(match.Groups[3].Value)
37-
]
38-
};
31+
if (_regexCommaSeparated.Match(Color) is { Success : true } match)
32+
return new ColorEntry {
33+
Name = Name,
34+
Codes = [
35+
int.Parse(match.Groups[1].Value),
36+
int.Parse(match.Groups[2].Value),
37+
int.Parse(match.Groups[3].Value)
38+
]
39+
};
3940

4041
if (_regexHexFormat.IsMatch(Color)) {
4142
string hex = Color.TrimStart('#');
@@ -55,6 +56,6 @@ public class ColorEntry {
5556
public string Name { get; set; } = string.Empty;// Mapped Name
5657

5758
public int[] Codes { get; set; } = [];// Mapped and split RGB values
58-
59+
5960
public string Colors => string.Join(",", Codes);
6061
}

0 commit comments

Comments
 (0)