-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (54 loc) · 2.14 KB
/
Copy pathProgram.cs
File metadata and controls
61 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Text;
using Spectre.Console;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RazorConsole.Core;
using Naptrack.Components;
using Naptrack.Services;
Console.OutputEncoding = Encoding.UTF8;
Console.InputEncoding = Encoding.UTF8;
ClearScreen();
IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args)
.UseRazorConsole<App>(configure: config =>
{
config.ConfigureServices(services =>
{
services.AddSingleton<ConfigService>();
services.AddSingleton<UpdateChecker>();
services.AddSingleton<BinaryDownloader>();
services.AddSingleton<DependencyChecker>();
services.AddSingleton<YtDlpUpdater>();
services.AddSingleton<YtDlpService>();
services.AddSingleton<FolderPickerService>();
services.AddSingleton<TextInputBufferSync>();
// Created here rather than left to the container: it has to register its console
// input proxy into this same collection before RazorConsole resolves the keyboard loop.
var inputLoop = new InputLoopScheduler();
services.AddSingleton(inputLoop);
inputLoop.Install(services);
});
});
IHost host = hostBuilder.Build();
await host.RunAsync();
// Naptrack paints a full-screen UI, so whatever the shell left on screen would otherwise sit
// behind and above it for the whole session.
static void ClearScreen()
{
try
{
Console.Clear();
// Console.Clear only wipes the visible window; the previous commands are still one
// scroll away. Dropping the scrollback needs an escape sequence, and a terminal that
// does not understand it would print the sequence literally instead of acting on it --
// so it is sent only where Spectre reports that ANSI is actually supported.
if (AnsiConsole.Profile.Capabilities.Ansi)
{
Console.Write("[3J");
}
}
catch (IOException)
{
// Output is redirected to a file or a pipe. There is no screen to clear, and failing to
// clear one is never a reason not to start.
}
}