コード例 #1
0
ファイル: Progress.cs プロジェクト: pha3z/PerrysNetConsole
 /// <summary>
 /// Clear progress bar
 /// </summary>
 protected void Clear()
 {
     if (this.StartY < CoEx.RealCursorY)
     {
         CoEx.Seek(0, (int)(this.StartY - CoEx.RealCursorY), true);
     }
     else
     {
         CoEx.Seek(0, null, true);
     }
 }
コード例 #2
0
        public void Start()
        {
            var  message     = this.Message;
            bool writtenonce = false;

            this.CurrentThread = new Thread(() =>
            {
                try
                {
                    while (this.StopPending == false)
                    {
                        if (writtenonce)
                        {
                            CoEx.Seek(1, null);
                            CoEx.Write("{0}", this.Color, this.Animation.NextFrame());
                        }
                        else
                        {
                            this.Clear();
                            CoEx.Write(" {0} ", this.Color, this.Animation.NextFrame());
                            CoEx.Write(" {0} ", message);
                            writtenonce = true;
                        }

                        if (this.StopPending)
                        {
                            break;
                        }
                        Thread.Sleep(100);
                    }

                    this.Clear();
                    CoEx.Write(" {0} ", this.Color, LoadAnimation.ANIMATIONCOMPLETE);
                    CoEx.Write(" {0} ", message);
                    Thread.Sleep(500);
                }
                catch { }
                finally
                {
                    if (writtenonce)
                    {
                        this.Clear();
                    }
                }
            });

            this.CurrentThread.Start();
            this.IsRunning   = true;
            this.StopPending = false;

            CoEx.CursorVisible = false;
        }
コード例 #3
0
ファイル: Progress.cs プロジェクト: pha3z/PerrysNetConsole
        /// <summary>
        /// Draw the progress
        /// </summary>
        /// <param name="force">force drawing, ignore dirty state</param>
        protected void Draw(bool force)
        {
            double     cpercentage, crecentpercentage;
            bool       cisdirty, cismessages;
            List <Msg> cmsg;

            lock (this.instancelock)
            {
                cpercentage       = this.Percentage;
                crecentpercentage = this.RecentPercentage;
                cisdirty          = this.IsDirty;
                cismessages       = this.IsUsingMessages;
                cmsg = this.MessageQueue.ToList();

                this.RecentPercentage = this.Percentage;
                this.MessageQueue.Clear();
            }

            //--> Draw bar
            if (this.IsWaiting || cisdirty || force)
            {
                if (this.IsInitialized)
                {
                    CoEx.Seek(0, null, true);
                }

                // Draw messages
                if (cmsg.Count > 0)
                {
                    if (this.IsInitialized && this.IsUsingMessages)
                    {
                        CoEx.Seek(0, -1, true);
                    }

                    foreach (var msg in cmsg)
                    {
                        this.PrintMessage(msg);
                    }

                    this.IsUsingMessages = true;
                    CoEx.WriteLine();
                }

                string percstr    = this.IsWaiting ? PERCUNKNOWN : string.Format(PERCFORMAT, cpercentage);
                string loadingstr = string.Format(" {0} ", cpercentage >= 100 ? LoadAnimation.ANIMATIONCOMPLETE : this.Animation.NextFrame().ToString());
                int    barmax     = CoEx.Width - loadingstr.Length - 1 - percstr.Length - BARBEGIN.Length - BAREND.Length - 1;

                CoEx.Write(loadingstr, CoEx.ColorTitlePrimary);
                CoEx.Write(" " + percstr + BARBEGIN);

                if (this.IsWaiting)
                {
                    // Draw waiting animation
                    double progresslength   = Math.Round(barmax * WAITBARLENGTHPERC / 100.0);
                    int    whitespacelength = (int)(barmax - progresslength);

                    this.WaitingPadding += this.WaitingIncrement;
                    if (this.WaitingPadding > whitespacelength || this.WaitingPadding < 0)
                    {
                        this.WaitingIncrement = this.WaitingIncrement > 0 ? -1 : 1;
                        this.WaitingPadding  += this.WaitingIncrement;
                    }

                    string beforeprogress = "".PadLeft(this.WaitingPadding, BAREMPTY);
                    string progress       = "".PadLeft((int)progresslength, BARPROGRESS);
                    string afterprogress  = "".PadLeft(whitespacelength - this.WaitingPadding, BAREMPTY);

                    CoEx.Write(beforeprogress);
                    CoEx.Write(progress, CoEx.ColorTitleSecondary.Invert());
                    CoEx.Write(afterprogress);
                }
                else
                {
                    // Draw progress bar
                    int fill    = (int)Math.Round(barmax * crecentpercentage / 100.0);
                    int newfill = (int)Math.Round(barmax * (cpercentage - crecentpercentage) / 100.0);

                    string progress    = "".PadLeft(fill, BARPROGRESS);
                    string newprogress = "".PadLeft(newfill, BARPROGRESS);
                    string empty       = "".PadLeft(barmax - (fill + newfill), BAREMPTY);

                    CoEx.Write(progress, CoEx.ColorTitleSecondary.Invert());
                    CoEx.Write(newprogress, CoEx.ColorTitlePrimary.Invert());
                    CoEx.Write(empty);
                }

                CoEx.Write(BAREND);
                this.IsInitialized = true;

                // Set dirty status to false
                if (this.IsDirty)
                {
                    lock (this.instancelock)
                    {
                        this.IsDirty = false;
                    }
                }
            }
            //--> No action nessasary, only draw load indicator
            else if (cpercentage < 100)
            {
                string loadingstr = string.Format("{0}", cpercentage >= 100 ? LoadAnimation.ANIMATIONCOMPLETE : this.Animation.NextFrame().ToString());
                CoEx.Seek(1, null);
                CoEx.Write(loadingstr, CoEx.ColorTitlePrimary);
            }
        }
コード例 #4
0
 protected void Clear()
 {
     CoEx.Seek(0, CoEx.CursorY, true);
 }