Updated initial setup

This commit is contained in:
2023-04-01 16:14:04 +03:00
parent f2418d0395
commit d20cb62139
12 changed files with 338 additions and 135 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Numerics;
using PluginManager.Others;
using Discord;
@@ -118,6 +119,34 @@ namespace PluginManager
LogEvent?.Invoke(message);
Console.ForegroundColor = oldColor;
}
public static void SetConsoleColor(TextType type)
{
if(!isConsole) return;
switch (type)
{
case TextType.NORMAL:
Console.ForegroundColor = ConsoleColor.White;
break;
case TextType.ERROR:
Console.ForegroundColor = ConsoleColor.Red;
break;
case TextType.WARNING:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case TextType.SUCCESS:
Console.ForegroundColor = ConsoleColor.Green;
break;
default:
Console.ForegroundColor = ConsoleColor.White;
break;
}
}
public static void ResetConsoleColor()
{
if (!isConsole) return;
Console.ForegroundColor = ConsoleColor.White;
}
/// <summary>
/// Write logs to file

View File

@@ -59,4 +59,13 @@ public enum ProgressBarType
{
NORMAL,
NO_END
}
}
public enum TextType
{
NORMAL,
ERROR,
WARNING,
SUCCESS
}

View File

@@ -14,6 +14,5 @@
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.8.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.117" />
<PackageReference Include="Terminal.Gui" Version="1.8.2" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PluginManager.WindowManagement.Controls
{
public class ConsoleOption
{
public string Text { get; set; }
public byte Index { get; set; }
public Action Action { get; set; }
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PluginManager.Others;
namespace PluginManager.WindowManagement.Controls
{
public class Label
{
public string Text { get; set; }
public TextType Type { get; set; } = TextType.NORMAL;
public void Show()
{
Logger.SetConsoleColor(Type);
Console.WriteLine(Text);
Logger.ResetConsoleColor();
}
public void Show(int x, int y)
{
Logger.SetConsoleColor(Type);
Console.SetCursorPosition(x, y);
Console.WriteLine(Text);
Logger.ResetConsoleColor();
}
public void Show(int x, int y, ConsoleColor color)
{
Console.SetCursorPosition(x, y);
Console.ForegroundColor = color;
Console.WriteLine(Text);
Console.ResetColor();
}
public void Show(int x, int y, ConsoleColor color, ConsoleColor background)
{
Console.SetCursorPosition(x, y);
Console.ForegroundColor = color;
Console.BackgroundColor = background;
Console.WriteLine(Text);
Console.ResetColor();
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PluginManager.WindowManagement.Controls
{
public class TextBox
{
public Label Label { get; set; }
public string Text { get; private set; }
public Func<string, bool> IsValid { get; set; }
public bool SetText(string text)
{
if(IsValid(text))
{
Text = text;
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PluginManager.WindowManagement.Controls;
using PluginManager.Others;
namespace PluginManager.WindowManagement
{
public class InputBox
{
public string Title { get; set; }
public string Message { get; set; }
private List<TextBox> options = new List<TextBox>();
private List<Label> labels = new List<Label>();
private string InputStr = "=> ";
public List<string> Show()
{
List<string> result = new List<string>();
Console.Clear();
Console.WriteLine(Title);
Console.WriteLine(Message);
foreach (var label in labels)
label.Show();
foreach (var option in options)
{
option.Label.Show();
while (true)
{
Console.Write(InputStr);
if(option.SetText(Console.ReadLine()))
{
result.Add(option.Text);
break;
}
}
}
return result;
}
public void AddOption(string text, Func<string, bool> isValid)
{
options.Add(new TextBox() { Label = new Label() {Text = text}, IsValid = isValid });
}
public void AddLabel(string text, TextType type)
{
labels.Add(new Label() {Text = text, Type = type});
}
}
}

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PluginManager.WindowManagement.Controls;
namespace PluginManager.WindowManagement
{
public class MessageBox
{
public string Title { get; set; }
public string Message { get; set; }
private List<ConsoleOption> options = new List<ConsoleOption>();
public int OptionsCount {get => options.Count;}
public MessageBox(string title, string message)
{
Title = title;
Message = message;
}
public void AddOption(string text, Action action)
{
options.Add(new ConsoleOption() { Text = text, Index = (byte)(options.Count+1), Action = action});
}
public void AddRangeOptions(List<string> texts, List<Action> actions)
{
for (int i = 0; i < texts.Count; i++)
{
options.Add(new ConsoleOption() { Text = texts[i], Index = (byte)(options.Count + 1), Action = actions[i] });
}
}
public int Show()
{
Console.Clear();
Console.WriteLine(Title);
Console.WriteLine(Message);
foreach (var option in options)
{
Console.WriteLine($"{option.Index}. {option.Text}");
}
if(options.Count == 0)
{
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
return 0;
}
if(int.TryParse(Console.ReadLine(), out int result))
{
if(result > 0 && result <= options.Count)
{
if(options[result - 1].Action != null)
options[result - 1].Action();
return result;
}
}
return -1;
}
}
}