//public bool TopMost //{ // get { return _topMost; } // set { SetTopMost(value); } //} //private void SetLocation(IConsoleConfiguration consoleConfiguration) //{ // try // { // var hWnd = Process.GetCurrentProcess().MainWindowHandle; // Position position = null; // if (consoleConfiguration.StartPosition != null) // { // position = consoleConfiguration.StartPosition; // } // else if (consoleConfiguration.RememberStartPosition) // { // position = GetStoredPosition(); // //SubscribeToWindowMovement(hWnd); // } // if (position != null) // { // SetWidth(position); // SetHeight(position); // //NOTE: Do not send the window where it cannot be visible. For instance, a secondary screen that is no longer attached. // var monitors = GetMonitors(); // var monitor = VisibleOnMonitor(monitors, Offset(position, GetWindowRect())); // if (monitor != null) // { // //OutputEvent($"SetWindowPos {position.Left}:{position.Top}"); // ExecuteApiFunction(() => SetWindowPos(hWnd, IntPtr.Zero, position.Left, position.Top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW)); // } // else // { // OutputWarning("Console location is reset since it otherwise sould appear outside the visual field."); // } // //NOTE: This code will reposition the window at startup, the same way as a "scr reset" command will. // //For some reason the "SetWindowPos" does not act the same when run directly when the console starts as it does when the application has been running for a short while. // //Task.Run(() => // //{ // // var monitors = GetMonitors(); // // var monitor = VisibleOnMonitor(monitors, Offset(GetWindowRect(), position)); // // if (monitor != null) // // { // // System.Threading.Thread.Sleep(1000); // // SetWindowPos(hWnd, IntPtr.Zero, position.Left, position.Top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW); // // } // // else // // { // // OutputWarning("Console location is reset since it otherwise sould appear outside the visual field."); // // } // //}); // //System.Console.WriteLine($"set: {position.Left}:{position.Top} {hWnd}"); // } // } // catch (Exception exception) // { // OutputError(exception); // } //} //private void ExecuteApiFunction(Action apiCall) //{ // try // { // var pre = GetLastError(); // apiCall(); // var aft = GetLastError(); // if (aft != 0 && pre != aft) // { // OutputWarning($"Error {aft} when calling api method {apiCall.Method.Name}."); // } // } // catch (Exception exception) // { // OutputError(exception); // } //} //private RECT Offset(Position position, RECT rect) //{ // var height = rect.Bottom - rect.Top; // var width = rect.Right - rect.Left; // var rct = new RECT // { // Top = position.Top, // Left = position.Left, // Bottom = position.Top + height, // Right = position.Left + width, // }; // return rct; //} //private int? VisibleOnMonitor(List<RECT> monitors, RECT window) //{ // var index = 0; // foreach (var monitor in monitors) // { // if (window.Right >= monitor.Left && (window.Left <= monitor.Right && (window.Bottom >= monitor.Top && window.Top <= monitor.Bottom))) // { // return index; // } // index++; // } // return null; //} //private List<RECT> GetMonitors() //{ // var monitors = new List<RECT>(); // MonitorEnumProc callback = (IntPtr hDesktop, IntPtr hdc, ref RECT prect, int d) => { monitors.Add(prect); return true; }; // ExecuteApiFunction(() => EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, callback, 0)); // return monitors; //} //private Position GetCurrentPosition() //{ // var rct = GetWindowRect(); // return new Position(rct.Left, rct.Top, ConsoleManager.WindowWidth, ConsoleManager.WindowHeight, ConsoleManager.BufferWidth, ConsoleManager.BufferHeight); //} //private RECT GetWindowRect() //{ // var hWnd = Process.GetCurrentProcess().MainWindowHandle; // var rct = new RECT(); // ExecuteApiFunction(() => GetWindowRect(hWnd, out rct)); // //Trace.TraceInformation($"GetWindowRect {hWnd} {rct.Left}:{rct.Top}."); // //OutputEvent($"GetWindowRect {hWnd} {rct.Left}:{rct.Top}."); // //var wp = new WINDOWPLACEMENT(); // //GetWindowPlacement(hWnd, ref wp); // //ExecuteApiFunction(); // //System.Console.WriteLine($"get: {wp.rcNormalPosition.Left}:{wp.rcNormalPosition.Top}"); // return rct; //} //private Position GetStoredPosition() //{ // //try // //{ // // var val = Registry.GetSetting("StartPosition", Registry.RegistryHKey.CurrentUser, string.Empty); // // if (string.IsNullOrEmpty(val)) return null; // // var segments = val.Split('|'); // // var pos = segments[0].Split(':'); // // var wz = segments[1].Split(':'); // // var bz = segments[2].Split(':'); // // return new Position(int.Parse(pos[0]), int.Parse(pos[1]), int.Parse(wz[0]), int.Parse(wz[1]), int.Parse(bz[0]), int.Parse(bz[1])); // //} // //catch (Exception exception) // //{ // // OutputError(exception); // // return null; // //} // return null; //} //private void StoreCurrentPosition() //{ // //try // //{ // // var position = GetCurrentPosition(); // // var val = $"{position.Left}:{position.Top}|{position.Width}:{position.Height}|{position.BufferWidth}:{position.BufferHeight}"; // // //ConsoleManager.WriteLine(val); // // Trace.TraceInformation($"StoreCurrentPosition {val}."); // // Registry.SetSetting("StartPosition", val, Registry.RegistryHKey.CurrentUser); // //} // //catch (Exception exception) // //{ // // OutputError(exception); // //} //} //private void SetWidth(Position position) //{ // try // { // if (position.Width != null && position.Width.Value > 0) // ConsoleManager.WindowWidth = position.Width.Value; // if (position.BufferWidth != null) // ConsoleManager.BufferWidth = position.BufferWidth.Value; // else if (ConsoleManager.WindowWidth > 0) // ConsoleManager.BufferWidth = ConsoleManager.WindowWidth; // } // catch (Exception exception) // { // OutputError(exception); // } //} //private void SetHeight(Position position) //{ // try // { // if (position.Height != null) // ConsoleManager.WindowHeight = position.Height.Value; // if (position.BufferHeight != null) // ConsoleManager.BufferHeight = position.BufferHeight.Value; // } // catch (Exception exception) // { // OutputError(exception); // } //} private void SetColor(IConsoleConfiguration consoleConfiguration) { if (ConsoleManager.BackgroundColor == consoleConfiguration.BackgroundColor && ConsoleManager.ForegroundColor == consoleConfiguration.DefaultTextColor) { return; } ConsoleManager.BackgroundColor = consoleConfiguration.BackgroundColor; ConsoleManager.ForegroundColor = consoleConfiguration.DefaultTextColor; ConsoleManager.Clear(); }
private static void _cManager_AfterResize(ConsoleManager cManager) { _cManager.Title = Console.WindowWidth.ToString() + ',' + Console.WindowHeight; if (cManager.PanelHeight < (BHeight + 1) * 8 + 1 || cManager.PanelWidth < (BWidth + 1) * 8 + 1) { cManager.Clear(); Console.WriteLine("窗口大小过小,无法继续显示。"); Console.WriteLine("按任意键继续..."); Console.ReadKey(true); Environment.Exit(-1); } }
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) { _cManager.Clear(); _cManager.IsPaused = true; Console.Clear(); Console.WriteLine("测试结束,程序将在3秒后退出..."); Thread.Sleep(3 * 1000); _cManager.Exit(); Console.Clear(); Console.WriteLine("程序已退出。"); Environment.Exit(0); }
private static void CManager_AfterResize(ConsoleManager cManager) { if (cManager.PanelWidth <= 6 || cManager.PanelHeight <= 2) { cManager.Exit(); Console.Clear(); Console.WriteLine("窗口过小,程序中止。"); } cManager.Clear(); cManager.DrawPanel(0, 0, 0, cManager.PanelWidth - 1, ' ', ConsoleColor.Black, ConsoleColor.Gray); cManager.DrawPanel(0, 0, "Test Nano in CSharp"); cManager.DrawPanel(0, cManager.PanelWidth - "Provided by XIONG".Length, "Provided by XIONG"); cManager.Title = (cManager.PanelWidth + 1).ToString() + ',' + (cManager.PanelHeight + 1); int row = 1, col = -1; for (var i = 0; i < StringBuffer.Length; i++) { if (++col == cManager.PanelWidth) { row++; col = 0; } if (StringBuffer[i] == '\n') { row++; if (row > cManager.PanelHeight - 1) { cManager.SetCursorPosition(cManager.PanelHeight - 1, col); StringBuffer.Remove(i, StringBuffer.Length - i); return; } col = -1; } else if (row > cManager.PanelHeight - 1) { cManager.SetCursorPosition(cManager.PanelHeight - 1, cManager.PanelWidth - 1); StringBuffer.Remove(i, StringBuffer.Length - i); return; } else { cManager.DrawPanel(row, col, StringBuffer[i].ToString()); } } cManager.SetCursorPosition(row, col + 1); }
public void PrintMarket(IUser user, IMarket market) { ConsoleManager.Clear(); PrintMarketName(); List <IMarketAssetPrice> ordered = market.AssetPrices.OrderBy(x => x.Category).ToList(); string category = ""; PrintUserInfo(user); for (int i = 0; i < ordered.Count; i++) { if (ordered[i].Category != category) { ConsoleManager.WriteLine(); category = ordered[i].Category; ConsoleManager.WriteAligned("\n{0,20} => ", category); } ConsoleManager.WriteAligned("{0,15} ", $"{ordered[i].Name}: "); string key = ordered[i].Name.First().ToString().ToUpper() + ordered[i].Name.Substring(1); if (user.Wallet.Portfolio.ContainsKey(key)) { if (user.Wallet.Portfolio[key].Price < ordered[i].Price) { ConsoleManager.ChangeColor(ConsoleColor.Green); } else if (user.Wallet.Portfolio[key].Price > ordered[i].Price) { ConsoleManager.ChangeColor(ConsoleColor.Red); } } ConsoleManager.WriteAligned("{0,7 } ", $"${ordered[i].Price}"); ConsoleManager.ResetColor(); ConsoleManager.Write("| "); } ConsoleManager.WriteLine("\n"); }
public void PrintStartup() { ConsoleManager.Clear(); ConsoleManager.WriteLine(StreamManager.ReadAllText(welcomeScreen), ConsoleColor.Blue); }
public override void Handle(string[] args) { ConsoleManager.Clear(); }