Skip to content

Commit

Permalink
fix - reg|prt - Make colors work again in standalo...
Browse files Browse the repository at this point in the history
...ne analyzers

---

We've fixed a regression where we wouldn't write with color as we were upgrading Terminaux.

---

Type: fix
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/2
  • Loading branch information
AptiviCEO committed Sep 9, 2024
1 parent 892f824 commit dba6f4d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal static string[] GetUnlocalizedStrings()
bool localizable = (bool?)themeMetadata["Localizable"] ?? false;
if (!string.IsNullOrEmpty(description) && localizable && !EntryPoint.localizationList.Contains(description))
{
TextWriterColor.Write($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized theme description found: {description}", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized theme description found: {description}", true, ConsoleColors.Yellow);
unlocalizedStrings.Add(description);
}
}
Expand All @@ -74,12 +74,12 @@ internal static string[] GetUnlocalizedStrings()
string displayAs = ((string?)settingsEntryList["DisplayAs"] ?? "").Replace("\\\"", "\"");
if (!string.IsNullOrEmpty(description) && !EntryPoint.localizationList.Contains(description))
{
TextWriterColor.Write($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized settings description found: {description}", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized settings description found: {description}", true, ConsoleColors.Yellow);
unlocalizedStrings.Add(description);
}
if (!string.IsNullOrEmpty(displayAs) && !EntryPoint.localizationList.Contains(displayAs))
{
TextWriterColor.Write($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized settings display found: {displayAs}", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized settings display found: {displayAs}", true, ConsoleColors.Yellow);
unlocalizedStrings.Add(displayAs);
}

Expand All @@ -93,12 +93,12 @@ internal static string[] GetUnlocalizedStrings()
string keyDesc = ((string?)key["Description"] ?? "").Replace("\\\"", "\"");
if (!string.IsNullOrEmpty(keyName) && !EntryPoint.localizationList.Contains(keyName))
{
TextWriterColor.Write($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized key name found: {keyName}", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized key name found: {keyName}", true, ConsoleColors.Yellow);
unlocalizedStrings.Add(keyName);
}
if (!string.IsNullOrEmpty(keyDesc) && !EntryPoint.localizationList.Contains(keyDesc))
{
TextWriterColor.Write($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized key description found: {keyDesc}", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{nameof(NLOC0001)}Resources: {resourceName}: Unlocalized key description found: {keyDesc}", true, ConsoleColors.Yellow);
unlocalizedStrings.Add(keyDesc);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public bool Analyze(Document document, out string[] unlocalized)
if (!EntryPoint.localizationList.Contains(text))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Unlocalized string found: {text}", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Unlocalized string found: {text}", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void Process(LiteralExpressionSyntax literalText)
if (!EntryPoint.localizationList.Contains(text))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Unlocalized string found: {text}", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Unlocalized string found: {text}", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand Down
14 changes: 7 additions & 7 deletions private/Nitrocid.LocaleCheckerStandalone/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ static async Task Main()
// Create a workspace using the instance
using var workspace = MSBuildWorkspace.Create();
workspace.WorkspaceFailed += (o, e) =>
TextWriterColor.Write($"Failed to load the workspace: [{e.Diagnostic.Kind}] {e.Diagnostic.Message}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($"Failed to load the workspace: [{e.Diagnostic.Kind}] {e.Diagnostic.Message}", true, ConsoleColors.Red);

// Check for Nitrocid solution
var solutionPath = "../../../../../Nitrocid.sln";
if (!File.Exists(solutionPath))
{
TextWriterColor.Write("Can't find Nitrocid solution. Make sure that it's run from the Nitrocid repo.", true, ConsoleColors.Red);
TextWriterColor.WriteColor("Can't find Nitrocid solution. Make sure that it's run from the Nitrocid repo.", true, ConsoleColors.Red);
return;
}

// Attach progress reporter so we print projects as they are loaded.
TextWriterColor.Write($"Loading solution {solutionPath}...");
var solution = await workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter());
TextWriterColor.Write($"Finished loading solution {solutionPath}!", true, ConsoleColors.Green);
TextWriterColor.WriteColor($"Finished loading solution {solutionPath}!", true, ConsoleColors.Green);

// Find the English JSON stream and open it.
var stream = thisAssembly.GetManifestResourceStream("Nitrocid.LocaleCheckerStandalone.eng.json") ??
Expand Down Expand Up @@ -110,7 +110,7 @@ static async Task Main()
}
catch (Exception ex)
{
TextWriterColor.Write($"Analyzer failed: {ex.Message}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($"Analyzer failed: {ex.Message}", true, ConsoleColors.Red);
}
}
}
Expand All @@ -126,11 +126,11 @@ static async Task Main()

// Save all unlocalized strings
File.WriteAllLines("unlocalized.txt", totalUnlocalized);
TextWriterColor.Write($"Total unlocalized strings: {totalUnlocalized.Count}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($"Total unlocalized strings: {totalUnlocalized.Count}", true, totalUnlocalized.Count > 0 ? ConsoleColors.Red : ConsoleColors.Lime);
}
catch (Exception ex)
{
TextWriterColor.Write($"General analysis failure: {ex.Message}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($"General analysis failure: {ex.Message}", true, ConsoleColors.Red);
}
}

Expand All @@ -154,7 +154,7 @@ private static VisualStudioInstance SelectVisualStudioInstance(VisualStudioInsta
{
return visualStudioInstances[instanceNumber - 1];
}
TextWriterColor.Write("Input not accepted, try again.", true, ConsoleColors.Red);
TextWriterColor.WriteColor("Input not accepted, try again.", true, ConsoleColors.Red);
}
}

Expand Down

0 comments on commit dba6f4d

Please sign in to comment.