cosmosOS中的文本编辑器



我正在制作一个os与Cosmos和工作在一个文本编辑器我从LiquidEditor复制了代码,但它似乎不能很好地工作,所以我试图实现一个小的行系统,但它给了我一个错误:Enum.ToString() is not implemented.

内核代码:

using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using Filesystem = Cosmos.System.FileSystem.CosmosVFS;
using VFSFilesystem = Cosmos.System.FileSystem.VFS.VFSManager;
namespace LDCM
{
public class Kernel : Sys.Kernel
{
Filesystem filesystem = new Filesystem();
protected override void BeforeRun()
{
Console.Clear();
VFSFilesystem.RegisterVFS(filesystem, false);
}
protected override void Run()
{
LiquidEditor.Start(@"0:");
Console.WriteLine(System.IO.File.ReadAllText(@"0:.txt"));
Console.ReadKey(true);
}
}
}

LiquidEditor代码:

using System;
using System.Collections.Generic;
using System.Text;
namespace LDCM
{
public class LiquidEditor
{
public static String version = "0.2";
public static Char[] line = new Char[80]; public static int pointer = 0;
public static List<String> lines = new List<String>();
public static String[] final;
public static void Start(String currentdirectory)
{
Console.Clear();
Utils.WriteTextCentered("Liquid Editor by TheCool1James & valentinbreiz");
Utils.WriteTextCentered("Version " + version);
Console.Write("Filename: ");
String filename = Console.ReadLine();
Start(filename, currentdirectory);
}
public static void Start(String filename, String currentdirectory)
{
if (System.IO.File.Exists(currentdirectory + filename))
{
Console.Clear();
drawTopBar();
Console.SetCursorPosition(0, 1);
ConsoleKeyInfo c; cleanArray(line);
List<String> text = new List<String>();
text.Add(System.IO.File.ReadAllText(currentdirectory + filename));
String file = "";
foreach (String value in text)
{
file = file + value;
}
Console.Write(file);
while ((c = Console.ReadKey(true)) != null)
{
drawTopBar();
Char ch = c.KeyChar;
if (c.Key == ConsoleKey.Escape)
break;
else if (c.Key == ConsoleKey.F1)
{
Console.Clear();
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Black;
Utils.WriteTextCentered("Liquid Editor by TheCool1James & valentinbreiz");
Utils.WriteTextCentered("Version " + version);
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
lines.Add(new String(line).TrimEnd());
final = lines.ToArray();
String foo = Utils.ConcatString(final);
System.IO.File.Create(currentdirectory + filename);
System.IO.File.WriteAllText(currentdirectory + filename, file + foo);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("'" + filename + "' has been saved in '" + currentdirectory + "' !");
Console.ForegroundColor = ConsoleColor.White;
Console.ReadKey();
break;
}
else if (c.Key == ConsoleKey.F2)
{
Start(currentdirectory);
break;
}
switch (c.Key)
{
case ConsoleKey.Home: break;
case ConsoleKey.PageUp: break;
case ConsoleKey.PageDown: break;
case ConsoleKey.End: break;
case ConsoleKey.UpArrow:
if (Console.CursorTop > 1)
{
Console.CursorTop = Console.CursorTop - 1;
}
break;
case ConsoleKey.DownArrow:
if (Console.CursorTop < 24)
{
Console.CursorTop = Console.CursorTop + 1;
}
break;
case ConsoleKey.LeftArrow: if (pointer > 0) { pointer--; Console.CursorLeft--; } break;
case ConsoleKey.RightArrow: if (pointer < 80) { pointer++; Console.CursorLeft++; if (line[pointer] == 0) line[pointer] = ' '; } break;
case ConsoleKey.Backspace: deleteChar(); break;
case ConsoleKey.Delete: deleteChar(); break;
case ConsoleKey.Enter:
lines.Add(new String(line).TrimEnd()); cleanArray(line); Console.CursorLeft = 0; Console.CursorTop++; pointer = 0;
break;
default: line[pointer] = ch; pointer++; Console.Write(ch); break;
}
}
Console.Clear();
}
else
{
Console.Clear();
drawTopBar();
Console.SetCursorPosition(0, 1);
ConsoleKeyInfo c; cleanArray(line);
while ((c = Console.ReadKey(true)) != null)
{
drawTopBar();
Char ch = c.KeyChar;
if (c.Key == ConsoleKey.Escape)
break;
else if (c.Key == ConsoleKey.F1)
{
Console.Clear();
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Black;
Utils.WriteTextCentered("Liquid Editor by TheCool1James & valentinbreiz");
Utils.WriteTextCentered("Version " + version);
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
lines.Add(new String(line).TrimEnd());
final = lines.ToArray();
String foo = Utils.ConcatString(final);
System.IO.File.Create(currentdirectory + filename);
System.IO.File.WriteAllText(currentdirectory + filename, foo);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("'" + filename + "' has been saved in '" + currentdirectory + "' !");
Console.ForegroundColor = ConsoleColor.White;
Console.ReadKey();
break;
}
else if (c.Key == ConsoleKey.F2)
{
Start(currentdirectory);
break;
}
switch (c.Key)
{
case ConsoleKey.Home: break;
case ConsoleKey.PageUp: break;
case ConsoleKey.PageDown: break;
case ConsoleKey.End: break;
case ConsoleKey.UpArrow:
if (Console.CursorTop > 1)
{
Console.CursorTop = Console.CursorTop - 1;
}
break;
case ConsoleKey.DownArrow:
if (Console.CursorTop < 23)
{
Console.CursorTop = Console.CursorTop + 1;
}
break;
case ConsoleKey.LeftArrow: if (pointer > 0) { pointer--; Console.CursorLeft--; } break;
case ConsoleKey.RightArrow: if (pointer < 80) { pointer++; Console.CursorLeft++; if (line[pointer] == 0) line[pointer] = ' '; } break;
case ConsoleKey.Backspace: deleteChar(); break;
case ConsoleKey.Delete: deleteChar(); break;
case ConsoleKey.Enter:
lines.Add(new String(line).TrimEnd()); cleanArray(line); Console.CursorLeft = 0; Console.CursorTop++; pointer = 0;
break;
default: line[pointer] = ch; pointer++; Console.Write(ch); break;
}
}
Console.Clear();
}
}
public static void cleanArray(Char[] c)
{
for (int i = 0; i < c.Length; i++)
c[i] = ' ';
}
public static void drawTopBar()
{
int x = Console.CursorLeft, y = Console.CursorTop;
Console.SetCursorPosition(0, 0);
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Black;
Console.Write("Liquid Editor v" + version + "                                  ");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("[F1]Save  [F2]New  [ESC]Exitn");
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
Console.SetCursorPosition(x, y);
}
public static void deleteChar()
{
if ((Console.CursorLeft >= 1) && (pointer >= 1))
{
pointer--;
Console.CursorLeft--;
Console.Write(" ");
Console.CursorLeft--;
line[pointer] = ' ';
}
else if ((Console.CursorTop >= 2))
{
Console.CursorTop--;
Console.Write(new String(' ', lines[lines.Count - 1].Length - 1));
Console.CursorTop--;
lines.RemoveAt(lines.Count - 1);
line = lines[lines.Count - 1].ToCharArray();
}
}
public static void listCheck()
{
foreach (var s in lines)
Console.WriteLine(" List: " + s + "n");
}
private String[] arrayCheck(String[] s)
{
foreach (var ss in s)
{
Console.WriteLine(" Line: " + ss + "n");
}
return s;
}
}
}

跑龙套代码:

using System;
using System.Collections.Generic;
using System.Text;
namespace LDCM
{
public static class Utils
{
public static void WriteTextCentered(String content)
{
Console.Write(new string(' ', (Console.WindowWidth - content.Length - 2) / 2));
Console.WriteLine(content);
}
public static String ConcatString(String[] s)
{
String t = "";
if (s.Length >= 1)
{
for (int i = 0; i < s.Length; i++)
{
if (!String.IsNullOrWhiteSpace(s[i]))
t = String.Concat(t, s[i].TrimEnd(), Environment.NewLine);
}
}
else
t = s[0];
t = String.Concat(t, '');
return t;
}
}
}

您提到的代码以这种方式在我的环境中运行良好:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
namespace Rextester
{
public class Program
{

public static void Main(string[] args)
{
List<String> lines = new List<String>();
Char[] line = new Char[80];
lines.Add("Giorgi");
lines.Add("Davut");
Console.Write(new String('_', lines[lines.Count - 1].Length - 1)); 
lines.RemoveAt(lines.Count - 1); 
line = lines[lines.Count - 1].ToCharArray(); 
}
}
}

我不能把这个贴在评论里来检查它是否有价值,但是让我知道它是否可以改进。

最新更新