-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutput.cs
More file actions
137 lines (120 loc) · 5.14 KB
/
Output.cs
File metadata and controls
137 lines (120 loc) · 5.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Drawing;
using System.IO.Pipelines;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cli_bot
{
public static class Output
{
static LinkedList<string> consoleLines = new(new[] { "" });
private static readonly System.Threading.Lock _consoleLock = new();
public static ConsoleColor Background { get { return Console.BackgroundColor; } set { Console.BackgroundColor = value; } }
public static ConsoleColor Foreground { get { return Console.ForegroundColor; } set { Console.ForegroundColor = value; } }
public static void Draw(TwitterBot bot)
{
try
{
System.Threading.ThreadState state = bot._runThread != null ? bot._runThread.ThreadState : System.Threading.ThreadState.Unstarted;
if (state == System.Threading.ThreadState.Running)
Console.Clear();
string fancy = $"--------~ {bot.DisplayName} ~--------";
var what = Console.GetCursorPosition();
Console.SetCursorPosition(0, 0);
ClearLine();
CoutL(new string(' ', (Console.WindowWidth - fancy.Length) / 2) + fancy);
ClearLine();
CoutL();
if (bot._loginState < 3)
{
ClearLine();
CoutL($"LOGGING INTO {bot.DisplayName}{(bot.ticks % 3 == 0 ? "..." : "")}");
var elTime = DateTime.Now - bot._loginStart;
ClearLine();
CoutL($"Elapsed time {elTime.Minutes:D2}:{elTime.Seconds:D2}");
}
else if (state == System.Threading.ThreadState.Running)
{
ClearLine();
CoutL("\n\n~~~~RUNNING BOT~~~~");
var elTime = DateTime.Now - bot._runStart;
ClearLine();
CoutL($"Elapsed time {elTime.Minutes:D2}:{elTime.Seconds:D2}");
}
else
{
DateTime endTime = DateTime.Now.AddSeconds(bot.timer);
TimeSpan essentiallyACrashout = TimeSpan.FromSeconds(bot.timer);
//CoutL($"{bot.timer} {bot.interval} {bot.Progress}");
ClearLine();
CoutL($"Next Tweet - {endTime.TimeOfDay.Hours:D2}:{endTime.TimeOfDay.Minutes:D2}:{endTime.TimeOfDay.Seconds:D2}");
ClearLine();
CoutL($"{(essentiallyACrashout.Hours > 0 ? $"{essentiallyACrashout.Hours:D2}:" : "")}{essentiallyACrashout.Minutes:D2}:{essentiallyACrashout.Seconds:D2} [{new string('#', (int)Math.Min(Math.Max(0, bot.Progress * 20), 20))}{new string('-', (int)Math.Min(Math.Max(0, (1 - bot.Progress) * 20), 20))}] {bot.Progress * 100}%");
}
ClearLine();
CoutL();
ClearLine();
CoutL();
ClearLine();
CoutL("-------------------------------------");
lock (_consoleLock)
{
foreach (string line in consoleLines)
{
ClearLine();
if (Console.GetCursorPosition().Top + 3 > Console.WindowHeight)
break;
Cout(line.TrimEnd());
}
}
Console.Out.Flush();
}
catch
{
}
}
private static void ClearLine() => Cout(new string(' ', Console.WindowWidth-1) + "\r");
private static void Cout(string str) => Console.Out.Write(str);
private static void CoutL(string str = "") => Console.Out.WriteLine(str);
public static void WriteLine(string contents) => Write(contents + "\n");
public static void Write(string contents)
{
try
{
if (consoleLines == null)
{
Console.Write(contents);
return;
}
string[] lines = contents.Split('\n');
lock (_consoleLock)
{
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];
if (i != lines.Length - 1)
consoleLines.AddFirst(line.Substring(0, Math.Min(line.Length, Console.WindowWidth)));
else if (consoleLines.First != null)
consoleLines.First.Value += line;
}
if (consoleLines.Count > Console.WindowHeight - 2)
while (consoleLines.Count > Console.WindowHeight - 15) consoleLines.RemoveLast();
}
}
catch
{
try
{
Console.Write(contents);
}
catch
{
}
}
}
}
}