Skip to content

Commit

Permalink
imp - Refactored text writers
Browse files Browse the repository at this point in the history
---

We've refactored the base text writers.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Jan 16, 2025
1 parent 8256a4e commit b255bfc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 48 deletions.
50 changes: 22 additions & 28 deletions public/Nitrocid/ConsoleBase/Writers/TextWriters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,15 @@ public static void Write(string Text, bool Line, bool Highlight, KernelColorType
{
try
{
// Check if default console output equals the new console output text writer. If it does, write in color, else, suppress the colors.
KernelColorTools.SetConsoleColorDry(colorType, Highlight, false);
KernelColorTools.SetConsoleColorDry(KernelColorType.Background, !Highlight, false);
// Get the colors
var foreground = KernelColorTools.GetColor(colorType);
var background = KernelColorTools.GetColor(KernelColorType.Background);

// Write the text to console
if (Highlight)
{
TextWriterRaw.WritePlain(Text, false, vars);
KernelColorTools.SetConsoleColorDry(colorType);
KernelColorTools.SetConsoleColorDry(KernelColorType.Background, true);
TextWriterRaw.WritePlain("", Line);
}
TextWriterHighlightedColor.WriteColorBack(Text, Line, foreground, background, vars);
else
{
TextWriterRaw.WritePlain(Text, Line, vars);
}
TextWriterColor.WriteColorBack(Text, Line, foreground, background, vars);
}
catch (Exception ex) when (ex.GetType().Name != nameof(ThreadInterruptedException))
{
Expand Down Expand Up @@ -128,22 +121,15 @@ public static void Write(string Text, bool Line, bool Highlight, KernelColorType
{
try
{
// Check if default console output equals the new console output text writer. If it does, write in color, else, suppress the colors.
KernelColorTools.SetConsoleColorDry(colorTypeForeground, Highlight, false);
KernelColorTools.SetConsoleColorDry(colorTypeBackground, !Highlight, false);
// Get the colors
var foreground = KernelColorTools.GetColor(colorTypeForeground);
var background = KernelColorTools.GetColor(colorTypeBackground);

// Write the text to console
if (Highlight)
{
TextWriterRaw.WritePlain(Text, false, vars);
KernelColorTools.SetConsoleColorDry(colorTypeForeground);
KernelColorTools.SetConsoleColorDry(colorTypeBackground, true);
TextWriterRaw.WritePlain("", Line);
}
TextWriterHighlightedColor.WriteColorBack(Text, Line, foreground, background, vars);
else
{
TextWriterRaw.WritePlain(Text, Line, vars);
}
TextWriterColor.WriteColorBack(Text, Line, foreground, background, vars);
}
catch (Exception ex) when (ex.GetType().Name != nameof(ThreadInterruptedException))
{
Expand Down Expand Up @@ -192,8 +178,12 @@ public static void WriteWhere(string msg, int Left, int Top, bool Return, int Ri
{
try
{
// Write text in another place. By the way, we check the text for newlines and console width excess
ConsoleWrapper.Write(TextWriterWhereColor.RenderWhereColorBack(msg, Left, Top, Return, RightMargin, KernelColorTools.GetColor(colorType), KernelColorTools.GetColor(KernelColorType.Background), vars));
// Get the colors
var foreground = KernelColorTools.GetColor(colorType);
var background = KernelColorTools.GetColor(KernelColorType.Background);

// Write the text to console
TextWriterWhereColor.WriteWhereColorBack(msg, Left, Top, Return, RightMargin, foreground, background, vars);
}
catch (Exception ex) when (ex.GetType().Name != nameof(ThreadInterruptedException))
{
Expand Down Expand Up @@ -245,8 +235,12 @@ public static void WriteWhere(string msg, int Left, int Top, bool Return, int Ri
{
try
{
// Write text in another place. By the way, we check the text for newlines and console width excess
ConsoleWrapper.Write(TextWriterWhereColor.RenderWhereColorBack(msg, Left, Top, Return, RightMargin, KernelColorTools.GetColor(colorTypeForeground), KernelColorTools.GetColor(colorTypeBackground), vars));
// Get the colors
var foreground = KernelColorTools.GetColor(colorTypeForeground);
var background = KernelColorTools.GetColor(colorTypeBackground);

// Write the text to console
TextWriterWhereColor.WriteWhereColorBack(msg, Left, Top, Return, RightMargin, foreground, background, vars);
}
catch (Exception ex) when (ex.GetType().Name != nameof(ThreadInterruptedException))
{
Expand Down
20 changes: 0 additions & 20 deletions public/Nitrocid/Drivers/Console/BaseConsoleDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,6 @@
//

extern alias TextifyDep;
//
// Nitrocid KS Copyright (C) 2018-2025 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using System;
using System.IO;
using System.Threading;
Expand All @@ -45,7 +26,6 @@
using Terminaux.Sequences.Builder.Types;
using Nitrocid.Kernel;
using Nitrocid.Kernel.Debugging;
using Nitrocid.Languages;
using Terminaux.Writer.ConsoleWriters;
using Terminaux.Colors;
using System.Runtime.Serialization;
Expand Down

0 comments on commit b255bfc

Please sign in to comment.