-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIV.cs
319 lines (285 loc) · 11 KB
/
MIV.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace FalloutOS
{
class MIV
{
public static void printMIVStartScreen()
{
Console.Clear();
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~ MIV - MInimalistic Vi");
Console.WriteLine("~");
Console.WriteLine("~ version 1.2");
Console.WriteLine("~ by Denis Bartashevich");
Console.WriteLine("~ Minor additions by CaveSponge");
Console.WriteLine("~ MIV is open source and freely distributable");
Console.WriteLine("~");
Console.WriteLine("~ type :help<Enter> for information");
Console.WriteLine("~ type :q<Enter> to exit");
Console.WriteLine("~ type :wq<Enter> save to file and exit");
Console.WriteLine("~ press i to write");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.WriteLine("~");
Console.Write("~");
}
public static String stringCopy(String value)
{
String newString = String.Empty;
for (int i = 0; i < value.Length - 1; i++)
{
newString += value[i];
}
return newString;
}
public static void printMIVScreen(char[] chars, int pos, String infoBar, Boolean editMode)
{
int countNewLine = 0;
int countChars = 0;
delay(10000000);
Console.Clear();
for (int i = 0; i < pos; i++)
{
if (chars[i] == '\n')
{
Console.WriteLine("");
countNewLine++;
countChars = 0;
}
else
{
Console.Write(chars[i]);
countChars++;
if (countChars % 80 == 79)
{
countNewLine++;
}
}
}
Console.Write("/");
for (int i = 0; i < 23 - countNewLine; i++)
{
Console.WriteLine("");
Console.Write("~");
}
//PRINT INSTRUCTION
Console.WriteLine();
for (int i = 0; i < 72; i++)
{
if (i < infoBar.Length)
{
Console.Write(infoBar[i]);
}
else
{
Console.Write(" ");
}
}
if (editMode)
{
Console.Write(countNewLine + 1 + "," + countChars);
}
}
public static String miv(String start)
{
Boolean editMode = false;
int pos = 0;
char[] chars = new char[2000];
String infoBar = String.Empty;
if (start == null)
{
printMIVStartScreen();
}
else
{
pos = start.Length;
for (int i = 0; i < start.Length; i++)
{
chars[i] = start[i];
}
printMIVScreen(chars, pos, infoBar, editMode);
}
ConsoleKeyInfo keyInfo;
do
{
keyInfo = Console.ReadKey(true);
if (isForbiddenKey(keyInfo.Key)) continue;
else if (!editMode && keyInfo.KeyChar == ':')
{
infoBar = ":";
printMIVScreen(chars, pos, infoBar, editMode);
do
{
keyInfo = Console.ReadKey(true);
if (keyInfo.Key == ConsoleKey.Enter)
{
if (infoBar == ":wq")
{
String returnString = String.Empty;
for (int i = 0; i < pos; i++)
{
returnString += chars[i];
}
return returnString;
}
else if (infoBar == ":q")
{
return null;
}
else if (infoBar == ":help")
{
printMIVStartScreen();
break;
}
else
{
infoBar = "ERROR: No such command";
printMIVScreen(chars, pos, infoBar, editMode);
break;
}
}
else if (keyInfo.Key == ConsoleKey.Backspace)
{
infoBar = stringCopy(infoBar);
printMIVScreen(chars, pos, infoBar, editMode);
}
else if (keyInfo.KeyChar == 'q')
{
infoBar += "q";
}
else if (keyInfo.KeyChar == ':')
{
infoBar += ":";
}
else if (keyInfo.KeyChar == 'w')
{
infoBar += "w";
}
else if (keyInfo.KeyChar == 'h')
{
infoBar += "h";
}
else if (keyInfo.KeyChar == 'e')
{
infoBar += "e";
}
else if (keyInfo.KeyChar == 'l')
{
infoBar += "l";
}
else if (keyInfo.KeyChar == 'p')
{
infoBar += "p";
}
else
{
continue;
}
printMIVScreen(chars, pos, infoBar, editMode);
} while (keyInfo.Key != ConsoleKey.Escape);
}
else if (keyInfo.Key == ConsoleKey.Escape)
{
editMode = false;
infoBar = String.Empty;
printMIVScreen(chars, pos, infoBar, editMode);
continue;
}
else if (keyInfo.Key == ConsoleKey.I && !editMode)
{
editMode = true;
infoBar = "-- INSERT --";
printMIVScreen(chars, pos, infoBar, editMode);
continue;
}
else if (keyInfo.Key == ConsoleKey.Enter && editMode && pos >= 0)
{
chars[pos++] = '\n';
printMIVScreen(chars, pos, infoBar, editMode);
continue;
}
else if (keyInfo.Key == ConsoleKey.Backspace && editMode && pos >= 0)
{
if (pos > 0) pos--;
chars[pos] = '\0';
printMIVScreen(chars, pos, infoBar, editMode);
continue;
}
if (editMode && pos >= 0)
{
chars[pos++] = keyInfo.KeyChar;
printMIVScreen(chars, pos, infoBar, editMode);
}
} while (true);
}
public static bool isForbiddenKey(ConsoleKey key)
{
ConsoleKey[] forbiddenKeys = { ConsoleKey.Print, ConsoleKey.PrintScreen, ConsoleKey.Pause, ConsoleKey.Home, ConsoleKey.PageUp, ConsoleKey.PageDown, ConsoleKey.End, ConsoleKey.NumPad0, ConsoleKey.NumPad1, ConsoleKey.NumPad2, ConsoleKey.NumPad3, ConsoleKey.NumPad4, ConsoleKey.NumPad5, ConsoleKey.NumPad6, ConsoleKey.NumPad7, ConsoleKey.NumPad8, ConsoleKey.NumPad9, ConsoleKey.Insert, ConsoleKey.F1, ConsoleKey.F2, ConsoleKey.F3, ConsoleKey.F4, ConsoleKey.F5, ConsoleKey.F6, ConsoleKey.F7, ConsoleKey.F8, ConsoleKey.F9, ConsoleKey.F10, ConsoleKey.F11, ConsoleKey.F12, ConsoleKey.Add, ConsoleKey.Divide, ConsoleKey.Multiply, ConsoleKey.Subtract, ConsoleKey.LeftWindows, ConsoleKey.RightWindows };
for (int i = 0; i < forbiddenKeys.Length; i++)
{
if (key == forbiddenKeys[i]) return true;
}
return false;
}
public static void delay(int time)
{
for (int i = 0; i < time; i++) ;
}
public static void StartMIV()
{
Console.WriteLine("Enter file's filename to open:");
Console.WriteLine("If the specified file does not exist, it will be created.");
Kernel.file = Console.ReadLine();
string fullPath = Path.Combine(Directory.GetCurrentDirectory(), Kernel.file);
try
{
if (File.Exists(fullPath))
{
Console.WriteLine("Found file!");
}
else if (!File.Exists(fullPath))
{
Console.WriteLine("Creating file!");
File.Create(fullPath);
}
Console.Clear();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
String text = String.Empty;
Console.WriteLine("Do you want to open " + Kernel.file + " content? (Yes/No)");
if (Console.ReadLine().ToLower() == "yes" || Console.ReadLine().ToLower() == "y")
{
text = miv(File.ReadAllText(fullPath));
}
else
{
text = miv(null);
}
Console.Clear();
if (text != null)
{
File.WriteAllText(fullPath, text);
Console.WriteLine("Content has been saved to " + Kernel.file);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
}
}