From 8e3bdf71e71096711f11a0d51b2b384e117391ee Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 07:21:16 -0400 Subject: [PATCH] strip things down but make things better --- ShiftOS.WinForms/Applications/Terminal.cs | 6 +-- ShiftOS.WinForms/Controls/TerminalBox.cs | 6 --- ShiftOS_TheReturn/ConsoleEx.cs | 7 ++++ ShiftOS_TheReturn/SaveSystem.cs | 2 + ShiftOS_TheReturn/TerminalBackend.cs | 11 ++---- ShiftOS_TheReturn/TerminalTextWriter.cs | 45 +++++++++++++---------- 6 files changed, 42 insertions(+), 35 deletions(-) diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 4cd4806..6039456 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -268,7 +268,8 @@ namespace ShiftOS.WinForms.Applications { try { - a.SuppressKeyPress = true; + if (!TerminalBackend.InStory) + a.SuppressKeyPress = false; if (!TerminalBackend.PrefixEnabled) { string textraw = txt.Lines[txt.Lines.Length - 1]; @@ -276,9 +277,8 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.SendText(textraw); return; } - Console.WriteLine(""); var text = txt.Lines.ToArray(); - var text2 = text[text.Length - 2]; + var text2 = text[text.Length - 1]; var text3 = ""; var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 7658c8c..25f7144 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -64,9 +64,6 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { this.HideSelection = true; - this.SelectionFont = ConstructFont(); - this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); - this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text)); this.HideSelection = false; } @@ -89,9 +86,6 @@ namespace ShiftOS.WinForms.Controls Engine.AudioManager.PlayStream(Properties.Resources.writesound); this.HideSelection = true; this.Select(this.TextLength, 0); - this.SelectionFont = ConstructFont(); - this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); - this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text) + Environment.NewLine); this.HideSelection = false; } diff --git a/ShiftOS_TheReturn/ConsoleEx.cs b/ShiftOS_TheReturn/ConsoleEx.cs index 90f9cc0..74483dc 100644 --- a/ShiftOS_TheReturn/ConsoleEx.cs +++ b/ShiftOS_TheReturn/ConsoleEx.cs @@ -48,5 +48,12 @@ namespace ShiftOS.Engine /// Gets or sets whether text in the Terminal is underlined. /// public static bool Underline { get; set; } + + internal static void Flush() + { + OnFlush?.Invoke(); + } + + public static Action OnFlush; } } diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index f3d95be..24a491d 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -393,6 +393,7 @@ namespace ShiftOS.Engine TerminalBackend.TextSent += ev; Console.WriteLine(); Console.Write(CurrentSave.SystemName + " login: "); + ConsoleEx.Flush(); while (progress == 0) { Thread.Sleep(10); @@ -401,6 +402,7 @@ namespace ShiftOS.Engine goto Login; Console.WriteLine(); Console.Write("password: "); + ConsoleEx.Flush(); while (progress == 1) Thread.Sleep(10); if (goback) diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index b18e27c..1c024eb 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -361,14 +361,12 @@ namespace ShiftOS.Engine /// Whether the command should be sent through Remote Terminal Session (RTS). public static void InvokeCommand(string text, bool isRemote = false) { + if (string.IsNullOrWhiteSpace(text)) + return; var tw = new MemoryTextWriter(); Console.SetOut(tw); try { - - if (string.IsNullOrWhiteSpace(text)) - return; - var args = GetArgs(ref text); Stopwatch debugger = new Stopwatch(); @@ -533,10 +531,9 @@ namespace ShiftOS.Engine /// public static void PrintPrompt() { + Console.WriteLine(); if (SaveSystem.CurrentSave != null && CurrentUser != null) { - Desktop.InvokeOnWorkerThread(() => - { ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; ConsoleEx.Italic = false; ConsoleEx.Underline = false; @@ -566,7 +563,7 @@ namespace ShiftOS.Engine ConsoleEx.Bold = false; ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; Console.Write(" "); - }); + ConsoleEx.Flush(); } } diff --git a/ShiftOS_TheReturn/TerminalTextWriter.cs b/ShiftOS_TheReturn/TerminalTextWriter.cs index 010e02c..4c0c3a0 100644 --- a/ShiftOS_TheReturn/TerminalTextWriter.cs +++ b/ShiftOS_TheReturn/TerminalTextWriter.cs @@ -37,14 +37,19 @@ namespace ShiftOS.Engine /// public class TerminalTextWriter : TextWriter { - /// - /// Win32 API call to lock the window from being updated. - /// - /// The Win32 window handle - /// ...I....have no idea. - [System.Runtime.InteropServices.DllImport("user32.dll")] - public static extern bool LockWindowUpdate(IntPtr hWndLock); + public TerminalTextWriter() + { + ConsoleEx.OnFlush = () => + { + Desktop.InvokeOnWorkerThread(() => + { + UnderlyingControl?.Write(buffer); + buffer = ""; + }); + }; + } + /// /// Gets the encoding format for this . God bless the Unicode Consortiem. /// @@ -94,11 +99,17 @@ namespace ShiftOS.Engine } else { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.Write(value.ToString()); - select(); - })); + buffer += value; + } + } + + private string buffer = ""; + + public string Buffer + { + get + { + return buffer; } } @@ -118,11 +129,8 @@ namespace ShiftOS.Engine else { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.WriteLine(value); - select(); - })); + buffer += value + Environment.NewLine; + ConsoleEx.Flush(); } } @@ -149,8 +157,7 @@ namespace ShiftOS.Engine Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl?.Write(value.ToString()); - select(); + buffer += value; })); } }