MongoExtensions / src / InteractiveReadLine / KeyBehaviors / IKeyBehaviorTarget.cs
Code · 73 lines · 2861 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73using System;
using System.Text;
using InteractiveReadLine.Formatting;
using InteractiveReadLine.Tokenizing;

namespace InteractiveReadLine.KeyBehaviors
{
    /// <summary>
    /// Provides the unified target of key behaviors, exposing a standard amount of state which the
    /// behavior method can act upon
    /// </summary>
    public interface IKeyBehaviorTarget
    {
        /// <summary>
        /// Gets the ConsoleKey which was received for the current request
        /// </summary>
        ConsoleKeyInfo ReceivedKey { get; }

        /// <summary>
        /// Gets the string buffer which holds the current readline text which is being edited by the user
        /// </summary>
        StringBuilder TextBuffer { get; }

        /// <summary>
        /// Gets or sets the integer position of the cursor. Cannot be set before the beginning or after the end
        /// of the TextBuffer.
        /// </summary>
        int CursorPosition { get; set; }

        /// <summary>
        /// Invokes the auto-complete's "next" functionality, which substitutes in the next suggestion
        /// </summary>
        void AutoCompleteNext();

        /// <summary>
        /// Invokes the auto-complete's "previous" functionality, which substitutes in the previous suggestion
        /// </summary>
        void AutoCompletePrevious();

        /// <summary>
        /// Inserts text to the console out in the spot where the current read line input is, then
        /// immediately re-displays the line input on the next row. Use this to interrupt the user with a message or
        /// information while the ReadLine is still being used
        /// </summary>
        /// <param name="text">The text to write to the console, a newline char will be added automatically</param>
        void InsertText(FormattedText text);

        /// <summary>
        /// If the handler configuration has a tokenizer, this will get the tokenization result of the text
        /// buffer
        /// </summary>
        /// <returns>Returns null if there is no tokenizer, otherwise a Tokens result</returns>
        TokenizedLine GetTextTokens();

        /// <summary>
        /// Invokes the history's "next" functionality, which replaces the entire line with the next element
        /// in the history collection. If the last history element has been reached, the previously entered
        /// LineState will be reverted.
        /// </summary>
        void HistoryNext();

        /// <summary>
        /// Invokes the history's "previous" functionality, which replaces the entire line with the previous
        /// element in the history collection.
        /// </summary>
        void HistoryPrevious();

        /// <summary>
        /// Tells the readline handler to finish this line of input and return it
        /// </summary>
        void Finish();
    }
}