From 3f08cb807c1490af423450e3eb03a46aa11caf2f Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 16:14:35 -0500 Subject: Colored terminal text --- ShiftOS_TheReturn/ConsoleEx.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ShiftOS_TheReturn/ConsoleEx.cs (limited to 'ShiftOS_TheReturn/ConsoleEx.cs') diff --git a/ShiftOS_TheReturn/ConsoleEx.cs b/ShiftOS_TheReturn/ConsoleEx.cs new file mode 100644 index 0000000..69f6a18 --- /dev/null +++ b/ShiftOS_TheReturn/ConsoleEx.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Engine +{ + public static class ConsoleEx + { + static ConsoleEx() + { + ForegroundColor = ConsoleColor.White; + BackgroundColor = ConsoleColor.Black; + + Bold = false; + Italic = false; + Underline = false; + } + + public static ConsoleColor ForegroundColor { get; set; } + public static ConsoleColor BackgroundColor { get; set; } + + public static bool Bold { get; set; } + public static bool Italic { get; set; } + public static bool Underline { get; set; } + } +} -- cgit v1.2.3 From a0fc2b5e701659d1ed17eba9c2888cae6d519c1e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Apr 2017 09:48:33 -0400 Subject: More documentation --- ShiftOS.WinForms/Applications/Pong.cs | 11 ++-- ShiftOS.WinForms/Applications/Terminal.cs | 1 - ShiftOS.WinForms/Resources/Shiftorium.txt | 7 --- ShiftOS.WinForms/WinformsWindowManager.cs | 6 -- ShiftOS_TheReturn/ConsoleEx.cs | 24 +++++++ ShiftOS_TheReturn/CrashHandler.cs | 1 - ShiftOS_TheReturn/Desktop.cs | 101 +++++++++++++++++++++++++++++- 7 files changed, 129 insertions(+), 22 deletions(-) (limited to 'ShiftOS_TheReturn/ConsoleEx.cs') diff --git a/ShiftOS.WinForms/Applications/Pong.cs b/ShiftOS.WinForms/Applications/Pong.cs index 5d09ca0..0ef4da3 100644 --- a/ShiftOS.WinForms/Applications/Pong.cs +++ b/ShiftOS.WinForms/Applications/Pong.cs @@ -115,11 +115,12 @@ namespace ShiftOS.WinForms.Applications paddleHuman.BackColor = SkinEngine.LoadedSkin.ControlTextColor; //Check if paddle upgrade has been bought and change paddles accordingly - if (ShiftoriumFrontend.UpgradeInstalled("pong_increased_paddle_size")) - { - paddleHuman.Height = 150; - paddleComputer.Height = 150; - } + //if (ShiftoriumFrontend.UpgradeInstalled("pong_increased_paddle_size")) + //{ + // paddleHuman.Height = 150; + // paddleComputer.Height = 150; + //} + //I don't know the point of this but I'm fucking 86ing it. - Michael //Set the computer player to move according to the ball's position. if (aiShouldIsbeEnabled) diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index c0fdf01..8d29cba 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -321,7 +321,6 @@ namespace ShiftOS.WinForms.Applications { if (SaveSystem.CurrentSave != null) { if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) { - rtbterm.Text = AppearanceManager.LastTerminalText; rtbterm.Select(rtbterm.TextLength, 0); } TerminalBackend.PrintPrompt(); diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index 2260198..82ee613 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -259,13 +259,6 @@ Category: "Device Drivers", Description: "With the free placement upgrade, you can place windows of any size anywhere on the desktop, which means theoretically you could add kernel coherence between ShiftOS and another GUI-based operating system and run their applications inside ShiftOS. This upgrade unlocks that.", }, - { - Name: "Pong Increased Paddle Size", - Cost: 1000, - Dependencies: "pong_upgrade", - Category: "Enhancements", - Description: "Having trouble keeping that darn ball in front of you? Well, with this upgrade, your paddle increases in height.... slightly.", - }, { Name: "WM 4 Windows", Cost: 150, diff --git a/ShiftOS.WinForms/WinformsWindowManager.cs b/ShiftOS.WinForms/WinformsWindowManager.cs index 4fcd185..8bff387 100644 --- a/ShiftOS.WinForms/WinformsWindowManager.cs +++ b/ShiftOS.WinForms/WinformsWindowManager.cs @@ -125,12 +125,6 @@ namespace ShiftOS.WinForms public override void SetupWindow(IShiftOSWindow form) { - if (!AppearanceManager.CanOpenWindow(form)) - { - Infobox.Show("{MULTIPLAYER_ONLY}", "{MULTIPLAYER_ONLY_EXP}"); - return; - } - foreach(var attr in form.GetType().GetCustomAttributes(true)) { if(attr is MultiplayerOnlyAttribute) diff --git a/ShiftOS_TheReturn/ConsoleEx.cs b/ShiftOS_TheReturn/ConsoleEx.cs index 69f6a18..90f9cc0 100644 --- a/ShiftOS_TheReturn/ConsoleEx.cs +++ b/ShiftOS_TheReturn/ConsoleEx.cs @@ -6,8 +6,14 @@ using System.Threading.Tasks; namespace ShiftOS.Engine { + /// + /// Provides extra eye candy data that can be used by ShiftOS terminals. + /// public static class ConsoleEx { + /// + /// Initializes the class, performing core configuration. + /// static ConsoleEx() { ForegroundColor = ConsoleColor.White; @@ -18,11 +24,29 @@ namespace ShiftOS.Engine Underline = false; } + /// + /// Gets or sets the foreground color of text in the Terminal. + /// public static ConsoleColor ForegroundColor { get; set; } + + /// + /// Gets or sets the background color of text in the Terminal. + /// public static ConsoleColor BackgroundColor { get; set; } + /// + /// Gets or sets whether text in the Terminal is bold. + /// public static bool Bold { get; set; } + + /// + /// Gets or sets whether text in the Terminal is italic. + /// public static bool Italic { get; set; } + + /// + /// Gets or sets whether text in the Terminal is underlined. + /// public static bool Underline { get; set; } } } diff --git a/ShiftOS_TheReturn/CrashHandler.cs b/ShiftOS_TheReturn/CrashHandler.cs index 734f1a9..ed42ea5 100644 --- a/ShiftOS_TheReturn/CrashHandler.cs +++ b/ShiftOS_TheReturn/CrashHandler.cs @@ -97,7 +97,6 @@ namespace ShiftOS.Engine { if(SaveSystem.CurrentSave != null) TerminalBackend.InvokeCommand("sos.save"); - AudioManager.Kill(); ServerManager.Disconnect(); while (Application.OpenForms.Count > 0) diff --git a/ShiftOS_TheReturn/Desktop.cs b/ShiftOS_TheReturn/Desktop.cs index b72f0cc..bc17a8e 100644 --- a/ShiftOS_TheReturn/Desktop.cs +++ b/ShiftOS_TheReturn/Desktop.cs @@ -37,6 +37,10 @@ using static ShiftOS.Engine.SkinEngine; namespace ShiftOS.Engine { + /// + /// Denotes that this class is launchable from the App Launcher. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class LauncherAttribute : Attribute { /// @@ -54,10 +58,29 @@ namespace ShiftOS.Engine ID = upgradeID; } + /// + /// Gets or sets the name of the launcher item + /// public string Name { get; set; } + + /// + /// Gets or sets whether this entry requires a Shiftorium upgrade. + /// public bool RequiresUpgrade { get; set; } + + /// + /// Gets or sets the ID of the required upgrade. + /// public string ID { get; set; } + + /// + /// Gets or sets this item's category. + /// public string Category { get; private set; } + + /// + /// Gets whether or not the required upgrade is installed. + /// public bool UpgradeInstalled { get @@ -70,36 +93,110 @@ namespace ShiftOS.Engine } } - + /// + /// Provides core functionality for a typical ShiftOS desktop. + /// public interface IDesktop { + /// + /// Gets the name of the desktop. + /// string DesktopName { get; } + + /// + /// Performs most of the skinning and layout handling for the desktop. + /// void SetupDesktop(); + /// + /// Hides the currently-opened app launcher menu. + /// void HideAppLauncher(); + + /// + /// Populates the app launcher menu. + /// + /// All items to be placed in the menu. void PopulateAppLauncher(LauncherItem[] items); + + /// + /// Handles desktop-specific routines for showing ShiftOS windows. + /// + /// The calling window. void ShowWindow(IWindowBorder border); + + /// + /// Handles desktop-specific routines for closing ShiftOS windows. + /// + /// The calling window. void KillWindow(IWindowBorder border); + + /// + /// Populates the panel button list with all open windows. + /// void PopulatePanelButtons(); + + /// + /// Performs desktop-specific routines for minimizing a window. + /// + /// The calling window. void MinimizeWindow(IWindowBorder brdr); + + + /// + /// Performs desktop-specific routines for maximizing a window. + /// + /// The calling window. void MaximizeWindow(IWindowBorder brdr); + + + /// + /// Performs desktop-specific routines for restoring a window to its default state. + /// + /// The calling window. void RestoreWindow(IWindowBorder brdr); + + /// + /// Invokes an action on the UI thread. + /// + /// The action to invoke. void InvokeOnWorkerThread(Action act); + + /// + /// Calculates the screen size of the desktop. + /// + /// The desktop's screen size. Size GetSize(); + /// + /// Opens the app launcher at a specific point. + /// + /// Where the app launcher should be opened. void OpenAppLauncher(Point loc); + /// + /// Opens the desktop. + /// void Show(); + + /// + /// Closes the desktop. + /// void Close(); } public static class Desktop { + /// + /// The underlying desktop object. + /// private static IDesktop _desktop = null; - public static Size Size { get + public static Size Size + { + get { return _desktop.GetSize(); } -- cgit v1.2.3 From 8e3bdf71e71096711f11a0d51b2b384e117391ee Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 07:21:16 -0400 Subject: 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(-) (limited to 'ShiftOS_TheReturn/ConsoleEx.cs') 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; })); } } -- cgit v1.2.3