コード例 #1
0
        public static void MakeWidget(Controls.TerminalBox txt)
        {
            AppearanceManager.StartConsoleOut();
            txt.GotFocus += (o, a) =>
            {
                AppearanceManager.ConsoleOut = txt;
            };
            txt.KeyDown += (o, a) =>
            {
                if (a.Control == true || a.Alt == true)
                {
                    a.SuppressKeyPress = true;
                    return;
                }

                if (a.KeyCode == Keys.Enter)
                {
                    try
                    {
                        if (!TerminalBackend.InStory)
                        {
                            a.SuppressKeyPress = false;
                        }
                        if (!TerminalBackend.PrefixEnabled)
                        {
                            string textraw = txt.Lines[txt.Lines.Length - 1];
                            TextSent?.Invoke(textraw);
                            TerminalBackend.SendText(textraw);
                            return;
                        }
                        var text  = txt.Lines.ToArray();
                        var text2 = text[text.Length - 1];
                        var text3 = "";
                        txt.AppendText(Environment.NewLine);
                        var text4 = Regex.Replace(text2, @"\t|\n|\r", "");

                        if (IsInRemoteSystem == true)
                        {
                            ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new
                            {
                                guid    = RemoteGuid,
                                command = text4
                            }));
                        }
                        else
                        {
                            if (TerminalBackend.PrefixEnabled)
                            {
                                text3 = text4.Remove(0, $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
                            }
                            TerminalBackend.LastCommand = text3;
                            TextSent?.Invoke(text4);
                            TerminalBackend.SendText(text4);
                            if (TerminalBackend.InStory == false)
                            {
                                if (text3 == "stop theme")
                                {
                                    CurrentCommandParser.parser = null;
                                }
                                else
                                {
                                    var result = SkinEngine.LoadedSkin.CurrentParser.ParseCommand(text3);

                                    if (result.Equals(default(KeyValuePair <string, Dictionary <string, string> >)))
                                    {
                                        Console.WriteLine("{ERR_SYNTAXERROR}");
                                    }
                                    else
                                    {
                                        TerminalBackend.InvokeCommand(result.Key, result.Value);
                                    }
                                }
                            }
                            if (TerminalBackend.PrefixEnabled)
                            {
                                TerminalBackend.PrintPrompt();
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                else if (a.KeyCode == Keys.Back)
                {
                    try
                    {
                        var tostring3   = txt.Lines[txt.Lines.Length - 1];
                        var tostringlen = tostring3.Length + 1;
                        var workaround  = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
                        var derp        = workaround.Length + 1;
                        if (tostringlen != derp)
                        {
                            AppearanceManager.CurrentPosition--;
                        }
                        else
                        {
                            a.SuppressKeyPress = true;
                        }
                    }
                    catch
                    {
                        Debug.WriteLine("Drunky alert in terminal.");
                    }
                }
                else if (a.KeyCode == Keys.Left)
                {
                    if (SaveSystem.CurrentSave != null)
                    {
                        var getstring = txt.Lines[txt.Lines.Length - 1];
                        var stringlen = getstring.Length + 1;
                        var header    = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
                        var headerlen = header.Length + 1;
                        var selstart  = txt.SelectionStart;
                        var remstrlen = txt.TextLength - stringlen;
                        var finalnum  = selstart - remstrlen;

                        if (finalnum != headerlen)
                        {
                            AppearanceManager.CurrentPosition--;
                        }
                        else
                        {
                            a.SuppressKeyPress = true;
                        }
                    }
                }
                else if (a.KeyCode == Keys.Up)
                {
                    var tostring3 = txt.Lines[txt.Lines.Length - 1];
                    if (tostring3 == $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ")
                    {
                        Console.Write(TerminalBackend.LastCommand);
                    }
                    ConsoleEx.OnFlush?.Invoke();
                    a.SuppressKeyPress = true;
                }
                else
                {
                    if (TerminalBackend.InStory)
                    {
                        a.SuppressKeyPress = true;
                    }
                    AppearanceManager.CurrentPosition++;
                }
            };

            AppearanceManager.ConsoleOut = txt;

            txt.Focus();

            txt.Font      = LoadedSkin.TerminalFont;
            txt.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC);
            txt.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC);
        }
コード例 #2
0
ファイル: Terminal.cs プロジェクト: carverh/ShiftOS-1
        public static void MakeWidget(Controls.TerminalBox txt)
        {
            AppearanceManager.StartConsoleOut();
            txt.GotFocus += (o, a) => {
                AppearanceManager.ConsoleOut = txt;
            };
            txt.KeyDown += (o, a) => {
                if (a.KeyCode == Keys.Enter)
                {
                    try {
                        a.SuppressKeyPress = true;
                        Console.WriteLine("");
                        var text  = txt.Lines.ToArray();
                        var text2 = text[text.Length - 2];
                        var text3 = "";
                        var text4 = Regex.Replace(text2, @"\t|\n|\r", "");

                        if (TerminalBackend.PrefixEnabled)
                        {
                            text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
                        }
                        TerminalBackend.LastCommand = text3;
                        TextSent?.Invoke(text4);
                        if (TerminalBackend.InStory == false)
                        {
                            TerminalBackend.InvokeCommand(text3);
                        }
                        if (TerminalBackend.PrefixEnabled)
                        {
                            Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
                        }
                    } catch {
                    }
                }
                else if (a.KeyCode == Keys.Back)
                {
                    var tostring3   = txt.Lines[txt.Lines.Length - 1];
                    var tostringlen = tostring3.Length + 1;
                    var workaround  = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
                    var derp        = workaround.Length + 1;
                    if (tostringlen != derp)
                    {
                        AppearanceManager.CurrentPosition--;
                    }
                    else
                    {
                        a.SuppressKeyPress = true;
                    }
                }
                else if (a.KeyCode == Keys.Left)
                {
                    var getstring = txt.Lines[txt.Lines.Length - 1];
                    var stringlen = getstring.Length + 1;
                    var header    = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
                    var headerlen = header.Length + 1;
                    var selstart  = txt.SelectionStart;
                    var remstrlen = txt.TextLength - stringlen;
                    var finalnum  = selstart - remstrlen;

                    if (finalnum != headerlen)
                    {
                        AppearanceManager.CurrentPosition--;
                    }
                    else
                    {
                        a.SuppressKeyPress = true;
                    }
                }
                //( ͡° ͜ʖ ͡° ) You found the lennyface without looking at the commit message. Message Michael in the #shiftos channel on Discord saying "ladouceur" somewhere in your message if you see this.
                else if (a.KeyCode == Keys.Up)
                {
                    var tostring3 = txt.Lines[txt.Lines.Length - 1];
                    if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ")
                    {
                        Console.Write(TerminalBackend.LastCommand);
                    }
                    a.SuppressKeyPress = true;
                }
                else
                {
                    if (TerminalBackend.InStory)
                    {
                        a.SuppressKeyPress = true;
                    }
                    AppearanceManager.CurrentPosition++;
                }
            };

            AppearanceManager.ConsoleOut = txt;

            txt.Focus();

            txt.Font      = LoadedSkin.TerminalFont;
            txt.ForeColor = LoadedSkin.TerminalForeColor;
            txt.BackColor = LoadedSkin.TerminalBackColor;
        }