Example #1
0
        /// <summary>
        /// Runs the prompt.
        /// </summary>
        public void Run()
        {
            Prompt();
            bool rkey = true;

            while (rkey)
            {
                System.ConsoleKeyInfo info = Console.ReadKey(true);
                switch (info.KeyChar)
                {
                    #region Letters&Numbers
                case 'a':
                case 'A':
                case 'b':
                case 'B':
                case 'c':
                case 'C':
                case 'd':
                case 'D':
                case 'e':
                case 'E':
                case 'f':
                case 'F':
                case 'g':
                case 'G':
                case 'h':
                case 'H':
                case 'i':
                case 'I':
                case 'j':
                case 'J':
                case 'k':
                case 'K':
                case 'l':
                case 'L':
                case 'm':
                case 'M':
                case 'n':
                case 'N':
                case 'o':
                case 'O':
                case 'p':
                case 'P':
                case 'q':
                case 'Q':
                case 'r':
                case 'R':
                case 's':
                case 'S':
                case 't':
                case 'T':
                case 'u':
                case 'U':
                case 'v':
                case 'V':
                case 'w':
                case 'W':
                case 'x':
                case 'X':
                case 'y':
                case 'Y':
                case 'z':
                case 'Z':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case ' ':
                case ';':
                case ':':
                case '<':
                case ',':
                case '>':
                case '.':
                case '?':
                case '/':
                case '"':
                case '\'':
                case '{':
                case '[':
                case '}':
                case ']':
                case '|':
                case '\\':
                case '+':
                case '=':
                case '-':
                case '_':
                case ')':
                case '(':
                case '*':
                case '&':
                case '^':
                case '%':
                case '$':
                case '#':
                case '@':
                case '!':
                case '~':
                case '`':
                    #endregion
                    //Erase cursor:
                    VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, bColor);
                    VGADriver.driver.DoubleBuffer_Update();
                    if ((currentDirectory + ">" + txt.ToString()).Length % 79 == 0)
                    {
                        ////Draw character entered:
                        //VGADriver.driver._DrawACSIIString(info.KeyChar.ToString(), tColor, (uint)LocX, (uint)LocY);
                        //VGADriver.driver.DoubleBuffer_Update();
                        ////Save last coordinates:
                        //LLocX = LocX;
                        //LLocY = LocY;
                        //// Go to next line:
                        //LocX = 0;
                        //LocY += 12;
                        ////Draw cursor up one character:
                        //VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, tColor);
                        //VGADriver.driver.DoubleBuffer_Update();
                    }
                    else
                    {
                        if ((LocX + 8) <= charLength)
                        {
                            LocX += 8;
                            //Draw cursor up one character:
                            VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, tColor);
                            VGADriver.driver.DoubleBuffer_Update();
                            //Draw character entered:
                            VGADriver.driver._DrawACSIIString(info.KeyChar.ToString(), tColor, (uint)LocX - 8, (uint)LocY);
                            VGADriver.driver.DoubleBuffer_Update();
                        }
                    }

                    if (KeyPress_Handler != null)
                    {
                        KeyPress_Handler.Invoke(info.KeyChar, new EventArgs());
                    }
                    txt.Append(info.KeyChar);
                    break;

                default:
                    switch (info.Key)
                    {
                    case ConsoleKey.Backspace:
                        if (txt.Length > 0)
                        {
                            if (LocX == 0)
                            {
                                //// Erase last character:
                                //VGADriver.driver._DrawACSIIString(txt[txt.Length - 1].ToString(), bColor, (uint)LLocX, (uint)LLocY);
                                ////Erase cursor:
                                //VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, bColor);
                                //VGADriver.driver.DoubleBuffer_Update();
                                //LocX = LLocX;
                                //LocY = LLocY;
                                ////LocX -= 8;
                                ////Draw cursor one character back:
                                //VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, tColor);
                                //VGADriver.driver.DoubleBuffer_Update();
                                //txt.Remove(txt.Length - 1, 1);
                            }
                            else
                            {
                                // Erase last character:
                                VGADriver.driver._DrawACSIIString(txt[txt.Length - 1].ToString(), bColor, (uint)LocX - 8, (uint)LocY);
                                //Erase cursor:
                                VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, bColor);
                                VGADriver.driver.DoubleBuffer_Update();
                                LocX -= 8;
                                //Draw cursor one character back:
                                VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, tColor);
                                VGADriver.driver.DoubleBuffer_Update();
                                txt.Remove(txt.Length - 1, 1);
                            }

                            if (Backspace_Handler != null)
                            {
                                Backspace_Handler.Invoke("BACKSPACE", new EventArgs());
                            }
                        }
                        else
                        {
                            if (Backspace_Handler != null)
                            {
                                Backspace_Handler.Invoke("BACKSPACE", new EventArgs());
                            }
                        }
                        break;

                    case ConsoleKey.Enter:
                        //EndLine += 1;
                        if (Internal.screenHeight <= (PromptLocY + 12))
                        {
                            //Erase cursor:
                            VGADriver.driver.DoubleBuffer_DrawFillRectangle((uint)LocX, (uint)LocY + 13, 8, 2, bColor);
                            VGADriver.driver.DoubleBuffer_Update();
                            // Go to next line:
                            LocX     = 0;
                            LocY    += 12;
                            EndLine += 1;
                            // Draw string:
                            //VGADriver.driver._DrawACSIIString(EndLine.ToString() + ", " + charHeight.ToString() + ", " + ScreenInput.Count.ToString(), (uint)Color.White.ToArgb(), (uint)LocX, (uint)LocY);
                            //VGADriver.driver.DoubleBuffer_Update();
                            // Go to next line:
                            //LocX = 0;
                            //LocY += 14;
                            //DrawCursor(LocX, LocY);
                            PromptLocX  = 0;
                            PromptLocY += 12;

                            VGADriver.driver.DoubleBuffer_Clear(bColor);
                            VGADriver.driver.DoubleBuffer_Update();
                            int range;
                            if ((ScreenInput.Count - charHeight) <= -1)
                            {
                                range = ScreenInput.Count;
                            }
                            else
                            {
                                range = ScreenInput.Count - charHeight;
                            }

                            for (int i = 0; i < range; i++)
                            {
                                VGADriver.driver._DrawACSIIString(ScreenInput[i], (uint)Color.White.ToArgb(), (uint)LocX, (uint)LocY);
                                VGADriver.driver.DoubleBuffer_Update();
                                LocY += 12;
                            }

                            PromptLocY = (uint)charHeight - 12;
                        }

                        if (txt.Length > 0)
                        {
                            if (txt.ToString().Contains(" "))
                            {
                                string[] cmds = txt.ToString().Split(' ');
                                if (CMDs.Contains(cmds[0]))
                                {
                                    int cmdindex = CMDs.IndexOf(cmds[0]);
                                    if (CMDS[cmdindex].Execute != null)
                                    {
                                        // use array
                                        List <string> args = new List <string>();
                                        for (int i = 1; i < cmds.Length; i++)
                                        {
                                            args.Add(cmds[i]);
                                        }
                                        CMDS[cmdindex].Execute.Invoke("EXECUTE", new CommandArgs(args));
                                        SaveToMemory();
                                    }
                                }
                                else
                                {
                                    if (InvalidCMD_Handler != null)
                                    {
                                        InvalidCMD_Handler.Invoke(cmds[0], new EventArgs());
                                    }
                                    SaveToMemory();
                                }
                            }
                            else
                            {
                                if (CMDs.Contains(txt.ToString()))
                                {
                                    // use string
                                    CMDS[CMDs.IndexOf(txt.ToString())].Execute.Invoke("EXECUTE", new CommandArgs(new List <string>()));
                                    SaveToMemory();
                                }
                                else
                                {
                                    if (InvalidCMD_Handler != null)
                                    {
                                        InvalidCMD_Handler.Invoke(txt.ToString(), new EventArgs());
                                    }
                                    SaveToMemory();
                                }
                            }
                        }
                        else
                        {
                            SaveToMemory();
                        }
                        break;
                    }
                    break;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Registers a command.
 /// </summary>
 /// <param name="command">The Command class instance representing the command to register.</param>
 public void RegisterCommand(Command command)
 {
     CMDs.Add(command.CommandText);
     CMDS.Add(command);
 }