Esempio n. 1
0
 protected override void Run()
 {
     StdIn.SetEchoStream(false);
     BeginInput();
     while (Running)
     {
         while (HasEvents())
         {
             Program.ProgramEvent progEvent = PopEvent();
             if (progEvent.Message == Program.KeyboardDown)
             {
                 Program.InputEvent keyEvent = (Program.InputEvent)progEvent;
                 if (keyEvent != null)
                 {
                     ProcessInputEvent(keyEvent);
                 }
             }
         }
         Thread.Sleep(100);
     }
 }
Esempio n. 2
0
                protected void ProcessInputEvent(Program.InputEvent keyEvent)
                {
                    int c = keyEvent.KeyCode;

                    if (c != '\0')
                    {
                        if (c == '\r' || c == '\n')
                        {
                            StdOut.Write("\n");
                            if (InputBuffer.Length > 1 &&
                                (History.Count == 0 || (History.Count > 0 && History[History.Count - 1] != InputBuffer)))
                            {
                                History.Add(InputBuffer);
                            }
                            HistoryPosition = History.Count;
                            Execute(InputBuffer);
                            BeginInput();
                            SetInputBuffer("");
                            Cursor = 0;
                        }
                        else if (c == '\t')
                        {
                            //InputBuffer = AutocompleteInput(InputBuffer, InputBuffer.Length - 1);
                            SetInputBuffer(AutocompleteInput(InputBuffer, Cursor - 1));
                            Cursor = InputBuffer.Length;
                        }
                        else
                        {
                            try
                            {
                                InputBuffer = InputBuffer.Insert(Cursor, c.ToString());
                            }
                            catch (Exception exp)
                            {
                                InputBuffer += c;
                            }

                            Cursor++;
                        }
                        WriteInputBuffer();
                    }
                    // Check for backspace
                    else if (keyEvent.KeyCode == 8)
                    {
                        if (InputBuffer.Length > 0)
                        {
                            if (Cursor > 0)
                            {
                                InputBuffer = InputBuffer.Remove(Cursor - 1, 1);
                                Cursor--;
                            }
                            WriteInputBuffer();
                        }
                    }
                    else if (keyEvent.KeyCode == 127)
                    {
                        if (InputBuffer.Length > 0)
                        {
                            if (Cursor < InputBuffer.Length)
                            {
                                InputBuffer = InputBuffer.Remove(Cursor, 1);
                            }
                            WriteInputBuffer();
                        }
                    }
                    else if (keyEvent.KeyCode == 279)
                    {
                        Cursor = InputBuffer.Length;
                        UpdateCursor();
                    }
                    else if (keyEvent.KeyCode == 278)
                    {
                        Cursor = 0;
                        UpdateCursor();
                    }
                    else if (keyEvent.KeyCode == 274)
                    {
                        Debug.Log("History: " + HistoryPosition + ", " + History.Count);
                        if (HistoryPosition >= History.Count - 1)
                        {
                            SetInputBuffer("");
                            HistoryPosition = History.Count - 1;
                            Debug.Log("Writing empty buffer");
                            WriteInputBuffer();
                            return;
                        }

                        if (HistoryPosition < 0)
                        {
                            return;
                        }
                        SetInputBuffer(History[++HistoryPosition]);
                        WriteInputBuffer();
                    }
                    else if (keyEvent.KeyCode == 273)
                    {
                        if (HistoryPosition >= History.Count)
                        {
                            HistoryPosition = History.Count - 1;
                        }
                        if (HistoryPosition < 0)
                        {
                            return;
                        }
                        SetInputBuffer(History[HistoryPosition--]);
                        if (HistoryPosition < 0)
                        {
                            HistoryPosition = 0;
                        }
                        WriteInputBuffer();
                    }
                    // Left
                    else if (keyEvent.KeyCode == 276)
                    {
                        if (Cursor > 0)
                        {
                            Cursor--;
                        }
                        UpdateCursor();
                    }
                    // Right
                    else if (keyEvent.KeyCode == 275)
                    {
                        if (Cursor < InputBuffer.Length)
                        {
                            Cursor++;
                        }
                        UpdateCursor();
                    }
                }