From 72fe64f28d02cf41aa90b636608421e9b86ab896 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 8 Aug 2017 11:29:03 -0400 Subject: [PATCH] Block enter in terminal --- ShiftOS.Frontend/Apps/Terminal.cs | 95 ++++++++++--------- ShiftOS.Frontend/GUI/TextInput.cs | 2 + .../GraphicsSubsystem/GraphicsContext.cs | 2 - 3 files changed, 53 insertions(+), 46 deletions(-) diff --git a/ShiftOS.Frontend/Apps/Terminal.cs b/ShiftOS.Frontend/Apps/Terminal.cs index ff06dd0..6d01d9f 100644 --- a/ShiftOS.Frontend/Apps/Terminal.cs +++ b/ShiftOS.Frontend/Apps/Terminal.cs @@ -199,9 +199,12 @@ namespace ShiftOS.Frontend.Apps private PointF CaretPosition = new PointF(2, 2); private Size CaretSize = new Size(2, 15); + private bool doEnter = true; protected override void OnKeyEvent(KeyEvent a) { + if (a.Key != Keys.Enter) + doEnter = true; if (a.ControlDown && (a.Key == Keys.OemPlus || a.Key == Keys.Add)) { _zoomFactor *= 2; @@ -221,66 +224,70 @@ namespace ShiftOS.Frontend.Apps if (a.Key == Keys.Enter && !ReadOnly) { - if (!PerformTerminalBehaviours) + if (doEnter == true) { - Text = Text.Insert(Index, Environment.NewLine); - Index += 2; - RecalculateLayout(); - Invalidate(); - return; - } - - try - { - if (!TerminalBackend.PrefixEnabled) + if (!PerformTerminalBehaviours) { - string textraw = Lines[Lines.Length - 1]; - TerminalBackend.SendText(textraw); + Text = Text.Insert(Index, Environment.NewLine); + Index += 2; + RecalculateLayout(); + Invalidate(); return; } - var text = Lines; - var text2 = text[text.Length - 1]; - var text3 = ""; - var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); - WriteLine(""); - if (TerminalBackend.PrefixEnabled) + try { - text3 = text4.Remove(0, TerminalBackend.ShellOverride.Length); - } - if (!string.IsNullOrWhiteSpace(text3)) - { - TerminalBackend.LastCommand = text3; - TerminalBackend.SendText(text4); - if (TerminalBackend.InStory == false) + if (!TerminalBackend.PrefixEnabled) { + string textraw = Lines[Lines.Length - 1]; + TerminalBackend.SendText(textraw); + return; + } + var text = Lines; + var text2 = text[text.Length - 1]; + var text3 = ""; + var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); + WriteLine(""); + + if (TerminalBackend.PrefixEnabled) + { + text3 = text4.Remove(0, TerminalBackend.ShellOverride.Length); + } + if (!string.IsNullOrWhiteSpace(text3)) + { + TerminalBackend.LastCommand = text3; + TerminalBackend.SendText(text4); + if (TerminalBackend.InStory == false) { - var result = SkinEngine.LoadedSkin.CurrentParser.ParseCommand(text3); - - if (result.Equals(default(KeyValuePair>))) { - Console.WriteLine("{ERR_SYNTAXERROR}"); - } - else - { - TerminalBackend.InvokeCommand(result.Key, result.Value); - } + var result = SkinEngine.LoadedSkin.CurrentParser.ParseCommand(text3); + if (result.Equals(default(KeyValuePair>))) + { + Console.WriteLine("{ERR_SYNTAXERROR}"); + } + else + { + TerminalBackend.InvokeCommand(result.Key, result.Value); + } + + } } } } - } - catch - { - } - finally - { - if (TerminalBackend.PrefixEnabled) + catch { - TerminalBackend.PrintPrompt(); } - AppearanceManager.CurrentPosition = 0; + finally + { + if (TerminalBackend.PrefixEnabled) + { + TerminalBackend.PrintPrompt(); + } + AppearanceManager.CurrentPosition = 0; + } + doEnter = false; } } else if (a.Key == Keys.Back && !ReadOnly) diff --git a/ShiftOS.Frontend/GUI/TextInput.cs b/ShiftOS.Frontend/GUI/TextInput.cs index 36e21b1..1733a6a 100644 --- a/ShiftOS.Frontend/GUI/TextInput.cs +++ b/ShiftOS.Frontend/GUI/TextInput.cs @@ -72,6 +72,8 @@ namespace ShiftOS.Frontend.GUI protected override void OnKeyEvent(KeyEvent e) { + if (e.Key == Microsoft.Xna.Framework.Input.Keys.Enter) + return; if(e.Key == Microsoft.Xna.Framework.Input.Keys.Left) { if (_index > 0) diff --git a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs index e6479e9..df9c064 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs @@ -209,8 +209,6 @@ namespace ShiftOS.Frontend.GraphicsSubsystem } } - - public class TextCache { public string Text { get; set; }