-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditor.cs
73 lines (70 loc) · 3.42 KB
/
Editor.cs
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
using System;
namespace ziv
{
public class Editor
{
// A list of colors that are hard to see if the white text is in front of it
private static ConsoleColor[] LightColors = { ConsoleColor.White, ConsoleColor.DarkCyan,ConsoleColor.DarkYellow,ConsoleColor.Cyan,ConsoleColor.Yellow,ConsoleColor.Gray,ConsoleColor.Green,ConsoleColor.Blue,ConsoleColor.Magenta };
public static void Entry(string file)
{
Console.Clear();
ConsoleColor back = (ConsoleColor)Program.rng.Next(0,15); // Random color
//Console.WriteLine(back);
ConsoleColor fore = ConsoleColor.White;
if (LightColors.Contains(back))
{
fore = ConsoleColor.Black;
}
Bar(back, $"ziv - {file} - Type $-wq on 1 line to save and quit.", fore);
MainLoop(file);
}
public static void MainLoop(string file)
{
Console.Write(Program.buffer);
while (true)
{
string Buffer2 = Console.ReadLine();
if (Buffer2 == "$-wq") // Write, then quit
{
Console.Clear();
Console.WriteLine("Saving file to disk...");
File.WriteAllText(file,Program.buffer);
Console.WriteLine("I finished! Have a good day/night!");
Environment.Exit(0);
} else if (Buffer2 == "$-q") // quit
{
Console.Clear();
Environment.Exit(0);
}
else if (Buffer2 == "$-waq") // Write as, then quit
{
Console.Clear();
Console.Write("Where do you want to save this text? ");
string dest = Console.ReadLine();
Console.WriteLine("Saving file to disk...");
File.WriteAllText(dest,Program.buffer);
Console.WriteLine("I finished! Have a good day/night!");
Environment.Exit(0);
}
else
{
Program.buffer += $"{Buffer2}\n";
}
}
}
public static void Bar(ConsoleColor barcolor, string Ltext, ConsoleColor LtextColor)
{
ConsoleColor oldc = Console.BackgroundColor; // Make an archive of the old background color
Console.BackgroundColor = barcolor; // Change background color to desired one
Console.SetCursorPosition(0, Console.CursorTop); // Go the the beginning of the current console line
Console.Write(new string(' ', Console.BufferWidth)); // Draw a white space, as many times as it takes to fill the terminal.
Console.SetCursorPosition(0, Console.CursorTop-1); // Go back to the beginning of the line that we drew the white spaces in
ConsoleColor oldlc = Console.ForegroundColor; // Make an archive of the old foreground color
Console.ForegroundColor = LtextColor; // Change foreground color to desired one
Console.Write(Ltext); // Draw the bar text
Console.ForegroundColor = oldlc; // Restore foreground color
Console.BackgroundColor = oldc; // Restore background color
Console.SetCursorPosition(0, Console.CursorTop + 1); // Go to the beginning of the line after the line that we drew the white spaces in
}
}
}