public ScriptConsoleServer(ScriptClient client, int session)
            {
                _client  = client;
                _session = session;
                Title    = Loc.GetString("Robust C# Interactive (SERVER)");

                OutputPanel.AddText(Loc.GetString(@"Robust C# interactive console (SERVER)."));
                OutputPanel.AddText(">");
            }
Example #2
0
        public ScriptConsoleClient()
        {
            Title = Loc.GetString("Robust C# Interactive (CLIENT)");
            ScriptInstanceShared.InitDummy();

            _globals = new ScriptGlobalsImpl(this);

            IoCManager.InjectDependencies(this);

            OutputPanel.AddText(Loc.GetString(@"Robust C# interactive console (CLIENT)."));
            OutputPanel.AddText(">");
        }
Example #3
0
        public ScriptConsole()
        {
            _globals = new ScriptGlobals(this);

            IoCManager.InjectDependencies(this);

            Title = Loc.GetString("Robust C# Interactive");

            Contents.AddChild(new VBoxContainer
            {
                Children =
                {
                    new PanelContainer
                    {
                        PanelOverride = new StyleBoxFlat
                        {
                            BackgroundColor           = Color.FromHex("#1E1E1E"),
                            ContentMarginLeftOverride = 4
                        },
                        Children =
                        {
                            (_outputPanel         = new OutputPanel
                            {
                                SizeFlagsVertical = SizeFlags.FillExpand,
                            })
                        },
                        SizeFlagsVertical = SizeFlags.FillExpand
                    },
                    (_inputBar = new HistoryLineEdit{
                        PlaceHolder = Loc.GetString("Your C# code here.")
                    })
                }
            });

            _inputBar.OnTextEntered += InputBarOnOnTextEntered;
            CustomMinimumSize        = (550, 300);

            _outputPanel.AddText(Loc.GetString(@"Robust C# interactive console."));
            _outputPanel.AddText(">");
        }
            public void ReceiveResponse(MsgScriptResponse response)
            {
                RunButton.Disabled = false;

                // Remove > or . at the end of the output panel.
                OutputPanel.RemoveEntry(^ 1);
                _linesEntered += 1;

                if (!response.WasComplete)
                {
                    if (_linesEntered == 1)
                    {
                        OutputPanel.AddText($"> {_lastEnteredText}");
                    }
                    else
                    {
                        OutputPanel.AddText($". {_lastEnteredText}");
                    }

                    OutputPanel.AddText(".");
                    return;
                }

                // Remove echo of partial submission from the output panel.
                for (var i = 1; i < _linesEntered; i++)
                {
                    OutputPanel.RemoveEntry(^ 1);
                }

                _linesEntered = 0;

                // Echo entered script.
                var echoMessage = new FormattedMessage();

                echoMessage.PushColor(Color.FromHex("#D4D4D4"));
                echoMessage.AddText("> ");
                echoMessage.AddMessage(response.Echo);
                OutputPanel.AddMessage(echoMessage);

                OutputPanel.AddMessage(response.Response);

                OutputPanel.AddText(">");
            }
Example #5
0
        protected override async void Run()
        {
            var code = InputBar.Text;

            InputBar.Clear();

            // Remove > or . at the end of the output panel.
            OutputPanel.RemoveEntry(^ 1);

            _inputBuffer.AppendLine(code);
            _linesEntered += 1;

            var tree = SyntaxFactory.ParseSyntaxTree(SourceText.From(_inputBuffer.ToString()), ScriptInstanceShared.ParseOptions);

            if (!SyntaxFactory.IsCompleteSubmission(tree))
            {
                if (_linesEntered == 1)
                {
                    OutputPanel.AddText($"> {code}");
                }
                else
                {
                    OutputPanel.AddText($". {code}");
                }
                OutputPanel.AddText(".");
                return;
            }

            code = _inputBuffer.ToString().Trim();

            // Remove echo of partial submission from the output panel.
            for (var i = 1; i < _linesEntered; i++)
            {
                OutputPanel.RemoveEntry(^ 1);
            }

            _inputBuffer.Clear();
            _linesEntered = 0;

            Script newScript;

            if (_state != null)
            {
                newScript = _state.Script.ContinueWith(code);
            }
            else
            {
                var options = ScriptInstanceShared.GetScriptOptions(_reflectionManager);
                newScript = CSharpScript.Create(code, options, typeof(ScriptGlobals));
            }

            // Compile ahead of time so that we can do syntax highlighting correctly for the echo.
            newScript.Compile();

            // Echo entered script.
            var echoMessage = new FormattedMessage();

            echoMessage.PushColor(Color.FromHex("#D4D4D4"));
            echoMessage.AddText("> ");
            ScriptInstanceShared.AddWithSyntaxHighlighting(newScript, echoMessage, code, _highlightWorkspace);

            OutputPanel.AddMessage(echoMessage);

            try
            {
                if (_state != null)
                {
                    _state = await newScript.RunFromAsync(_state, _ => true);
                }
                else
                {
                    _state = await newScript.RunAsync(_globals, _ => true);
                }
            }
            catch (CompilationErrorException e)
            {
                var msg = new FormattedMessage();

                msg.PushColor(Color.Crimson);

                foreach (var diagnostic in e.Diagnostics)
                {
                    msg.AddText(diagnostic.ToString());
                    msg.AddText("\n");
                }

                OutputPanel.AddMessage(msg);
                OutputPanel.AddText(">");
                return;
            }

            if (_state.Exception != null)
            {
                var msg = new FormattedMessage();
                msg.PushColor(Color.Crimson);
                msg.AddText(CSharpObjectFormatter.Instance.FormatException(_state.Exception));
                OutputPanel.AddMessage(msg);
            }
            else if (ScriptInstanceShared.HasReturnValue(newScript))
            {
                var msg = new FormattedMessage();
                msg.AddText(CSharpObjectFormatter.Instance.FormatObject(_state.ReturnValue));
                OutputPanel.AddMessage(msg);
            }

            OutputPanel.AddText(">");
        }