Code
·
50 lines
·
2160 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
50namespace InteractiveReadLine.Formatting
{
/// <summary>
/// Holds all of the information to present to the user through the view. The LineDisplayState is typically
/// the output of a formatter, and is intended to be written directly to an IReadLineProvider
/// </summary>
/// <remarks>
/// The LineDisplayState is the output of a formatter, which is a function which receives either a LineState or
/// a TokenizedLine object and returns a LineDisplayState.
///
/// A LineDisplayState consists of three pieces of formatted text in addition to a cursor position. The
/// actual presentation of the LineDisplayState is the responsibility of the IReadLineProvider, but it is
/// typically intended that the prefix be written first (like a prompt), the line body in the middle, and
/// the suffix at the end. The cursor should be located as an offset of the first character of the line
/// body in order to visually align with how the ReadLineHandler will perform character inserts.
///
/// Text and word wrapping is left up to the provider.
/// </remarks>
public class LineDisplayState
{
public LineDisplayState(FormattedText prefix, FormattedText lineBody, FormattedText suffix, int cursor)
{
Prefix = prefix;
LineBody = lineBody;
Suffix = suffix;
Cursor = cursor;
}
/// <summary>
/// Gets the prefix, which is displayed before the line body
/// </summary>
public FormattedText Prefix { get; }
/// <summary>
/// Gets the line's body text, which is typically the text entered by the user or some representation of
/// what they've entered
/// </summary>
public FormattedText LineBody { get; }
/// <summary>
/// Gets the position of the cursor as an integer offset from the beginning of the LineBody
/// </summary>
public int Cursor { get; }
/// <summary>
/// Gets the suffix, which is displayed after the line body
/// </summary>
public FormattedText Suffix { get; }
}
}