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

MorganKryze / ConsoleAppVisuals / 7473998763

10 Jan 2024 11:06AM UTC coverage: 37.669% (+1.7%) from 35.959%
7473998763

push

github

MorganKryze
🤖 (ci and docs) remove obsolete attribute from coverage

365 of 1034 branches covered (0.0%)

Branch coverage included in aggregate %.

750 of 1926 relevant lines covered (38.94%)

157.53 hits per line

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

0.0
/src/ConsoleAppVisuals/elements/interactive/EmbeddedText.cs
1
/*
2
    MIT License 2023 MorganKryze
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 basic properties of an embedded text.
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 EmbeddedText : InteractiveElement<string>
18
{
19
    #region Fields
20
    private readonly List<string> _text;
21
    private readonly string _button;
22
    private readonly TextAlignment _align;
23
    private readonly Placement _placement;
24
    private readonly int _line;
25
    private List<string>? _textToDisplay;
26
    #endregion
27

28
    #region Properties
29
    /// <summary>
30
    /// The position of the Embedded text.
31
    /// </summary>
32
    public override Placement Placement => _placement;
×
33

34
    /// <summary>
35
    /// The Line of the Embedded text.
36
    /// </summary>
37
    public override int Line => _line;
×
38

39
    /// <summary>
40
    /// The height of the Embedded text.
41
    /// </summary>
42
    public override int Height => _textToDisplay!.Count;
×
43

44
    /// <summary>
45
    /// The width of the Embedded text.
46
    /// </summary>
47
    public override int Width => _textToDisplay!.Max((string s) => s.Length) - 8;
×
48
    #endregion
49

50
    #region Constructor
51
    /// <summary>
52
    /// The natural constructor of the Embedded text.
53
    /// </summary>
54
    /// <param name="text">The text to display.</param>
55
    /// <param name="button">The text of the button.</param>
56
    /// <param name="align">The alignment of the Embedded text.</param>
57
    /// <param name="placement">The placement of the Embedded text element.</param>
58
    /// <param name="line">The line of the Embedded text.</param>
59
    /// <remarks>
60
    /// For more information, refer to the following resources:
61
    /// <list type="bullet">
62
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
63
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
64
    /// </list>
65
    /// </remarks>
66
    public EmbeddedText(
×
67
        List<string> text,
×
68
        string? button = null,
×
69
        TextAlignment align = TextAlignment.Left,
×
70
        Placement placement = Placement.TopCenter,
×
71
        int? line = null
×
72
    )
×
73
    {
74
        _text = text;
×
75
        _button = button ?? "Press [Enter] to continue";
×
76
        _align = align;
×
77
        _placement = placement;
×
78
        _line = Window.CheckLine(line) ?? Window.GetLineAvailable(placement);
×
79
        BuildText();
×
80
    }
×
81
    #endregion
82

83
    #region Methods
84
    /// <summary>
85
    /// Adds a line to the Embedded text.
86
    /// </summary>
87
    /// <param name="line">The line to add.</param>
88
    /// <remarks>
89
    /// For more information, refer to the following resources:
90
    /// <list type="bullet">
91
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
92
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
93
    /// </list>
94
    /// </remarks>
95
    public void AddLine(string line)
96
    {
97
        _text.Add(line);
×
98
    }
×
99

100
    /// <summary>
101
    /// Inserts a line to the Embedded text.
102
    /// </summary>
103
    /// <param name="line">The line to insert.</param>
104
    /// <param name="index">The index where to insert the line.</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/Program.cs">Example Project</a></description></item>
110
    /// </list>
111
    /// </remarks>
112
    public void InsertLine(string line, int index)
113
    {
114
        _text.Insert(index, line);
×
115
    }
×
116

117
    /// <summary>
118
    /// Removes a line from the Embedded text.
119
    /// </summary>
120
    /// <param name="line">The line to remove.</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/Program.cs">Example Project</a></description></item>
126
    /// </list>
127
    /// </remarks>
128
    public void RemoveLine(string line)
129
    {
130
        _text.Remove(line);
×
131
    }
×
132

133
    /// <summary>
134
    /// Removes a line from the Embedded text.
135
    /// </summary>
136
    /// <param name="index">The index of the line to remove.</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/Program.cs">Example Project</a></description></item>
142
    /// </list>
143
    /// </remarks>
144
    public void RemoveLine(int index)
145
    {
146
        _text.RemoveAt(index);
×
147
    }
×
148

149
    /// <summary>
150
    /// Renders the Embedded text.
151
    /// </summary>
152
    protected override void RenderElementActions()
153
    {
154
        BuildText();
×
155
        Core.WriteMultiplePositionedLines(
×
156
            false,
×
157
            _placement.ToTextAlignment(),
×
158
            false,
×
159
            _line,
×
160
            _textToDisplay!.ToArray()
×
161
        );
×
162
        Window.StopExecution();
×
163
        Window.DeactivateElement<EmbeddedText>();
×
164
    }
×
165

166
    private void BuildText()
167
    {
168
        var maxLength = _text.Max((string s) => s.Length);
×
169
        _textToDisplay = new List<string>();
×
170
        foreach (var line in _text)
×
171
        {
172
            var lineToDisplay = "│ ";
×
173
            switch (_align)
×
174
            {
175
                case TextAlignment.Center:
176
                    int totalPadding = maxLength - line.Length;
×
177
                    int padLeft = totalPadding / 2;
×
178
                    lineToDisplay += line.PadLeft(line.Length + padLeft).PadRight(maxLength);
×
179
                    break;
×
180
                case TextAlignment.Left:
181
                    lineToDisplay += line.PadRight(maxLength);
×
182
                    break;
×
183
                case TextAlignment.Right:
184
                    lineToDisplay += line.PadLeft(maxLength);
×
185
                    break;
186
            }
187
            lineToDisplay += " │";
×
188
            _textToDisplay.Add(lineToDisplay);
×
189
        }
190
        _textToDisplay.Insert(0, "┌" + new string('─', maxLength + 2) + "┐");
×
191
        _textToDisplay.Add("│ " + new string(' ', maxLength) + " │");
×
192
        _textToDisplay.Add(
×
193
            "│ "
×
194
                + "".PadRight(maxLength - _button.Length - 2)
×
195
                + Core.NEGATIVE_ANCHOR
×
196
                + " "
×
197
                + _button
×
198
                + " "
×
199
                + Core.NEGATIVE_ANCHOR
×
200
                + " │"
×
201
        );
×
202
        _textToDisplay.Add("└" + new string('─', maxLength + 2) + "┘");
×
203
    }
×
204
    #endregion
205
}
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