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

MorganKryze / ConsoleAppVisuals / 7919257510

15 Feb 2024 04:37PM UTC coverage: 60.617% (+20.3%) from 40.338%
7919257510

push

github

MorganKryze
✅ some update

577 of 1044 branches covered (55.27%)

Branch coverage included in aggregate %.

1210 of 1904 relevant lines covered (63.55%)

243.34 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
    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 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 Getters and setters
51
    
52
    #endregion
53

54
    #region Constructor
55
    /// <summary>
56
    /// The natural constructor of the Embedded text.
57
    /// </summary>
58
    /// <param name="text">The text to display.</param>
59
    /// <param name="button">The text of the button.</param>
60
    /// <param name="align">The alignment of the Embedded text.</param>
61
    /// <param name="placement">The placement of the Embedded text element.</param>
62
    /// <param name="line">The line of the Embedded text.</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/Program.cs">Example Project</a></description></item>
68
    /// </list>
69
    /// </remarks>
70
    public EmbeddedText(
×
71
        List<string> text,
×
72
        string? button = null,
×
73
        TextAlignment align = TextAlignment.Left,
×
74
        Placement placement = Placement.TopCenter,
×
75
        int? line = null
×
76
    )
×
77
    {
78
        _text = text;
×
79
        _button = button ?? "Press [Enter] to continue";
×
80
        _align = align;
×
81
        _placement = placement;
×
82
        _line = Window.CheckLine(line) ?? Window.GetLineAvailable(placement);
×
83
        BuildText();
×
84
    }
×
85
    #endregion
86

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

104
    /// <summary>
105
    /// Inserts a line to the Embedded text.
106
    /// </summary>
107
    /// <param name="line">The line to insert.</param>
108
    /// <param name="index">The index where to insert the line.</param>
109
    /// <remarks>
110
    /// For more information, refer to the following resources:
111
    /// <list type="bullet">
112
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
113
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
114
    /// </list>
115
    /// </remarks>
116
    public void InsertLine(string line, int index)
117
    {
118
        _text.Insert(index, line);
×
119
    }
×
120

121
    /// <summary>
122
    /// Removes a line from the Embedded text.
123
    /// </summary>
124
    /// <param name="line">The line to remove.</param>
125
    /// <remarks>
126
    /// For more information, refer to the following resources:
127
    /// <list type="bullet">
128
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
129
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
130
    /// </list>
131
    /// </remarks>
132
    public void RemoveLine(string line)
133
    {
134
        _text.Remove(line);
×
135
    }
×
136

137
    /// <summary>
138
    /// Removes a line from the Embedded text.
139
    /// </summary>
140
    /// <param name="index">The index of the line to remove.</param>
141
    /// <remarks>
142
    /// For more information, refer to the following resources:
143
    /// <list type="bullet">
144
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
145
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/Program.cs">Example Project</a></description></item>
146
    /// </list>
147
    /// </remarks>
148
    public void RemoveLine(int index)
149
    {
150
        _text.RemoveAt(index);
×
151
    }
×
152

153
    /// <summary>
154
    /// Renders the Embedded text.
155
    /// </summary>
156
    [Visual]
157
    protected override void RenderElementActions()
158
    {
159
        BuildText();
160
        Core.WriteMultiplePositionedLines(
161
            false,
162
            _placement.ToTextAlignment(),
163
            false,
164
            _line,
165
            _textToDisplay!.ToArray()
166
        );
167
        Window.StopExecution();
168
        Window.DeactivateElement<EmbeddedText>();
169
    }
170

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