• 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/Header.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 header 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 Header : Element
18
{
19
    #region Fields
20
    private (string, string, string) _text;
21
    private readonly int _margin;
22
    #endregion
23

24
    #region Properties
25
    /// <summary>
26
    /// The placement of the header.
27
    /// </summary>
28
    public override Placement Placement => Placement.TopCenterFullWidth;
×
29

30
    /// <summary>
31
    /// The line of the header in the console.
32
    /// </summary>
33
    /// <remarks>We add 2 because so the header does not overlap with the title.</remarks>
34
    public override int Line => Window.GetVisibleElement<Title>()?.Height ?? default;
×
35

36
    /// <summary>
37
    /// The height of the header.
38
    /// </summary>
39
    public override int Height => 1 + _margin;
×
40

41
    /// <summary>
42
    /// The width of the header.
43
    /// </summary>
44
    public override int Width => Console.WindowWidth;
×
45
    #endregion
46

47
    #region Constructor
48
    /// <summary>
49
    /// The natural constructor of the header.
50
    /// </summary>
51
    /// <param name="leftText">The text on the left of the header.</param>
52
    /// <param name="centerText">The text in the center of the header.</param>
53
    /// <param name="rightText">The text on the right of the header.</param>
54
    /// <param name="margin">The margin of the header.</param>
55
    /// <remarks>
56
    /// For more information, refer to the following resources:
57
    /// <list type="bullet">
58
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
59
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
60
    /// </list>
61
    /// </remarks>
62
    public Header(
×
63
        string leftText = "Header Left",
×
64
        string centerText = "Header Center",
×
65
        string rightText = "Header Right",
×
66
        int margin = 1
×
67
    )
×
68
    {
69
        _text.Item1 = leftText;
×
70
        _text.Item2 = centerText;
×
71
        _text.Item3 = rightText;
×
72
        _margin = margin;
×
73
    }
×
74
    #endregion
75

76
    #region Methods
77
    /// <summary>
78
    /// This method is used to update the text on the left of the header.
79
    /// </summary>
80
    /// <param name="leftText">The new text on the left of the header.</param>
81
    /// <remarks>
82
    /// For more information, refer to the following resources:
83
    /// <list type="bullet">
84
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
85
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
86
    /// </list>
87
    /// </remarks>
88
    public void UpdateLeftText(string leftText)
89
    {
90
        _text.Item1 = leftText;
×
91
    }
×
92

93
    /// <summary>
94
    /// This method is used to update the text in the center of the header.
95
    /// </summary>
96
    /// <param name="centerText">The new text in the center of the header.</param>
97
    /// <remarks>
98
    /// For more information, refer to the following resources:
99
    /// <list type="bullet">
100
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
101
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
102
    /// </list>
103
    /// </remarks>
104
    public void UpdateCenterText(string centerText)
105
    {
106
        _text.Item2 = centerText;
×
107
    }
×
108

109
    /// <summary>
110
    /// This method is used to update the text on the right of the header.
111
    /// </summary>
112
    /// <param name="rightText">The new text on the right of the header.</param>
113
    /// <remarks>
114
    /// For more information, refer to the following resources:
115
    /// <list type="bullet">
116
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
117
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
118
    /// </list>
119
    /// </remarks>
120
    public void UpdateRightText(string rightText)
121
    {
122
        _text.Item3 = rightText;
×
123
    }
×
124

125
    /// <summary>
126
    /// This method is used to render the header on the console.
127
    /// </summary>
128
    protected override void RenderElementActions()
129
    {
130
        Core.WritePositionedString(_text.BannerToString(), TextAlignment.Center, true, Line, false);
×
131
    }
×
132
    #endregion
133
}
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