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

MorganKryze / ConsoleAppVisuals / 8119668611

02 Mar 2024 02:13AM UTC coverage: 85.188% (-9.9%) from 95.086%
8119668611

push

github

MorganKryze
🤖 update action to node 20

866 of 1080 branches covered (80.19%)

Branch coverage included in aggregate %.

1699 of 1931 relevant lines covered (87.99%)

272.46 hits per line

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

22.22
/src/ConsoleAppVisuals/models/InteractiveElement.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.Models;
6

7
/// <summary>
8
/// Defines the basic properties of an console element.
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 abstract class InteractiveElement<TResponse> : Element
18
{
19
    #region Properties
20
    /// <summary>
21
    /// Whether the element is interactive or not.
22
    /// </summary>
23
    public sealed override bool IsInteractive { get; } = true;
594✔
24

25
    /// <summary>
26
    /// The maximum number of this element that can be drawn on the console. As an interactive element, the value is 1.
27
    /// </summary>
28
    public sealed override int MaxNumberOfThisElement { get; } = 1;
468✔
29

30
    /// <summary>
31
    ///
32
    /// </summary>
33
    public event EventHandler<InteractionEventArgs<TResponse>>? EndOfInteractionEvent;
34

35
    /// <summary>
36
    /// The response of the user.
37
    /// </summary>
38
    protected InteractionEventArgs<TResponse>? _interactionResponse;
39
    #endregion
40

41
    #region Methods
42
    /// <summary>
43
    /// Sets the response of the user in the attribute field.
44
    /// </summary>
45
    /// <param name="sender">The sender of the event.</param>
46
    /// <param name="e">The response of the user.</param>
47
    protected void SetInteractionResponse(object? sender, InteractionEventArgs<TResponse> e)
48
    {
49
        _interactionResponse = e;
×
50
    }
×
51

52
    /// <summary>
53
    /// Triggers the EndOfInteractionEvent event.
54
    /// </summary>
55
    /// <param name="sender">The sender of the event.</param>
56
    /// <param name="e">The response of the user.</param>
57
    [Visual]
58
    protected void SendResponse(object? sender, InteractionEventArgs<TResponse> e)
59
    {
60
        EndOfInteractionEvent?.Invoke(sender, e);
61
    }
62

63
    /// <summary>
64
    /// Returns the response of the user after an interaction.
65
    /// </summary>
66
    /// <returns>Null if the user has not interacted with the element, otherwise the response of the user.</returns>
67
    /// <remarks>
68
    /// This sample shows how to use the <see cref="GetResponse"/> method using the var keyword:
69
    /// <code>
70
    /// var response = element.GetResponse();
71
    /// </code>
72
    /// For more information, refer to the following resources:
73
    /// <list type="bullet">
74
    /// <item><description><a href="https://morgankryze.github.io/ConsoleAppVisuals/">Documentation</a></description></item>
75
    /// <item><description><a href="https://github.com/MorganKryze/ConsoleAppVisuals/blob/main/example/">Example Project</a></description></item>
76
    /// </list>
77
    /// </remarks>
78
    [Visual]
79
    public InteractionEventArgs<TResponse>? GetResponse()
80
    {
81
        return _interactionResponse;
82
    }
83

84
    /// <summary>
85
    /// This method is used to set options before drawing the element on the console.
86
    /// </summary>
87
    protected sealed override void RenderOptionsBeforeHand()
88
    {
89
        EndOfInteractionEvent += SetInteractionResponse;
×
90
    }
×
91

92
    /// <summary>
93
    /// This method is used to set options after drawing the element on the console.
94
    /// </summary>
95
    protected sealed override void RenderOptionsAfterHand()
96
    {
97
        EndOfInteractionEvent -= SetInteractionResponse;
×
98
        Window.DeactivateElement(this);
×
99
    }
×
100
    #endregion
101
}
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