110 lines
4.0 KiB
C#
110 lines
4.0 KiB
C#
using FileTime.App.Core.Clipboard;
|
|
using FileTime.ConsoleUI.App;
|
|
using FileTime.ConsoleUI.App.UI;
|
|
using FileTime.ConsoleUI.App.UI.Color;
|
|
using FileTime.Core.Command;
|
|
using FileTime.Core.Models;
|
|
using FileTime.Core.Providers;
|
|
using FileTime.Core.StateManagement;
|
|
using FileTime.Providers.Local;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace FileTime.ConsoleUI
|
|
{
|
|
public static class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
/* Console.Clear();
|
|
for (var x = 0; x < 16; x++)
|
|
{
|
|
for (var y = 0; y < 16; y++)
|
|
{
|
|
var i = x * 16 + y;
|
|
Console.Write("\u001b[48;5;{0}m{0,4}", i);
|
|
Console.ResetColor();
|
|
Console.Write(' ');
|
|
}
|
|
Console.WriteLine("\n");
|
|
}
|
|
return; */
|
|
|
|
/* var colors = new int[][]
|
|
{
|
|
new int[] {0,43,54},
|
|
new int[] {255,0,0},
|
|
new int[] {0,255,0},
|
|
new int[] {0,0,255},
|
|
};
|
|
|
|
foreach (var color in colors)
|
|
{
|
|
Console.Write($"\u001b[0m\u001b[48;2;{color[0]};{color[1]};{color[2]}mTESZT ");
|
|
Console.WriteLine($"\u001b[0m\u001b[38;2;{color[0]};{color[1]};{color[2]}mTESZT");
|
|
}
|
|
|
|
Console.WriteLine("\u001b[0m\u001b[48;5;0;38;5;14mASD");
|
|
return; */
|
|
|
|
var serviceProvider = CreateServiceProvider();
|
|
|
|
var coloredConsoleRenderer = serviceProvider.GetService<IColoredConsoleRenderer>()!;
|
|
var localContentProvider = serviceProvider.GetService<LocalContentProvider>()!;
|
|
|
|
var currentPossibleDirectory = localContentProvider.GetByPath(Environment.CurrentDirectory.Replace(Path.DirectorySeparatorChar, Constants.SeparatorChar));
|
|
|
|
if (currentPossibleDirectory is IContainer container)
|
|
{
|
|
coloredConsoleRenderer.Clear();
|
|
Console.CursorVisible = false;
|
|
|
|
var app = serviceProvider.GetService<Application>()!;
|
|
app.SetContainer(container);
|
|
app.PrintUI();
|
|
|
|
while (app.IsRunning)
|
|
{
|
|
if (app.ProcessKey(Console.ReadKey(true)))
|
|
{
|
|
app.PrintUI();
|
|
}
|
|
}
|
|
|
|
Console.SetCursorPosition(0, Console.WindowHeight - 1);
|
|
|
|
Console.CursorVisible = true;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Current working directory is not a directory???");
|
|
}
|
|
}
|
|
|
|
private static ServiceProvider CreateServiceProvider()
|
|
{
|
|
return new ServiceCollection()
|
|
.AddSingleton<Application>()
|
|
.AddSingleton<IStyles>(new Styles(true))
|
|
.AddSingleton<IColoredConsoleRenderer, ColoredConsoleRenderer>()
|
|
.AddSingleton<IClipboard, Clipboard>()
|
|
.AddSingleton<LocalContentProvider>()
|
|
.AddSingleton<IContentProvider, LocalContentProvider>(sp => sp.GetService<LocalContentProvider>() ?? throw new Exception($"No {nameof(LocalContentProvider)} instance found"))
|
|
.AddSingleton<ElementCreationStates>()
|
|
.AddSingleton<CommandExecutor>()
|
|
.AddSingleton<ConsoleReader>()
|
|
.AddTransient<Render>()
|
|
.RegisterCommandHandlers()
|
|
.BuildServiceProvider();
|
|
}
|
|
|
|
private static IServiceCollection RegisterCommandHandlers(this IServiceCollection serviceCollection)
|
|
{
|
|
foreach (var commandHandler in Startup.GetCommandHandlers())
|
|
{
|
|
serviceCollection.AddTransient(typeof(ICommandHandler), commandHandler);
|
|
}
|
|
|
|
return serviceCollection;
|
|
}
|
|
}
|
|
} |