Compare commits
No commits in common. "613b11e88cd79832d07838cdbc0259ae07cdb389" and "826c11aa55da3194c1a42e6c7a9c2f7f2774be9f" have entirely different histories.
613b11e88c
...
826c11aa55
@ -1,89 +1,86 @@
|
||||
namespace DTLib.Console;
|
||||
|
||||
//
|
||||
// вывод и ввод цветного текста в консоли
|
||||
// работает медленнее чем хотелось бы
|
||||
//
|
||||
public static class ColoredConsole
|
||||
{
|
||||
public static int Width => System.Console.WindowWidth;
|
||||
public static int Height => System.Console.WindowHeight;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Fg(ConsoleColor color) => System.Console.ForegroundColor = color;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Bg(ConsoleColor color) => System.Console.BackgroundColor = color;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ResetColor() => System.Console.ResetColor();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Clear()
|
||||
// парсит название цвета в ConsoleColor
|
||||
public static ConsoleColor ParseColor(string color) => color switch
|
||||
{
|
||||
ResetColor();
|
||||
System.Console.Clear();
|
||||
//case "magneta":
|
||||
"m" => ConsoleColor.Magenta,
|
||||
//case "green":
|
||||
"g" => ConsoleColor.Green,
|
||||
//case "red":
|
||||
"r" => ConsoleColor.Red,
|
||||
//case "yellow":
|
||||
"y" => ConsoleColor.Yellow,
|
||||
//case "white":
|
||||
"w" => ConsoleColor.White,
|
||||
//case "blue":
|
||||
"b" => ConsoleColor.Blue,
|
||||
//case "cyan":
|
||||
"c" => ConsoleColor.Cyan,
|
||||
//case "h":
|
||||
"h" or "gray" => ConsoleColor.Gray,
|
||||
//case "black":
|
||||
"black" => ConsoleColor.Black,
|
||||
_ => throw new Exception($"ColoredConsole.ParseColor({color}) error: incorrect color"),
|
||||
};
|
||||
|
||||
public static void Write(ConsoleColor color,string msg)
|
||||
{
|
||||
System.Console.ForegroundColor = color;
|
||||
System.Console.Write(msg);
|
||||
System.Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Write(char c) => System.Console.Write(c);
|
||||
public static void Write(string msg) => Write(ConsoleColor.Gray, msg);
|
||||
|
||||
public static void Write(string msg, ConsoleColor? fg = null, ConsoleColor? bg = null)
|
||||
// вывод цветного текста
|
||||
public static void Write(params string[] input)
|
||||
{
|
||||
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)
|
||||
if (input.Length == 1)
|
||||
{
|
||||
Write(chars[i]);
|
||||
}
|
||||
Write(input[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteLine() => Write('\n');
|
||||
if (input.Length % 2 != 0)
|
||||
throw new Exception("ColoredConsole.Write() error: every text string must have color string before");
|
||||
|
||||
public static void WriteLine(string msg, ConsoleColor? fg = null, ConsoleColor? bg = null)
|
||||
for (ushort i = 0; i < input.Length; i++)
|
||||
{
|
||||
Write(msg, fg, bg);
|
||||
System.Console.ForegroundColor = ParseColor(input[i++]);
|
||||
System.Console.Write(input[i]);
|
||||
}
|
||||
System.Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
||||
public static void WriteLine() => System.Console.WriteLine();
|
||||
public static void WriteLine(ConsoleColor color,string msg)
|
||||
{
|
||||
System.Console.ForegroundColor = color;
|
||||
System.Console.WriteLine(msg);
|
||||
System.Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
||||
public static void WriteLine(params string[] input)
|
||||
{
|
||||
Write(input);
|
||||
WriteLine();
|
||||
}
|
||||
|
||||
public static string? ReadLine(string query, ConsoleColor? fg = null, ConsoleColor? bg = null)
|
||||
// ввод цветного текста
|
||||
public static string? Read(ConsoleColor color)
|
||||
{
|
||||
Write(query, fg, bg);
|
||||
Write(':');
|
||||
Write(' ');
|
||||
return System.Console.ReadLine();
|
||||
System.Console.ForegroundColor = color;
|
||||
var r = System.Console.ReadLine();
|
||||
System.Console.ForegroundColor = ConsoleColor.Gray;
|
||||
return r;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int both_spacing_length = Width - title.Length - left_framing.Length - right_framing.Length - 1;
|
||||
int left_spacing_length = both_spacing_length / 2;
|
||||
int right_spacing_length = left_spacing_length + both_spacing_length % 2;
|
||||
|
||||
var b = new StringBuilder();
|
||||
if(left_spacing_length > 0)
|
||||
b.Append(spacing.Multiply(left_spacing_length));
|
||||
b.Append(left_framing);
|
||||
b.Append(title);
|
||||
b.Append(right_framing);
|
||||
if(right_spacing_length > 0)
|
||||
b.Append(spacing.Multiply(right_spacing_length));
|
||||
|
||||
WriteLine(b.ToString(), fg, bg);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteCentred(string title, ConsoleColor? fg = null, ConsoleColor? bg = null)
|
||||
{
|
||||
WriteTitle(title, ' ', "", "", fg, bg);
|
||||
}
|
||||
public static string? Read(string color) => Read(ParseColor(color));
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<!--package info-->
|
||||
<PackageId>DTLib</PackageId>
|
||||
<Version>1.6.0</Version>
|
||||
<Version>1.4.3</Version>
|
||||
<Authors>Timerix</Authors>
|
||||
<Description>Library for all my C# projects</Description>
|
||||
<RepositoryType>GIT</RepositoryType>
|
||||
|
||||
@ -27,7 +27,7 @@ public class ConsoleLogger : ILogger
|
||||
|
||||
var msg = format.CreateMessage(context, severity, message);
|
||||
lock (consolelocker)
|
||||
ColoredConsole.WriteLine(msg, fg: ColorFromSeverity(severity));
|
||||
ColoredConsole.WriteLine(ColorFromSeverity(severity),msg);
|
||||
}
|
||||
|
||||
private static ConsoleColor ColorFromSeverity(LogSeverity severity)
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
namespace DTLib.Logging;
|
||||
using DTLib.Logging;
|
||||
|
||||
public interface ILineWriter : IDisposable
|
||||
namespace launcher_client;
|
||||
|
||||
public interface IConsoleWrapper : IDisposable
|
||||
{
|
||||
public void WriteLine(string msg);
|
||||
}
|
||||
|
||||
public class LineWriterLogger : ILogger
|
||||
public class ConsoleWrapperLogger : ILogger
|
||||
{
|
||||
public bool DebugLogEnabled { get; set; } = false;
|
||||
public bool InfoLogEnabled { get; set; } = true;
|
||||
@ -13,16 +15,16 @@ public class LineWriterLogger : ILogger
|
||||
public bool ErrorLogEnabled { get; set; } = true;
|
||||
public ILogFormat Format { get; set; }
|
||||
|
||||
private readonly ILineWriter _lineWriter;
|
||||
private readonly IConsoleWrapper _consoleWrapper;
|
||||
|
||||
public LineWriterLogger(ILineWriter lineWriter, ILogFormat format)
|
||||
public ConsoleWrapperLogger(IConsoleWrapper consoleWrapper, ILogFormat format)
|
||||
{
|
||||
_lineWriter = lineWriter;
|
||||
_consoleWrapper = consoleWrapper;
|
||||
Format = format;
|
||||
}
|
||||
|
||||
public LineWriterLogger(ILineWriter lineWriter)
|
||||
: this(lineWriter, new DefaultLogFormat())
|
||||
public ConsoleWrapperLogger(IConsoleWrapper consoleWrapper)
|
||||
: this(consoleWrapper, new DefaultLogFormat())
|
||||
{}
|
||||
|
||||
public void Log(string context, LogSeverity severity, object message, ILogFormat format)
|
||||
@ -31,14 +33,14 @@ public class LineWriterLogger : ILogger
|
||||
return;
|
||||
|
||||
var msg = format.CreateMessage(context, severity, message);
|
||||
lock (_lineWriter)
|
||||
_lineWriter.WriteLine(msg);
|
||||
lock (_consoleWrapper)
|
||||
_consoleWrapper.WriteLine(msg);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_lineWriter.Dispose();
|
||||
_consoleWrapper.Dispose();
|
||||
}
|
||||
|
||||
~LineWriterLogger() => Dispose();
|
||||
~ConsoleWrapperLogger() => Dispose();
|
||||
}
|
||||
24
pack.sh
24
pack.sh
@ -1,10 +1,17 @@
|
||||
#!/usr/bin/bash
|
||||
set -eo pipefail
|
||||
|
||||
rm -rf nuget
|
||||
if [[ -d nuget ]]; then
|
||||
echo "archiving old ./nuget/ content"
|
||||
mkdir -p nuget_old
|
||||
TIMESTAMP=$(date +%Y.%m.%d_%H-%M-%S)
|
||||
mv nuget "nuget_$TIMESTAMP"
|
||||
tar cvf "nuget_old/nuget_$TIMESTAMP.tar" "nuget_$TIMESTAMP"
|
||||
rm -rf "nuget_$TIMESTAMP"
|
||||
fi
|
||||
mkdir nuget
|
||||
|
||||
function build_package() {
|
||||
function create_package() {
|
||||
echo "----------[$1]----------"
|
||||
cd "$1" || return 1
|
||||
dotnet pack -c Release -o bin/pack_tmp || return 1
|
||||
@ -14,12 +21,9 @@ function build_package() {
|
||||
cd ..
|
||||
}
|
||||
|
||||
packages_to_build="$@"
|
||||
if [ -z "$packages_to_build" ]; then
|
||||
packages_to_build='DTLib.Demystifier DTLib.XXHash DTLib DTLib.Logging.Microsoft'
|
||||
fi
|
||||
echo "building packages $packages_to_build"
|
||||
for p in $packages_to_build; do
|
||||
build_package "$p"
|
||||
done
|
||||
echo "building packages"
|
||||
create_package DTLib.Demystifier
|
||||
create_package DTLib.XXHash
|
||||
create_package DTLib
|
||||
create_package DTLib.Logging.Microsoft
|
||||
ls -shk nuget
|
||||
|
||||
Loading…
Reference in New Issue
Block a user