From 00cd41ea928781ad760cff3d14bd78d60758679d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 28 Jun 2017 08:19:44 -0400 Subject: Slight... very slight... fileskimmer mods --- ShiftOS.WinForms/Applications/Terminal.cs | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 51ad42b..794edf7 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -47,12 +47,51 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [FileHandler("Shell script", ".trm", "fileicontrm")] [Launcher("{TITLE_TERMINAL}", false, null, "{AL_UTILITIES}")] [WinOpen("{WO_TERMINAL}")] [DefaultTitle("{TITLE_TERMINAL}")] [DefaultIcon("iconTerminal")] - public partial class Terminal : UserControl, IShiftOSWindow + public partial class Terminal : UserControl, IShiftOSWindow, IFileHandler { + public void OpenFile(string file) + { + int lastline = 0; + string lastlinetext = ""; + + try + { + var lines = new List(ShiftOS.Objects.ShiftFS.Utils.ReadAllText(file).Split(new[] { Environment.NewLine.ToString() }, StringSplitOptions.RemoveEmptyEntries)); + AppearanceManager.SetupWindow(this); + var parser = CommandParser.GenerateSample(); + foreach (var line in lines) + { + lastline = lines.IndexOf(line) + 1; + lastlinetext = line; + var command = parser.ParseCommand(line); + TerminalBackend.InvokeCommand(command.Key, command.Value); + } + } + catch(Exception ex) + { + ConsoleEx.ForegroundColor = ConsoleColor.Red; + ConsoleEx.Bold = true; + Console.WriteLine("Script exception"); + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + ConsoleEx.Bold = false; + ConsoleEx.Italic = true; +#if DEBUG + Console.WriteLine(ex.Message); +#endif + Console.WriteLine(ex.StackTrace); + if(lastline > 0) + { + Console.WriteLine(" at " + lastlinetext + " (line " + lastline + ") in " + file); + } + } + TerminalBackend.PrintPrompt(); + } + public static Stack ConsoleStack = new Stack(); public static System.Windows.Forms.Timer ti = new System.Windows.Forms.Timer(); -- cgit v1.2.3