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

MorganKryze / ConsoleAppVisuals / 7993638304

pending completion
7993638304

push

github

MorganKryze
📖 add files and contributing recommendation

827 of 916 branches covered (90.28%)

Branch coverage included in aggregate %.

1676 of 1694 relevant lines covered (98.94%)

104.0 hits per line

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

95.65
/src/ConsoleAppVisuals/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;
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/Program.cs">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 readonly int _width;
23
    private readonly TextAlignment _align;
24
    #endregion
25

26
    #region Properties
27
    /// <summary>
28
    /// 
29
    /// </summary>
30
    public string[] StyledText => Core.StyleText(_text);
60✔
31
    /// <summary>
32
    /// The placement of the title.
33
    /// </summary>
34
    public override Placement Placement => Placement.TopCenterFullWidth;
72✔
35

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

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

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

76
    #region Methods
77
    /// <summary>
78
    /// This method updates the text of the title.
79
    /// </summary>
80
    /// <param name="text">The new text of the title.</param>
81
    /// <remarks>
82
    /// For more information, refer to the following resources:
83
    /// <list type="bullet">
84
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
85
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
86
    /// </list>
87
    /// </remarks>
88
    public void UpdateText(string text)
89
    {
90
        _text = text;
3✔
91
    }
3✔
92

93
    /// <summary>
94
    /// This method updates the margin of the title.
95
    /// </summary>
96
    /// <param name="margin">The new margin of the title.</param>
97
    /// <remarks>
98
    /// For more information, refer to the following resources:
99
    /// <list type="bullet">
100
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
101
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
102
    /// </list>
103
    /// </remarks>
104
    public void UpdateMargin(int margin)
105
    {
106
        _margin = margin;
3✔
107
    }
3✔
108

109
    /// <summary>
110
    /// This method is used to draw the title on the console.
111
    /// </summary>
112
    protected override void RenderElementActions()
113
    {
114
        Core.WritePositionedStyledText(StyledText, 0, _width, _margin, _align, false);
9✔
115
    }
9✔
116
    #endregion
117
}
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