示例#1
0
        public static void ShowInformation(this PSHostRawUserInterface host, string caption, string message, int offsetX = 0, int offsetY = 3)
        {
            var pos = host.WindowPosition;
            var con = host.WindowSize;

            pos.X += offsetX;
            pos.Y += offsetY;

            string spacer = "  ";

            string[] text = new string[]
            {
                SB.Remove(0, SB.Length).Insert(0, ((char)32).ToString(), con.Width).ToString(),
                SB.Remove(0, SB.Length).Append(spacer).Append(caption)
                .Insert(caption.Length + spacer.Length, ((char)32).ToString(), (con.Width - caption.Length - spacer.Length)).ToString(),
                SB.Remove(0, SB.Length).Insert(0, ((char)32).ToString(), con.Width).ToString(),
                SB.Remove(0, SB.Length).Append(spacer).Append(message)
                .Insert(message.Length + spacer.Length, ((char)32).ToString(), (con.Width - message.Length - spacer.Length)).ToString(),
                SB.Remove(0, SB.Length).Insert(0, ((char)32).ToString(), con.Width).ToString()
            };

            var row = host.NewBufferCellArray(text, ConsoleColor.Black, ConsoleColor.DarkGray);

            host.SetBufferContents(pos, row);
        }
示例#2
0
        public static void PopHostUI(this PSHostRawUserInterface host)
        {
            host.BufferSize = HostBufferImage.BufferSize;
            host.SetBufferContents(HostBufferImage.WindowPosition, HostBufferImage.Buffer);

            host.CursorSize     = HostBufferImage.CursorSize;
            host.CursorPosition = HostBufferImage.CursorPosition;

            host.BackgroundColor = HostBufferImage.Background;
            host.ForegroundColor = HostBufferImage.Foreground;

            host.WindowTitle    = HostBufferImage.WindowTitle;
            host.WindowPosition = HostBufferImage.WindowPosition;
            host.WindowSize     = HostBufferImage.WindowSize;
        }
示例#3
0
        /// <summary>
        /// Flush the contents of the playfield buffer to the screen.
        /// </summary>
        /// <param name="sync">the number of millis between flushes</param>
        public void Flush(int sync)
        {
            if (sync > 0)
            {
                TimeSpan elapsed = DateTime.Now - flushtime;
                int      remain  = sync - (int)elapsed.TotalMilliseconds;
                if (remain > 0)
                {
                    System.Threading.Thread.Sleep(remain);
                }
            }
            DateTime thisflushtime = DateTime.Now;

            stats[nextstat++] = (thisflushtime - flushtime).TotalMilliseconds;
            nextstat          = (nextstat + 1) % stats.Length;
            if (nextstat == 0)
            {
                int sum = 0, num = 0;
                foreach (int n in stats)
                {
                    if (n > 0)
                    {
                        sum += n; num++;
                    }
                }
                if (num > 0)
                {
                    fps = (int)(1000.0 / (sum / num));
                }
            }
            if (showfps)
            {
                if (fps != lastfps || fpsimage == null)
                {
                    BufferCell[,] cells = ui.NewBufferCellArray(new string[] { fps + "fps" }, ConsoleColor.White, ConsoleColor.Black);
                    fpsimage            = new Image(cells, '\0', 0, 0);
                    lastfps             = fps;
                }
                DrawImage(fpsimage, Width - fpsimage.Width, 0);
            }
            flushtime = thisflushtime;
            ui.SetBufferContents(coord, buffer);
        }
示例#4
0
        protected override void EndProcessing()
        {
            PSHostRawUserInterface ui = Host.UI.RawUI;
            Size max = ui.MaxPhysicalWindowSize;

            if (w > max.Width || h > max.Height)
            {
                throw new InvalidOperationException(
                          string.Format("Console can not be bigger than {0}x{1}. Consider using a smaller font size.", max.Width, max.Height));
            }
            // ensure that the host console is big enough for our needs
            int bw = ui.BufferSize.Width;
            int bh = ui.BufferSize.Height;

            bw            = Math.Max(w, bw);
            bh            = Math.Max(h, bh);
            ui.BufferSize = new Size(bw, bh);
            ui.WindowSize = new Size(w, h);

            // now erase using current background colour (not sure how to call clear-host)
            ui.SetBufferContents(new Rectangle(0, 0, bw - 1, bh - 1),
                                 new BufferCell(' ', ui.ForegroundColor, ui.BackgroundColor, BufferCellType.Complete));
            ui.CursorPosition = new Coordinates(0, 0);
        }