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

MorganKryze / ConsoleAppVisuals / 8114215569

01 Mar 2024 04:29PM UTC coverage: 85.767% (-9.3%) from 95.093%
8114215569

push

github

MorganKryze
🤖 moved to publish

865 of 1072 branches covered (80.69%)

Branch coverage included in aggregate %.

1708 of 1928 relevant lines covered (88.59%)

273.5 hits per line

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

52.17
/src/ConsoleAppVisuals/elements/static_elements/Title.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 title 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 Title : Element
18
{
19
    #region Fields
20
    private string _text;
21
    private int _margin;
22
    private int _width;
23
    private TextAlignment _align;
24
    #endregion
25

26
    #region Properties
27
    /// <summary>
28
    ///
29
    /// </summary>
30
    public string[] StyledText => Core.StyleText(_text);
18✔
31

32
    /// <summary>
33
    /// The placement of the title.
34
    /// </summary>
35
    public override Placement Placement => Placement.TopCenterFullWidth;
6✔
36

37
    /// <summary>
38
    /// The height of the title.
39
    /// </summary>
40
    public override int Height => StyledText.Length + _margin * 2;
12✔
41

42
    /// <summary>
43
    /// The width of the title.
44
    /// </summary>
45
    public override int Width => _width;
27✔
46

47
    /// <summary>
48
    /// The line of the title.
49
    /// </summary>
50
    public override int Line => 0;
6✔
51
    #endregion
52

53
    #region Constructor
54
    /// <summary>
55
    /// The constructor of the title.
56
    /// </summary>
57
    /// <param name="text">The text of the title.</param>
58
    /// <param name="margin">The margin of the title.</param>
59
    /// <param name="width">The width of the title (by default the width of the console).</param>
60
    /// <param name="align">The alignment of the title.</param>
61
    /// <remarks>
62
    /// For more information, refer to the following resources:
63
    /// <list type="bullet">
64
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
65
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
66
    /// </list>
67
    /// </remarks>
68
    public Title(
24✔
69
        string text,
24✔
70
        int margin = 1,
24✔
71
        int? width = null,
24✔
72
        TextAlignment align = TextAlignment.Center
24✔
73
    )
24✔
74
    {
75
        _text = text;
24✔
76
        _margin = margin;
24✔
77
        _width = width ?? Console.WindowWidth;
24!
78
        _align = align;
24✔
79
    }
24✔
80
    #endregion
81

82
    #region Methods
83
    /// <summary>
84
    /// This method updates the text of the title.
85
    /// </summary>
86
    /// <param name="text">The new text of the title.</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/">Example Project</a></description></item>
92
    /// </list>
93
    /// </remarks>
94
    public void UpdateText(string text)
95
    {
96
        _text = text;
3✔
97
    }
3✔
98

99
    /// <summary>
100
    /// This method updates the margin of the title.
101
    /// </summary>
102
    /// <param name="margin">The new margin of the title.</param>
103
    /// <exception cref="ArgumentOutOfRangeException">The margin must be between 0 and the half of the console height.</exception>
104
    /// <remarks>
105
    /// For more information, refer to the following resources:
106
    /// <list type="bullet">
107
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
108
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
109
    /// </list>
110
    /// </remarks>
111
    public void UpdateMargin(int margin)
112
    {
113
        if (margin < 0 || margin > Console.WindowHeight / 2)
3!
114
        {
115
            throw new ArgumentOutOfRangeException(
×
116
                nameof(margin),
×
117
                "The margin must be between 0 and the half of the console height."
×
118
            );
×
119
        }
120
        _margin = margin;
3✔
121
    }
3✔
122

123
    /// <summary>
124
    /// This method updates the width of the title.
125
    /// </summary>
126
    /// <param name="width">The new width of the title.</param>
127
    /// <exception cref="ArgumentOutOfRangeException">The width must be between 0 and the console width.</exception>
128
    /// <remarks>
129
    /// For more information, refer to the following resources:
130
    /// <list type="bullet">
131
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
132
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
133
    /// </list>
134
    /// </remarks>
135
    public void UpdateWidth(int width)
136
    {
137
        if (width < 0 || width > Console.WindowWidth)
×
138
        {
139
            throw new ArgumentOutOfRangeException(
×
140
                nameof(width),
×
141
                "The width must be between 0 and the console width."
×
142
            );
×
143
        }
144
        _width = width;
×
145
    }
×
146

147
    /// <summary>
148
    /// This method updates the alignment of the title.
149
    /// </summary>
150
    /// <param name="align">The new alignment of the title.</param>
151
    /// <remarks>
152
    /// For more information, refer to the following resources:
153
    /// <list type="bullet">
154
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
155
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
156
    /// </list>
157
    /// </remarks>
158
    public void UpdateAlignment(TextAlignment align)
159
    {
160
        _align = align;
×
161
    }
×
162

163
    /// <summary>
164
    /// This method is used to draw the title on the console.
165
    /// </summary>
166
    protected override void RenderElementActions()
167
    {
168
        Core.WritePositionedStyledText(StyledText, Line, _width, _margin, _align, false);
×
169
    }
×
170
    #endregion
171
}
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