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

MorganKryze / ConsoleAppVisuals / 8157925255

05 Mar 2024 02:28PM UTC coverage: 86.165%. Remained the same
8157925255

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%)

618.96 hits per line

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

66.67
/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 TextAlignment _align;
23
    private TextStyler _styler;
24

25
    #endregion
26

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

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

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

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

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

54
    #region Constructor
55
    /// <summary>
56
    /// The constructor of the title.
57
    /// </summary>
58
    /// <param name="text">The text of the title.</param>
59
    /// <param name="margin">The margin of the title.</param>
60
    /// <param name="align">The alignment of the title.</param>
61
    /// <param name="font">The font of the title.</param>
62
    /// <param name="fontPath">ATTENTION: fill this parameter only if you want to use a custom font (Font.Custom).</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 Title(
24✔
71
        string text,
24✔
72
        int margin = 1,
24✔
73
        TextAlignment align = TextAlignment.Center,
24✔
74
        Font font = Font.ANSI_Shadow,
24✔
75
        string? fontPath = null
24✔
76
    )
24✔
77
    {
78
        _text = text;
24✔
79
        _margin = margin;
24✔
80
        _align = align;
24✔
81
        _styler = new TextStyler(font, fontPath);
24✔
82
    }
24✔
83
    #endregion
84

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

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

126
    /// <summary>
127
    /// This method updates the alignment of the title.
128
    /// </summary>
129
    /// <param name="align">The new alignment of the title.</param>
130
    /// <remarks>
131
    /// For more information, refer to the following resources:
132
    /// <list type="bullet">
133
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
134
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
135
    /// </list>
136
    /// </remarks>
137
    public void UpdateAlignment(TextAlignment align)
138
    {
139
        _align = align;
×
140
    }
×
141

142
    /// <summary>
143
    /// This method updates the font of the title.
144
    /// </summary>
145
    /// <param name="font">The new font of the title.</param>
146
    /// <param name="fontPath">ATTENTION: fill this parameter only if you want to use a custom font (Font.Custom).</param>
147
    public void UpdateFont(Font font, string? fontPath = null)
148
    {
149
        _styler = new TextStyler(font, fontPath);
×
150
    }
×
151

152
    /// <summary>
153
    /// This method is used to draw the title on the console.
154
    /// </summary>
155
    protected override void RenderElementActions()
156
    {
157
        Core.WritePositionedStyledText(StyledText, Line, Width, _margin, _align, false);
×
158
    }
×
159
    #endregion
160
}
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