• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MorganKryze / ConsoleAppVisuals / 7473998763

10 Jan 2024 11:06AM UTC coverage: 37.669% (+1.7%) from 35.959%
7473998763

push

github

MorganKryze
🤖 (ci and docs) remove obsolete attribute from coverage

365 of 1034 branches covered (0.0%)

Branch coverage included in aggregate %.

750 of 1926 relevant lines covered (38.94%)

157.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ConsoleAppVisuals/elements/FakeLoadingBar.cs
1
/*
2
    MIT License 2023 MorganKryze
3
    For full license information, please visit: https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/LICENSE
4
*/
5
namespace ConsoleAppVisuals;
6

7
/// <summary>
8
/// Defines the loading bar of the console window.
9
/// </summary>
10
/// <remarks>
11
/// For more information, refer to the following resources:
12
/// <list type="bullet">
13
/// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
14
/// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
15
/// </list>
16
/// </remarks>
17
public class FakeLoadingBar : Element
18
{
19
    #region Fields
20
    private string _text;
21
    private readonly Placement _placement;
22
    private readonly int _processDuration;
23
    private readonly int _additionalDuration;
24
    private readonly int _line;
25
    #endregion
26

27
    #region Constants
28
    private const char LOADING_BAR_CHAR = 'â–ˆ';
29
    #endregion
30

31
    #region Properties
32
    /// <summary>
33
    /// The line of the loading bar in the console.
34
    /// </summary>
35
    /// <remarks>We add 2 because so the loading bar does not overlap with the title.</remarks>
36
    public override int Line => _line;
×
37

38
    /// <summary>
39
    /// The height of the loading bar.
40
    /// </summary>
41
    /// <remarks>One line for the text,one line for the space between and one line for the progress.</remarks>
42
    public override int Height => 3;
×
43

44
    /// <summary>
45
    /// The width of the loading bar.
46
    /// </summary>
47
    public override int Width => _text.Length;
×
48
    #endregion
49

50
    #region Constructor
51
    /// <summary>
52
    /// The natural constructor of the loading bar.
53
    /// </summary>
54
    /// <param name="text">The text of the loading bar.</param>
55
    /// <param name="placement">The placement of the loading bar.</param>
56
    /// <param name="line">The line of the loading bar.</param>
57
    /// <param name="processDuration">The duration of the loading bar.</param>
58
    /// <param name="additionalDuration">The additional duration of the loading bar at the end.</param>
59
    /// <remarks>
60
    /// For more information, refer to the following resources:
61
    /// <list type="bullet">
62
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
63
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
64
    /// </list>
65
    /// </remarks>
66
    public FakeLoadingBar(
×
67
        string text = "[ Loading ...]",
×
68
        Placement placement = Placement.TopCenter,
×
69
        int? line = null,
×
70
        int processDuration = 2000,
×
71
        int additionalDuration = 1000
×
72
    )
×
73
    {
74
        _text = text[..Math.Min(text.Length, Console.WindowWidth - 1)];
×
75
        _placement = placement;
×
76
        _line = Window.CheckLine(line) ?? Window.GetLineAvailable(placement);
×
77
        _processDuration = processDuration;
×
78
        _additionalDuration = additionalDuration;
×
79
    }
×
80
    #endregion
81

82
    #region Methods
83
    /// <summary>
84
    /// This method is used to update the text of the loading bar.
85
    /// </summary>
86
    /// <param name="text">The new text of the loading bar.</param>
87
    /// <remarks>
88
    /// For more information, refer to the following resources:
89
    /// <list type="bullet">
90
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
91
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
92
    /// </list>
93
    /// </remarks>
94
    public void UpdateText(string text)
95
    {
96
        _text = text;
×
97
    }
×
98

99
    /// <summary>
100
    /// This method is used to draw the loading bar on the console.
101
    /// </summary>
102
    protected override void RenderElementActions()
103
    {
104
        Core.WritePositionedString(_text, _placement.ToTextAlignment(), false, _line, false);
×
105
        StringBuilder loadingBar = new();
×
106
        for (int j = 0; j < _text.Length; j++)
×
107
        {
108
            loadingBar.Append(LOADING_BAR_CHAR);
×
109
        }
110
        Core.WriteContinuousString(
×
111
            loadingBar.ToString(),
×
112
            _line + 2,
×
113
            false,
×
114
            _processDuration,
×
115
            _additionalDuration,
×
116
            Width,
×
117
            default,
×
118
            false
×
119
        );
×
120
        Window.DeactivateElement(this);
×
121
    }
×
122
    #endregion
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc