// todo Implement PromtUser method // todo Implement ShowNotification/overload for AskUser method // todo Add overload taking string[] param for multiple-row message // todo Add param for more display positions (center, top-left etc..) /// <summary> /// Shows one-row long message /// </summary> /// <param name="message"></param> /// <param name="brush"></param> /// <returns></returns> public CancellationTokenSource ShowNotification(string message, PaintBrush brush) { CancellationTokenSource cts = new CancellationTokenSource(); Task.Run(() => { Canvas notificationCanvas = new Canvas { Width = message.Length + 4, Height = 5, RenderPosition = RenderPosition.TopLeft }; // render brush.RenderCanvas(notificationCanvas); for (int i = 0; i < message.Length; i++) { brush.Render( notificationCanvas, new Position(notificationCanvas.CenterXPosition - (int)Math.Ceiling(message.Length / 2.0) + i, 1), message[i]); } // wait for cancelation WaitHandle.WaitAll(new[] { cts.Token.WaitHandle }); // derender brush.DerenderCanvas(notificationCanvas); }, cts.Token); return(cts); }
// todo Implement PromtUser method // todo Implement ShowNotification/overload for AskUser method // todo Add overload taking string[] param for multiple-row message // todo Add param for more display positions (center, top-left etc..) /// <summary> /// Shows one-row long message /// </summary> /// <param name="message"></param> /// <param name="brush"></param> /// <param name="slowWrite"></param> /// <returns></returns> public CancellationTokenSource ShowNotification(string message, PaintBrush brush, bool slowWrite = false) { CancellationTokenSource cts = new CancellationTokenSource(); Task.Run(() => { Canvas notificationCanvas = new Canvas { Width = message.Length + 5, Height = 5, RenderPosition = RenderPosition.TopLeft }; // render lock (consoleGuardian) { brush.RenderCanvas(notificationCanvas); } lock (consoleGuardian) { if (slowWrite) { for (int i = 0; i < message.Length; i++) { brush.Render( notificationCanvas, new Position(notificationCanvas.CenterXPosition - (int)Math.Ceiling(message.Length / 2.0) + i, 1), message[i]); } } else { notificationCanvas.SetCursorPosition(notificationCanvas.CenterXPosition - (int)Math.Ceiling(message.Length / 2.0), 1); Console.Write(message); } } // wait for cancelation WaitHandle.WaitAll(new[] { cts.Token.WaitHandle }); // derender lock (consoleGuardian) { brush.DerenderCanvas(notificationCanvas); } }, cts.Token); return(cts); }