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();
                    _gui.Focus();
                }

                var actualBuffer = new byte[count];
                Array.Copy(buffer, offset, actualBuffer, 0, count);
                var text = Encoding.UTF8.GetString(actualBuffer);

                // append output to the buffer
                _outputBuffer += text;

                if (count % 1024 != 0)
                {
                    // Cleanup output for html
                    if (_outputBuffer.EndsWith("\n"))
                    {
                        _outputBuffer = _outputBuffer.Remove(_outputBuffer.Length - 1);
                    }
                    _outputBuffer = _outputBuffer.Replace("<", "&lt;").Replace(">", "&gt;");
                    _outputBuffer = _outputBuffer.Replace("&clt;", "<").Replace("&cgt;", ">");
                    _outputBuffer = _outputBuffer.Replace("\n", "<br/>");
                    _outputBuffer = _outputBuffer.Replace("\t", "&emsp;&emsp;");

                    // write to output window
                    _gui.AppendText(_outputBuffer, ExternalConfig.defaultelement);

                    // reset buffer and flush state for next time
                    _outputBuffer = String.Empty;
                }
            }
        }