using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WIDESEAWCS_Core.Helper
{
public static class ConsoleHelper
{
private static readonly object _objLock = new();
///
/// 在控制台输出
///
/// 文本
/// 前颜色
public static void WriteColorLine(string str, ConsoleColor color)
{
lock (_objLock)
{
ConsoleColor currentForeColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(str);
Console.ForegroundColor = currentForeColor;
}
}
///
/// 在控制台输出
///
/// 文本
/// 前颜色
public static void WriteColorLine(object str, ConsoleColor color)
{
lock (_objLock)
{
ConsoleColor currentForeColor = Console.ForegroundColor;
Console.ForegroundColor = color;
Console.WriteLine(str);
Console.ForegroundColor = currentForeColor;
}
}
///
/// 打印错误信息
///
/// 待打印的字符串
/// 想要打印的颜色
public static void WriteErrorLine(this string str, ConsoleColor color = ConsoleColor.Red) => WriteColorLine(str, color);
///
/// 打印警告信息
///
/// 待打印的字符串
/// 想要打印的颜色
public static void WriteWarningLine(this string str, ConsoleColor color = ConsoleColor.Yellow) => WriteColorLine(str, color);
///
/// 打印正常信息
///
/// 待打印的字符串
/// 想要打印的颜色
public static void WriteInfoLine(this string str, ConsoleColor color = ConsoleColor.White) => WriteColorLine(str, color);
///
/// 打印成功的信息
///
/// 待打印的字符串
/// 想要打印的颜色
public static void WriteSuccessLine(this string str, ConsoleColor color = ConsoleColor.Green) => WriteColorLine(str, color);
}
}