small changes in ColoredConsole

This commit is contained in:
Timerix 2025-04-06 13:50:42 +05:00
parent c461418185
commit 26c118195c
2 changed files with 14 additions and 27 deletions

View File

@ -14,6 +14,9 @@ public static class ColoredConsole
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ResetColor() => System.Console.ResetColor();
/// <summary>
/// Clears console buffer and resets color
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clear()
{
@ -21,26 +24,15 @@ public static class ColoredConsole
System.Console.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Write(char c) => System.Console.Write(c);
public static void Write(string msg, ConsoleColor? fg = null, ConsoleColor? bg = null)
{
if(fg != null) Fg(fg.Value);
if(bg != null) Bg(bg.Value);
#if NETSTANDARD2_0
var chars = msg.ToCharArray();
#else
var chars = msg.AsSpan();
#endif
for (int i = 0; i < chars.Length; ++i)
{
Write(chars[i]);
}
System.Console.Write(msg);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteLine() => Write('\n');
public static void WriteLine() => System.Console.Write('\n');
public static void WriteLine(string msg, ConsoleColor? fg = null, ConsoleColor? bg = null)
{
@ -48,19 +40,16 @@ public static class ColoredConsole
WriteLine();
}
public static string? ReadLine(string query, ConsoleColor? fg = null, ConsoleColor? bg = null)
public static string ReadLine(ConsoleColor? fg = null, ConsoleColor? bg = null)
{
Write(query, fg, bg);
Write(':');
Write(' ');
return System.Console.ReadLine();
if(fg != null) Fg(fg.Value);
if(bg != null) Bg(bg.Value);
return System.Console.ReadLine() ?? string.Empty;
}
public static void WriteHLine(char c, ConsoleColor? fg = null, ConsoleColor? bg = null)
{
public static void WriteHLine(char c, ConsoleColor? fg = null, ConsoleColor? bg = null) =>
WriteLine(c.Multiply(Width - 1), fg, bg);
}
public static void WriteTitle(string title, char spacing = '-',
string left_framing = "[", string right_framing = "]",
ConsoleColor? fg = null, ConsoleColor? bg = null)
@ -82,8 +71,6 @@ public static class ColoredConsole
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteCentred(string title, ConsoleColor? fg = null, ConsoleColor? bg = null)
{
WriteTitle(title, ' ', "", "", fg, bg);
}
public static void WriteCentred(string title, ConsoleColor? fg = null, ConsoleColor? bg = null)
=> WriteTitle(title, ' ', "", "", fg, bg);
}

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<!--package info-->
<PackageId>DTLib</PackageId>
<Version>1.6.5</Version>
<Version>1.7.0</Version>
<Authors>Timerix</Authors>
<Description>Library for all my C# projects</Description>
<RepositoryType>GIT</RepositoryType>