/// <summary> /// Change the Windows console mode to support ANSI color strings /// Sets the console size & position /// </summary> public static void PrepareConsole() { #if __MonoCS__ #else // 0x0004 = Modify Console for color codes ( Windows only) // ConsoleUtils.GetConsoleMode(ConsoleHandle, out int currentMode); ConsoleUtils.SetConsoleMode(ConsoleHandle, currentMode | 0x0004); #endif ModifyConsoleWindow(); SharedEvents.OnCoreStartupCompleted += () => { #if !__MonoCS__ ConsoleInput.PrepareConsoleInput(); #endif // Register Console commands. (In core not automaticly) ConsoleOutput.WriteLine(ConsoleType.ConsoleCommand, "ConsoleHandler commands."); ConsoleOutput.AppendPrefix("\t > ~;~"); ConsoleCommandHandler.InspectModule(new Commands()); ConsoleOutput.ResetPrefix(); }; #if !__MonoCS__ // Debug // Catch CTRL + C Console.CancelKeyPress += (sender, args) => { args.Cancel = true; ConsoleOutput.WriteLine(ConsoleType.Info, "Please shutdown with ~b~exit~;~ console command."); }; #endif }
/// <summary> /// Modifys the console window propertys /// </summary> private static void ModifyConsoleWindow() { //TODO: Linux support #if !__MonoCS__ // Setting screen or primary screen // Fullscreen if (Settings.Default.ConsoleFullscreenMode) { Screen screen = Screen.AllScreens.ElementAt(Settings.Default.ConsoleFullscreenDisplay); // Fullscreen screen connected -> restore fullscreen on screen if (screen != null) { // Move to wanted display ConsoleUtils.SetWindowPos(ConsoleUtils.GetConsoleWindow(), 0, screen.WorkingArea.Left, screen.WorkingArea.Top, Console.LargestWindowWidth, Console.LargestWindowHeight, 1); ConsoleUtils.ToggleConsoleFullscreenMode(); } // else -> write message after server startup else { SharedEvents.OnAfterCoreStartupCompleted += () => ConsoleOutput.WriteLine(ConsoleType.Warn, "Can't restore fullscreen mode in this session. Console use default settings instead."); } } // Normal console window else { Point savedPosition = Settings.Default.ConsoleLocation; Size ConsoleSize = Settings.Default.ConsoleSize; // Console position saved -> check if valid after screen changes || set position if (savedPosition.X != -1 && savedPosition.Y != -1) { // Saved on not connected screen -> message after server startup if (!Screen.AllScreens.Any(screen => screen.Bounds.Contains(savedPosition))) { ConsoleUtils.SetWindowPos(ConsoleUtils.GetConsoleWindow(), 0, 0, 0, ConsoleSize.Width, ConsoleSize.Height, 1); SharedEvents.OnAfterCoreStartupCompleted += () => ConsoleOutput.WriteLine(ConsoleType.Warn, "Can't restore saved console location. Saved location was on disconnected screen. Console use default location instead."); } // Valid saved position -> restore else { ConsoleUtils.SetWindowPos(ConsoleUtils.GetConsoleWindow(), 0, Settings.Default.ConsoleLocation.X, Settings.Default.ConsoleLocation.Y, ConsoleSize.Width, ConsoleSize.Height, 1); } } } #endif // Prepare submodules ConsoleOutput.PrepareConsoleOutput(); ConsoleError.PrepareConsoleError(); ConsoleCommandHandler.PrepareConsoleCommands(); }
public static void ViewHelpInformations(string commandName) { ConsoleCommand command = ConsoleCommandHandler.GetConsoleCommand(commandName); // Not command found -> message & return. if (command == null) { ConsoleOutput.WriteLine(ConsoleType.Help, $"No console command found for ~w~{commandName}~;~."); return; } // Show command help string commandParameter = string.Join(", ", command.MethodInfo.GetParameters() .Select(info => $"~m~{info.ParameterType}~;~ {info.Name} " + $"~l~{(info.IsOptional ? $" = [{info.DefaultValue}] " : "")}~;~")); ConsoleOutput.WriteLine(ConsoleType.Help, $"Command: ~w~{command.Command}~;~\n" + $"Aliase: ~w~{string.Join(", ", command.CommandAliases)}\n" + $"Usage: ~w~{command.Command} {commandParameter}"); }