public static void Test() { Widget_Countdown widget = new Widget_Countdown(TimeSpan.FromSeconds(20), ANSI.CyanBright("Countdown")); Task.WaitAll(widget.Get_Task()); using (Widget_Prompt prompt = new Widget_Prompt("Press ANY key to exit.")) { prompt.Wait(); } Environment.Exit(0); }
/// <summary> /// Sets the progress being displayed to a new value /// </summary> /// <param name="Percent">Progress percentage in the [0.0 - 1.0] range</param> public void Set_Progress(double Percent) { lock (Line) { if (Equals(Disposed, 1)) { return; } if (!last_time.HasValue) { last_time = DateTime.UtcNow; LastPct = (float)Percent; } else { History.Enqueue(new Tuple <TimeSpan, float>(DateTime.UtcNow.Subtract(last_time.Value), (float)Percent - LastPct)); while (History.Count > MAX_HIST) { History.Dequeue(); } } Buffer.Clear(); Buffer.Append(string.Format(ANSI.Yellow("{0,6:#00.00}%") + ANSI.MagentaBright(" ["), Percent * 100f));// 9 chars // draw the active '=' portion of the bar const int ACTIVE_SPACE = PROG_BAR_WIDTH; double progSafe = Math.Min(1.0, Math.Max(0.0, Percent)); int active = (int)(progSafe * ACTIVE_SPACE); bool has_cap = active < ACTIVE_SPACE; string active_str = new string('=', active);// always draw an arrow head to cap the active portion of the bar UNLESS it would extend past the bars end if (has_cap) { active_str += ">"; } Buffer.Append(ANSI.CyanBright(active_str)); Buffer.Append(new string(' ', ACTIVE_SPACE - active_str.Length));// pad out the bar's unused space Buffer.Append(ANSI.MagentaBright("]")); Line.Set(Buffer.ToString()); } }