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

MorganKryze / ConsoleAppVisuals / 7919257510

15 Feb 2024 04:37PM UTC coverage: 60.617% (+20.3%) from 40.338%
7919257510

push

github

MorganKryze
✅ some update

577 of 1044 branches covered (55.27%)

Branch coverage included in aggregate %.

1210 of 1904 relevant lines covered (63.55%)

243.34 hits per line

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

88.89
/src/ConsoleAppVisuals/elements/Header.cs
1
/*
2
    GNU GPL License 2024 MorganKryze(Yann Vidamment)
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 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;
3✔
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;
3!
35

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

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

47
    #region Getters and Setters
48
    /// <summary>
49
    /// The getter and setter of the text of the header.
50
    /// </summary>
51
    public (string, string, string) Text
52
    {
53
        get => _text;
24✔
54
        set => _text = value;
×
55
    }
56

57
    /// <summary>
58
    /// The getter and setter of the margin of the header.
59
    /// </summary>
60
    public int Margin
61
    {
62
        get => _margin;
9✔
63
        set => _margin = value;
×
64
    }
65
    #endregion
66

67
    #region Constructor
68
    /// <summary>
69
    /// The natural constructor of the header.
70
    /// </summary>
71
    /// <param name="leftText">The text on the left of the header.</param>
72
    /// <param name="centerText">The text in the center of the header.</param>
73
    /// <param name="rightText">The text on the right of the header.</param>
74
    /// <param name="margin">The margin of the header.</param>
75
    /// <remarks>
76
    /// For more information, refer to the following resources:
77
    /// <list type="bullet">
78
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
79
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
80
    /// </list>
81
    /// </remarks>
82
    public Header(
39✔
83
        string leftText = "Header Left",
39✔
84
        string centerText = "Header Center",
39✔
85
        string rightText = "Header Right",
39✔
86
        int margin = 1
39✔
87
    )
39✔
88
    {
89
        _text.Item1 = leftText;
39✔
90
        _text.Item2 = centerText;
39✔
91
        _text.Item3 = rightText;
39✔
92
        _margin = margin;
39✔
93
    }
39✔
94
    #endregion
95

96
    #region Methods
97
    /// <summary>
98
    /// This method is used to update the text on the left of the header.
99
    /// </summary>
100
    /// <param name="leftText">The new text on the left of the header.</param>
101
    /// <remarks>
102
    /// For more information, refer to the following resources:
103
    /// <list type="bullet">
104
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
105
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
106
    /// </list>
107
    /// </remarks>
108
    public void UpdateLeftText(string leftText)
109
    {
110
        _text.Item1 = leftText;
6✔
111
    }
6✔
112

113
    /// <summary>
114
    /// This method is used to update the text in the center of the header.
115
    /// </summary>
116
    /// <param name="centerText">The new text in the center of the header.</param>
117
    /// <remarks>
118
    /// For more information, refer to the following resources:
119
    /// <list type="bullet">
120
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
121
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
122
    /// </list>
123
    /// </remarks>
124
    public void UpdateCenterText(string centerText)
125
    {
126
        _text.Item2 = centerText;
6✔
127
    }
6✔
128

129
    /// <summary>
130
    /// This method is used to update the text on the right of the header.
131
    /// </summary>
132
    /// <param name="rightText">The new text on the right of the header.</param>
133
    /// <remarks>
134
    /// For more information, refer to the following resources:
135
    /// <list type="bullet">
136
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
137
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
138
    /// </list>
139
    /// </remarks>
140
    public void UpdateRightText(string rightText)
141
    {
142
        _text.Item3 = rightText;
6✔
143
    }
6✔
144

145
    /// <summary>
146
    /// This method is used to render the header on the console.
147
    /// </summary>
148
    [Visual]
149
    protected override void RenderElementActions()
150
    {
151
        Core.WritePositionedString(Text.BannerToString(), TextAlignment.Center, true, Line, false);
152
    }
153
    #endregion
154
}
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

© 2026 Coveralls, Inc