-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathProtocolPSHostUserInterface.cs
123 lines (109 loc) · 4.34 KB
/
ProtocolPSHostUserInterface.cs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.PowerShell.EditorServices.Console;
using Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
using Microsoft.PowerShell.EditorServices.Protocol.Server;
using Microsoft.PowerShell.EditorServices.Utility;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Host
{
internal class ProtocolPSHostUserInterface : EditorServicesPSHostUserInterface
{
#region Private Fields
private IMessageSender messageSender;
private OutputDebouncer outputDebouncer;
#endregion
#region Constructors
/// <summary>
/// Creates a new instance of the ConsoleServicePSHostUserInterface
/// class with the given IConsoleHost implementation.
/// </summary>
/// <param name="powerShellContext"></param>
public ProtocolPSHostUserInterface(
PowerShellContext powerShellContext,
IMessageSender messageSender,
ILogger logger)
: base(powerShellContext, new SimplePSHostRawUserInterface(logger), logger)
{
this.messageSender = messageSender;
this.outputDebouncer = new OutputDebouncer(messageSender);
}
public void Dispose()
{
// TODO: Need a clear API path for this
// Make sure remaining output is flushed before exiting
if (this.outputDebouncer != null)
{
this.outputDebouncer.FlushAsync().Wait();
this.outputDebouncer = null;
}
}
#endregion
/// <summary>
/// Writes output of the given type to the user interface with
/// the given foreground and background colors. Also includes
/// a newline if requested.
/// </summary>
/// <param name="outputString">
/// The output string to be written.
/// </param>
/// <param name="includeNewLine">
/// If true, a newline should be appended to the output's contents.
/// </param>
/// <param name="outputType">
/// Specifies the type of output to be written.
/// </param>
/// <param name="foregroundColor">
/// Specifies the foreground color of the output to be written.
/// </param>
/// <param name="backgroundColor">
/// Specifies the background color of the output to be written.
/// </param>
public override void WriteOutput(
string outputString,
bool includeNewLine,
OutputType outputType,
ConsoleColor foregroundColor,
ConsoleColor backgroundColor)
{
// TODO: This should use a synchronous method!
this.outputDebouncer.InvokeAsync(
new OutputWrittenEventArgs(
outputString,
includeNewLine,
outputType,
foregroundColor,
backgroundColor)).Wait();
}
/// <summary>
/// Sends a progress update event to the user.
/// </summary>
/// <param name="sourceId">The source ID of the progress event.</param>
/// <param name="progressDetails">The details of the activity's current progress.</param>
protected override void UpdateProgress(
long sourceId,
ProgressDetails progressDetails)
{
}
protected override Task<string> ReadCommandLineAsync(CancellationToken cancellationToken)
{
// This currently does nothing because the "evaluate" request
// will cancel the current prompt and execute the user's
// script selection.
return new TaskCompletionSource<string>().Task;
}
protected override InputPromptHandler OnCreateInputPromptHandler()
{
return new ProtocolInputPromptHandler(this.messageSender, this, this, this.Logger);
}
protected override ChoicePromptHandler OnCreateChoicePromptHandler()
{
return new ProtocolChoicePromptHandler(this.messageSender, this, this, this.Logger);
}
}
}