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

MorganKryze / ConsoleAppVisuals / 8142798391

04 Mar 2024 03:31PM UTC coverage: 84.112% (-1.1%) from 85.231%
8142798391

push

github

MorganKryze
🌟 can specify default of custom font | remove textstyler from core | add author, supported chars to config.yml files | add security on the import of fonts

896 of 1126 branches covered (79.57%)

Branch coverage included in aggregate %.

113 of 154 new or added lines in 4 files covered. (73.38%)

1 existing line in 1 file now uncovered.

1767 of 2040 relevant lines covered (86.62%)

380.16 hits per line

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

52.94
/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
    private TextStyler _styler;
25

26
    #endregion
27

28
    #region Properties
29
    /// <summary>
30
    ///
31
    /// </summary>
32
    public string[] StyledText => _styler.StyleTextToStringArray(_text);
18✔
33

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

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

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

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

55
    #region Constructor
56
    /// <summary>
57
    /// The constructor of the title.
58
    /// </summary>
59
    /// <param name="text">The text of the title.</param>
60
    /// <param name="margin">The margin of the title.</param>
61
    /// <param name="width">The width of the title (by default the width of the console).</param>
62
    /// <param name="align">The alignment of the title.</param>
63
    /// <param name="font">The font of the title.</param>
64
    /// <param name="fontPath">ATTENTION: fill this parameter only if you want to use a custom font (Font.Custom).</param>
65
    /// <remarks>
66
    /// For more information, refer to the following resources:
67
    /// <list type="bullet">
68
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
69
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
70
    /// </list>
71
    /// </remarks>
72
    public Title(
24✔
73
        string text,
24✔
74
        int margin = 1,
24✔
75
        int? width = null,
24✔
76
        TextAlignment align = TextAlignment.Center,
24✔
77
        Font font = Font.ANSI_Shadow,
24✔
78
        string? fontPath = null
24✔
79
    )
24✔
80
    {
81
        _text = text;
24✔
82
        _margin = margin;
24✔
83
        _width = width ?? Console.WindowWidth;
24!
84
        _align = align;
24✔
85
        _styler = new TextStyler(font, fontPath);
24✔
86
    }
24✔
87
    #endregion
88

89
    #region Methods
90
    /// <summary>
91
    /// This method updates the text of the title.
92
    /// </summary>
93
    /// <param name="text">The new text of the title.</param>
94
    /// <remarks>
95
    /// For more information, refer to the following resources:
96
    /// <list type="bullet">
97
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
98
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
99
    /// </list>
100
    /// </remarks>
101
    public void UpdateText(string text)
102
    {
103
        _text = text;
3✔
104
    }
3✔
105

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

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

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

170
    /// <summary>
171
    /// This method updates the font of the title.
172
    /// </summary>
173
    /// <param name="font">The new font of the title.</param>
174
    /// <param name="fontPath">ATTENTION: fill this parameter only if you want to use a custom font (Font.Custom).</param>
175
    public void UpdateFont(Font font, string? fontPath = null)
176
    {
NEW
177
        _styler = new TextStyler(font, fontPath);
×
NEW
178
    }
×
179

180
    /// <summary>
181
    /// This method is used to draw the title on the console.
182
    /// </summary>
183
    protected override void RenderElementActions()
184
    {
185
        Core.WritePositionedStyledText(StyledText, Line, _width, _margin, _align, false);
×
186
    }
×
187
    #endregion
188
}
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