Example #1
0
        /// Append the text in the buffer to gui.txtStdOut
        public override void Write(byte[] buffer, int offset, int count)
        {
            lock (this)
            {
                if (_gui.IsDisposed)
                {
                    return;
                }

                if (!_gui.Visible)
                {
                    _gui.Show();
                }

                var actualBuffer = new byte[count];
                Array.Copy(buffer, offset, actualBuffer, 0, count);
                var text = Encoding.UTF8.GetString(actualBuffer);
                _gui.BeginInvoke((Action) delegate()
                {
                    // Cleanup output for html
                    var div = _gui.txtStdOut.Document.CreateElement(ExternalConfig.defaultelement);
                    // if (text.StartsWith("\n"))
                    //     text = text.Remove(0);
                    if (text.EndsWith("\n"))
                    {
                        text = text.Remove(text.Length - 1);
                    }
                    text          = text.Replace("<", "&lt;").Replace(">", "&gt;");
                    text          = text.Replace("&clt;", "<").Replace("&cgt;", ">");
                    text          = text.Replace("\n", "<br/>");
                    text          = text.Replace("\t", "&emsp;&emsp;");
                    div.InnerHtml = text;
                    _gui.txtStdOut.Document.Body.AppendChild(div);
                });
                _gui.ScrollToBottom();
            }
        }