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

MorganKryze / ConsoleAppVisuals / 8158191062

05 Mar 2024 02:47PM UTC coverage: 86.165% (+0.9%) from 85.231%
8158191062

push

github

MorganKryze
📖 (readme) update roadmap

931 of 1144 branches covered (81.38%)

Branch coverage included in aggregate %.

1803 of 2029 relevant lines covered (88.86%)

412.64 hits per line

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

100.0
/src/ConsoleAppVisuals/elements/static_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.Elements;
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/">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 Constants
25
    private const int TEXT_HEIGHT = 1;
26
    #endregion
27

28
    #region Properties
29
    /// <summary>
30
    /// The placement of the header.
31
    /// </summary>
32
    public override Placement Placement => Placement.TopCenterFullWidth;
4✔
33

34
    /// <summary>
35
    /// The height of the header.
36
    /// </summary>
37
    public override int Height => TEXT_HEIGHT + _margin;
2✔
38

39
    /// <summary>
40
    /// The width of the header.
41
    /// </summary>
42
    public override int Width => Console.WindowWidth;
2✔
43

44
    /// <summary>
45
    /// The text of the header.
46
    /// </summary>
47
    public (string, string, string) Text => _text;
16✔
48

49
    /// <summary>
50
    /// The margin of the header.
51
    /// </summary>
52
    public int Margin => _margin;
8✔
53
    #endregion
54

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

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

101
    /// <summary>
102
    /// This method is used to update the text in the center of the header.
103
    /// </summary>
104
    /// <param name="centerText">The new text in the center of the header.</param>
105
    /// <remarks>
106
    /// For more information, refer to the following resources:
107
    /// <list type="bullet">
108
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
109
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
110
    /// </list>
111
    /// </remarks>
112
    public void UpdateCenterText(string centerText)
113
    {
114
        _text.Item2 = centerText;
4✔
115
    }
4✔
116

117
    /// <summary>
118
    /// This method is used to update the text on the right of the header.
119
    /// </summary>
120
    /// <param name="rightText">The new text on the right of the header.</param>
121
    /// <remarks>
122
    /// For more information, refer to the following resources:
123
    /// <list type="bullet">
124
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
125
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
126
    /// </list>
127
    /// </remarks>
128
    public void UpdateRightText(string rightText)
129
    {
130
        _text.Item3 = rightText;
4✔
131
    }
4✔
132

133
    /// <summary>
134
    /// This method is used to update the margin of the header.
135
    /// </summary>
136
    /// <param name="margin">The new margin of the header.</param>
137
    /// <remarks>
138
    /// For more information, refer to the following resources:
139
    /// <list type="bullet">
140
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
141
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
142
    /// </list>
143
    /// </remarks>
144
    public void UpdateMargin(int margin)
145
    {
146
        _margin = margin;
2✔
147
    }
2✔
148

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