From c4f20d272286fe259366b9354ba4b3376d548649 Mon Sep 17 00:00:00 2001 From: Aptivi Date: Sun, 10 Mar 2024 13:51:43 +0300 Subject: [PATCH] imp - Use ConsoleWrapper for adaptibility --- We need to better detect the dumb console, so we've converted all calls to System.Console to ConsoleWrapper as per guidance that Nitrocid analyzers provide. --- Type: imp Breaking: False Doc Required: False Part: 1/1 --- GRILO.Bootloader/Boot/Style/BaseBootStyle.cs | 14 +++++++------- .../Boot/Style/Styles/BootMgrBootStyle.cs | 16 ++++++++-------- .../Boot/Style/Styles/GrubBootStyle.cs | 5 +++-- .../Boot/Style/Styles/GrubLegacyBootStyle.cs | 5 +++-- .../Boot/Style/Styles/LiloBootStyle.cs | 5 +++-- .../Boot/Style/Styles/NtldrBootStyle.cs | 3 ++- .../Boot/Style/Styles/StandardBootStyle.cs | 4 ++-- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/GRILO.Bootloader/Boot/Style/BaseBootStyle.cs b/GRILO.Bootloader/Boot/Style/BaseBootStyle.cs index aa09355..96c9783 100644 --- a/GRILO.Bootloader/Boot/Style/BaseBootStyle.cs +++ b/GRILO.Bootloader/Boot/Style/BaseBootStyle.cs @@ -50,20 +50,20 @@ public virtual string Render() // Write the section title var builder = new StringBuilder(); string finalRenderedSection = "-- Select boot entry --"; - int halfX = Console.WindowWidth / 2 - finalRenderedSection.Length / 2; + int halfX = ConsoleWrapper.WindowWidth / 2 - finalRenderedSection.Length / 2; builder.Append( TextWriterWhereColor.RenderWhereColor(finalRenderedSection, halfX, 2, new Color(sectionTitle)) ); // Now, render a box builder.Append( - BorderColor.RenderBorder(2, 4, Console.WindowWidth - 6, Console.WindowHeight - 9, new Color(boxBorderColor)) + BorderColor.RenderBorder(2, 4, ConsoleWrapper.WindowWidth - 6, ConsoleWrapper.WindowHeight - 9, new Color(boxBorderColor)) ); // Offer help for new users string help = $"SHIFT + H for help. Version {Entry.griloVersion}"; builder.Append( - TextWriterWhereColor.RenderWhereColor(help, Console.WindowWidth - help.Length - 2, Console.WindowHeight - 2, new Color(ConsoleColor.White)) + TextWriterWhereColor.RenderWhereColor(help, ConsoleWrapper.WindowWidth - help.Length - 2, ConsoleWrapper.WindowHeight - 2, new Color(ConsoleColor.White)) ); return builder.ToString(); } @@ -80,7 +80,7 @@ public virtual string RenderHighlight(int chosenBootEntry) var builder = new StringBuilder(); var bootApps = BootManager.GetBootApps(); (int, int) upperLeftCornerInterior = (4, 6); - (int, int) lowerLeftCornerInterior = (4, Console.WindowHeight - 6); + (int, int) lowerLeftCornerInterior = (4, ConsoleWrapper.WindowHeight - 6); int maxItemsPerPage = lowerLeftCornerInterior.Item2 - upperLeftCornerInterior.Item2; int pages = (int)Math.Truncate(bootApps.Count / (double)maxItemsPerPage); int currentPage = (int)Math.Truncate(chosenBootEntry / (double)maxItemsPerPage); @@ -102,7 +102,7 @@ public virtual string RenderHighlight(int chosenBootEntry) // Populate page number string renderedNumber = $"[{chosenBootEntry + 1}/{bootApps.Count}]═[{currentPage + 1}/{pages}]"; - (int, int) lowerRightCornerToWrite = (Console.WindowWidth - renderedNumber.Length - 3, Console.WindowHeight - 4); + (int, int) lowerRightCornerToWrite = (ConsoleWrapper.WindowWidth - renderedNumber.Length - 3, ConsoleWrapper.WindowHeight - 4); builder.Append( TextWriterWhereColor.RenderWhereColor(renderedNumber, lowerRightCornerToWrite.Item1, lowerRightCornerToWrite.Item2, new Color(pageNumberColor)) ); @@ -139,13 +139,13 @@ public virtual string RenderBootFailedMessage(string content) => /// public virtual string RenderSelectTimeout(int timeout) => - TextWriterWhereColor.RenderWhereColor($"{timeout} ", 2, Console.WindowHeight - 2, true, new Color(ConsoleColor.White)); + TextWriterWhereColor.RenderWhereColor($"{timeout} ", 2, ConsoleWrapper.WindowHeight - 2, true, new Color(ConsoleColor.White)); /// public virtual string ClearSelectTimeout() { string spaces = new(' ', GetDigits(Config.Instance.BootSelectTimeoutSeconds)); - return TextWriterWhereColor.RenderWhereColor(spaces, 2, Console.WindowHeight - 2, true, new Color(ConsoleColor.White)); + return TextWriterWhereColor.RenderWhereColor(spaces, 2, ConsoleWrapper.WindowHeight - 2, true, new Color(ConsoleColor.White)); } internal static int GetDigits(int Number) => diff --git a/GRILO.Bootloader/Boot/Style/Styles/BootMgrBootStyle.cs b/GRILO.Bootloader/Boot/Style/Styles/BootMgrBootStyle.cs index 18551fa..83b8865 100644 --- a/GRILO.Bootloader/Boot/Style/Styles/BootMgrBootStyle.cs +++ b/GRILO.Bootloader/Boot/Style/Styles/BootMgrBootStyle.cs @@ -41,11 +41,11 @@ public override string Render() // Render the header and footer int marginX = 2; int headerY = 0; - int footerY = Console.WindowHeight - 1; - int barLength = Console.WindowWidth - 4; + int footerY = ConsoleWrapper.WindowHeight - 1; + int barLength = ConsoleWrapper.WindowWidth - 4; string header = "Windows Boot Manager"; string footer = "ENTER=Choose"; - int headerTextX = Console.WindowWidth / 2 - header.Length / 2; + int headerTextX = ConsoleWrapper.WindowWidth / 2 - header.Length / 2; var builder = new StringBuilder(); ConsoleColor barColor = ConsoleColor.Gray; ConsoleColor barForeground = ConsoleColor.Black; @@ -96,7 +96,7 @@ public override string RenderHighlight(int chosenBootEntry) var finalColorBg = i == chosenBootEntry ? selectedEntryBg : normalEntryBg; var finalColorFg = i == chosenBootEntry ? selectedEntryFg : normalEntryFg; builder.Append( - TextWriterWhereColor.RenderWhereColorBack(rendered + new string(' ', Console.WindowWidth - 15 - rendered.Length) + (i == chosenBootEntry ? '>' : ' '), 6, 5 + renderedAnswers, false, new Color(finalColorFg), new Color(finalColorBg)) + TextWriterWhereColor.RenderWhereColorBack(rendered + new string(' ', ConsoleWrapper.WindowWidth - 15 - rendered.Length) + (i == chosenBootEntry ? '>' : ' '), 6, 5 + renderedAnswers, false, new Color(finalColorFg), new Color(finalColorBg)) ); renderedAnswers++; } @@ -108,11 +108,11 @@ public override string RenderBootFailedMessage(string content) // Render the header and footer int marginX = 2; int headerY = 0; - int footerY = Console.WindowHeight - 1; - int barLength = Console.WindowWidth - 4; + int footerY = ConsoleWrapper.WindowHeight - 1; + int barLength = ConsoleWrapper.WindowWidth - 4; string header = "Windows Boot Manager"; string footer = "ENTER=Continue"; - int headerTextX = Console.WindowWidth / 2 - header.Length / 2; + int headerTextX = ConsoleWrapper.WindowWidth / 2 - header.Length / 2; var builder = new StringBuilder(); ConsoleColor barColor = ConsoleColor.Gray; ConsoleColor barForeground = ConsoleColor.Black; @@ -165,7 +165,7 @@ public override string ClearSelectTimeout() int timeoutY = 13; ConsoleColor hintColor = ConsoleColor.Gray; builder.Append( - TextWriterWhereColor.RenderWhereColor(new string(' ', Console.WindowWidth - 2), marginX, timeoutY, true, new Color(hintColor)) + TextWriterWhereColor.RenderWhereColor(new string(' ', ConsoleWrapper.WindowWidth - 2), marginX, timeoutY, true, new Color(hintColor)) ); return builder.ToString(); } diff --git a/GRILO.Bootloader/Boot/Style/Styles/GrubBootStyle.cs b/GRILO.Bootloader/Boot/Style/Styles/GrubBootStyle.cs index 9879be5..556ce07 100644 --- a/GRILO.Bootloader/Boot/Style/Styles/GrubBootStyle.cs +++ b/GRILO.Bootloader/Boot/Style/Styles/GrubBootStyle.cs @@ -26,6 +26,7 @@ using Terminaux.Colors; using Terminaux.Writer.ConsoleWriters; using Terminaux.Writer.FancyWriters; +using Terminaux.Base; namespace GRILO.Bootloader.Boot.Style.Styles { @@ -42,14 +43,14 @@ public override string Render() // Write the section title string finalRenderedSection = "GNU GRUB version 2.06"; - int halfX = Console.WindowWidth / 2 - finalRenderedSection.Length / 2; + int halfX = ConsoleWrapper.WindowWidth / 2 - finalRenderedSection.Length / 2; builder.Append( TextWriterWhereColor.RenderWhereColor(finalRenderedSection, halfX, 2, new Color(sectionTitle)) ); // Now, render a box builder.Append( - BorderColor.RenderBorder(2, 4, Console.WindowWidth - 6, Console.WindowHeight - 15, new Color(boxBorderColor)) + BorderColor.RenderBorder(2, 4, ConsoleWrapper.WindowWidth - 6, Console.WindowHeight - 15, new Color(boxBorderColor)) ); // Offer help for new users diff --git a/GRILO.Bootloader/Boot/Style/Styles/GrubLegacyBootStyle.cs b/GRILO.Bootloader/Boot/Style/Styles/GrubLegacyBootStyle.cs index 5d267df..42c6631 100644 --- a/GRILO.Bootloader/Boot/Style/Styles/GrubLegacyBootStyle.cs +++ b/GRILO.Bootloader/Boot/Style/Styles/GrubLegacyBootStyle.cs @@ -26,6 +26,7 @@ using Terminaux.Colors; using Terminaux.Writer.ConsoleWriters; using Terminaux.Writer.FancyWriters; +using Terminaux.Base; namespace GRILO.Bootloader.Boot.Style.Styles { @@ -42,14 +43,14 @@ public override string Render() // Write the section title string finalRenderedSection = "GNU GRUB version 0.97 (638K lower / 1046784K upper memory)"; - int halfX = Console.WindowWidth / 2 - finalRenderedSection.Length / 2; + int halfX = ConsoleWrapper.WindowWidth / 2 - finalRenderedSection.Length / 2; builder.Append( TextWriterWhereColor.RenderWhereColor(finalRenderedSection, halfX, 2, new Color(sectionTitle)) ); // Now, render a box builder.Append( - BorderColor.RenderBorder(2, 4, Console.WindowWidth - 6, Console.WindowHeight - 15, new Color(boxBorderColor)) + BorderColor.RenderBorder(2, 4, ConsoleWrapper.WindowWidth - 6, Console.WindowHeight - 15, new Color(boxBorderColor)) ); // Offer help for new users diff --git a/GRILO.Bootloader/Boot/Style/Styles/LiloBootStyle.cs b/GRILO.Bootloader/Boot/Style/Styles/LiloBootStyle.cs index 4eb1c59..40e91c5 100644 --- a/GRILO.Bootloader/Boot/Style/Styles/LiloBootStyle.cs +++ b/GRILO.Bootloader/Boot/Style/Styles/LiloBootStyle.cs @@ -25,6 +25,7 @@ using Terminaux.Colors; using Terminaux.Writer.ConsoleWriters; using Terminaux.Writer.FancyWriters; +using Terminaux.Base; namespace GRILO.Bootloader.Boot.Style.Styles { @@ -45,8 +46,8 @@ public override string Render() int interiorWidth = 41; int interiorHeight = 12; int bootPrompt = 16; - int halfX = Console.WindowWidth / 2 - (interiorWidth + 2) / 2; - int extraStartX = Console.WindowWidth / 2 - (interiorWidth + 4) / 2; + int halfX = ConsoleWrapper.WindowWidth / 2 - (interiorWidth + 2) / 2; + int extraStartX = ConsoleWrapper.WindowWidth / 2 - (interiorWidth + 4) / 2; int extraEndX = Console.WindowWidth / 2 + (interiorWidth + 4) / 2; int startY = 1; int endY = bootPrompt + startY - 2; diff --git a/GRILO.Bootloader/Boot/Style/Styles/NtldrBootStyle.cs b/GRILO.Bootloader/Boot/Style/Styles/NtldrBootStyle.cs index a89e8e9..6c2d6b2 100644 --- a/GRILO.Bootloader/Boot/Style/Styles/NtldrBootStyle.cs +++ b/GRILO.Bootloader/Boot/Style/Styles/NtldrBootStyle.cs @@ -25,6 +25,7 @@ using Terminaux.Colors; using Terminaux.Inputs; using Terminaux.Writer.ConsoleWriters; +using Terminaux.Base; namespace GRILO.Bootloader.Boot.Style.Styles { @@ -115,7 +116,7 @@ public override string ClearSelectTimeout() bootEntryPositions[bootEntryPositions.Count - 1].Item2 + 9 : 17; ConsoleColor hintColor = ConsoleColor.Gray; - return TextWriterWhereColor.RenderWhereColor(new string(' ', Console.WindowWidth - 2), marginX, timeoutY, true, new Color(hintColor)); + return TextWriterWhereColor.RenderWhereColor(new string(' ', ConsoleWrapper.WindowWidth - 2), marginX, timeoutY, true, new Color(hintColor)); } private string ShowBootFailure(int choiceNum) diff --git a/GRILO.Bootloader/Boot/Style/Styles/StandardBootStyle.cs b/GRILO.Bootloader/Boot/Style/Styles/StandardBootStyle.cs index b66ec82..e8a052f 100644 --- a/GRILO.Bootloader/Boot/Style/Styles/StandardBootStyle.cs +++ b/GRILO.Bootloader/Boot/Style/Styles/StandardBootStyle.cs @@ -72,12 +72,12 @@ public override string RenderBootFailedMessage(string content) => RenderModalDialog(content); public override string RenderSelectTimeout(int timeout) => - TextWriterWhereColor.RenderWhereColor($" {timeout}", Console.WindowWidth - $" {timeout}".Length - 2, Console.WindowHeight - 2, true, new Color(ConsoleColor.White)); + TextWriterWhereColor.RenderWhereColor($" {timeout}", ConsoleWrapper.WindowWidth - $" {timeout}".Length - 2, ConsoleWrapper.WindowHeight - 2, true, new Color(ConsoleColor.White)); public override string ClearSelectTimeout() { string spaces = new(' ', GetDigits(Config.Instance.BootSelectTimeoutSeconds)); - return TextWriterWhereColor.RenderWhereColor(spaces, Console.WindowWidth - spaces.Length - 2, Console.WindowHeight - 2, true, new Color(ConsoleColor.White)); + return TextWriterWhereColor.RenderWhereColor(spaces, ConsoleWrapper.WindowWidth - spaces.Length - 2, ConsoleWrapper.WindowHeight - 2, true, new Color(ConsoleColor.White)); } } }