Пример #1
0
        static void Main(string[] args)
        {
            try
            {
            Terminal.SetRaw();

            int terminalWidth;
            int terminalHeight;
            Terminal.GetDimensions(out terminalWidth, out terminalHeight);

            FrameManager frameManager =
                new FrameManager(terminalWidth, terminalHeight);

            Buffer b = new Buffer();
            for (int y = 0; y < 100000; ++y) {
                b.AppendLine($"line {y} asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf");
            }

            Terminal.Clear();

            Terminal.SetCursorPosition(b.Cursor.X, b.Cursor.Y);

            frameManager.CurrentFrame?.AddBuffer(b);

            frameManager.Draw();

            while (true)
            {
                int key = Console.Read();
                if ('q' == key) {
                    break;
                }
                else if ('d' == key) {
                    b.DeleteCurrentLine();
                }
                else if ('j' == key) {
                    b.MoveCursorDown(1);
                }
                else if ('k' == key) {
                    b.MoveCursorUp(1);
                }
                else if ('h' == key) {
                    b.MoveCursorLeft(1);
                }
                else if ('l' == key) {
                    b.MoveCursorRight(1);
                }
                else if ('g' == key) {
                    b.ScrollUp(1);
                }
                else if ('t' == key) {
                    b.ScrollDown(1);
                }

                frameManager.Draw();
            }
            }
            catch (Exception ex)
            {
            Console.WriteLine(ex.StackTrace);
            }
            finally
            {
            Terminal.Clear();
            Terminal.SetCursorPosition(0, 0);
            Terminal.SetCooked();
            }
        }