2

I am making a os with Cosmos and working in a text editor I copied the code from LiquidEditor but it does not seem to work very well with lines, so I tried to inplement a little line system, but it gives me an error: Enum.ToString() is not implemented.

Kernel code:

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:\0.txt"));
            Console.ReadKey(true);
        }
    }
}

LiquidEditor code:

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]Exit\n");
            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;
        }
    }
}

Utils code:

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, '\0');
            return t;
        }
    }
}
DALVES2012
  • 27
  • 5
  • Is there any part of code where you use `Enum.ToString()` ? – Giorgi Gvimradze Sep 13 '21 at 19:29
  • thanks, but please let's use only the problematic part. the part of the code where you think the problem is located. – Giorgi Gvimradze Sep 13 '21 at 19:42
  • The problem is in this code: ``` 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(); } ``` – DALVES2012 Sep 13 '21 at 19:49

1 Answers1

1

The code you mentioned works fine on my environment in this way:

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(); 
        }
    }
}

I couldn't post this in comments to check if it is valued or not, but let me know if it is improveable.

Giorgi Gvimradze
  • 1,714
  • 1
  • 17
  • 34