diff options
| author | william341 <[email protected]> | 2017-05-28 12:37:00 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-28 12:37:00 -0700 |
| commit | 771c20cfb3a703e0f1550fdcf9eb07b78298c944 (patch) | |
| tree | 59cb532e15ebff313fdba2be264d78ec0033f407 /ShiftOS_TheReturn/TerminalTextWriter.cs | |
| parent | 496b0cbf8659c99203f48210fd39c572400ae623 (diff) | |
| parent | c7ba7d733c756d196f98dd4533289a1ef4db715f (diff) | |
| download | shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.gz shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.bz2 shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.zip | |
Merge pull request #1 from shiftos-game/master
welp, no longer a dev.
Diffstat (limited to 'ShiftOS_TheReturn/TerminalTextWriter.cs')
| -rw-r--r-- | ShiftOS_TheReturn/TerminalTextWriter.cs | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/ShiftOS_TheReturn/TerminalTextWriter.cs b/ShiftOS_TheReturn/TerminalTextWriter.cs index bc242a9..63e88eb 100644 --- a/ShiftOS_TheReturn/TerminalTextWriter.cs +++ b/ShiftOS_TheReturn/TerminalTextWriter.cs @@ -32,12 +32,28 @@ using System.Windows.Forms; namespace ShiftOS.Engine { + /// <summary> + /// Backend class for forwarding <see cref="System.Console"/> to the ShiftOS terminal. + /// </summary> public class TerminalTextWriter : TextWriter { - [System.Runtime.InteropServices.DllImport("user32.dll")] - public static extern bool LockWindowUpdate(IntPtr hWndLock); + public TerminalTextWriter() + { + ConsoleEx.OnFlush = () => + { + System.Diagnostics.Debug.WriteLine("[terminal] " + buffer); + Desktop.InvokeOnWorkerThread(() => + { + UnderlyingControl?.Write(buffer); + buffer = ""; + }); + }; + } + /// <summary> + /// Gets the encoding format for this <see cref="TextWriter"/>. God bless the Unicode Consortiem. + /// </summary> public override Encoding Encoding { get @@ -46,6 +62,9 @@ namespace ShiftOS.Engine } } + /// <summary> + /// Gets the underlying <see cref="ITerminalWidget"/> that this <see cref="TerminalTextWriter"/> is forwarding to. + /// </summary> public ITerminalWidget UnderlyingControl { get @@ -54,15 +73,22 @@ namespace ShiftOS.Engine } } + /// <summary> + /// Moves the caret to the last character in the textbox. + /// </summary> public void select() { Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl.SelectBottom(); + UnderlyingControl?.SelectBottom(); })); } + /// <summary> + /// Write a character to the Terminal. + /// </summary> + /// <param name="value">The character to write.</param> public override void Write(char value) { if (TerminalBackend.IsForwardingConsoleWrites) @@ -74,14 +100,24 @@ namespace ShiftOS.Engine } else { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl.Write(value.ToString()); - select(); - })); + buffer += value; + } + } + + private string buffer = ""; + + public string Buffer + { + get + { + return buffer; } } + /// <summary> + /// Write text to the Terminal, followed by a newline. + /// </summary> + /// <param name="value">The text to write.</param> public override void WriteLine(string value) { if (TerminalBackend.IsForwardingConsoleWrites) @@ -94,18 +130,20 @@ namespace ShiftOS.Engine else { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl.WriteLine(value); - select(); - })); + buffer += value + Environment.NewLine; + ConsoleEx.Flush(); } } + [Obsolete("Stub.")] public void SetLastText() { } + /// <summary> + /// Write text to the Terminal. + /// </summary> + /// <param name="value">The text to write.</param> public override void Write(string value) { if (TerminalBackend.IsForwardingConsoleWrites) @@ -120,8 +158,7 @@ namespace ShiftOS.Engine Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl.Write(value.ToString()); - select(); + buffer += value; })); } } |
