Updating linux build.
[Widgit.git] / OutputTextWriter.cs
blob6b10d1a0499fa040c34e47632a66714e30333cd6
1 //Widgit is free software; you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation; either version 2 of the License, or
4 //(at your option) any later version.
6 //Widgit is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
11 //You should have received a copy of the GNU General Public License
12 //along with Widgit; if not, write to the Free Software
13 //Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USAusing System;
16 using System;
17 using System.Windows.Forms;
18 using System.IO;
19 using System.Threading;
20 using System.ComponentModel;
22 namespace Widgit
26 public class OutputTextWriter : System.IO.StringWriter
28 delegate void SetTextCallback(char[] buffer, int index, int count);
30 ListBox m_listBox;
31 TextWriter m_realConsole;
32 public OutputTextWriter(ListBox b, TextWriter w)
34 m_listBox = b;
35 m_realConsole = w;
38 public override void Write(char[] buffer, int index, int count)
40 if (!m_listBox.InvokeRequired)
42 string s = new string(buffer);
43 int start = index > -1 ? index : 0;
44 int newcount = count < ((buffer.Length - 1) - start) ? count : ((buffer.Length - 1) - start);
45 m_listBox.Items.Add(s.Substring(index, newcount).Trim());
46 Application.DoEvents();
49 m_realConsole.Write(buffer, index, count);
51 public override void Write(string value)
53 m_listBox.Items.Add(value);
54 m_realConsole.Write(value + System.Environment.NewLine);
55 Application.DoEvents();
58 public void DebugWrite(string value)
60 m_listBox.Items.Add(value);
61 Application.DoEvents();