forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleHostUserInterfaceProgress.cs
More file actions
177 lines (133 loc) · 3.99 KB
/
Copy pathConsoleHostUserInterfaceProgress.cs
File metadata and controls
177 lines (133 loc) · 3.99 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Management.Automation;
using Dbg = System.Management.Automation.Diagnostics;
namespace Microsoft.PowerShell
{
internal partial
class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInterface
{
/// <summary>
///
/// Called at the end of a prompt loop to take down any progress display that might have appeared and purge any
/// outstanding progress activity state.
///
/// </summary>
internal
void
ResetProgress()
{
// destroy the data structures representing outstanding progress records
// take down and destroy the progress display
if (_progPane != null)
{
Dbg.Assert(_pendingProgress != null, "How can you have a progress pane and no backing data structure?");
_progPane.Hide();
_progPane = null;
}
_pendingProgress = null;
}
/// <summary>
///
/// Invoked by ConsoleHostUserInterface.WriteProgress to update the set of outstanding activities for which
/// ProgressRecords have been received.
///
/// </summary>
private
void
HandleIncomingProgressRecord(Int64 sourceId, ProgressRecord record)
{
Dbg.Assert(record != null, "record should not be null");
if (_pendingProgress == null)
{
Dbg.Assert(_progPane == null, "If there is no data struct, there shouldn't be a pane, either.");
_pendingProgress = new PendingProgress();
}
_pendingProgress.Update(sourceId, record);
if (_progPane == null)
{
// This is the first time we've received a progress record. Create a pane to show it, and
// then show it.
_progPane = new ProgressPane(this);
}
_progPane.Show(_pendingProgress);
}
private
void
PreWrite()
{
if (_progPane != null)
{
_progPane.Hide();
}
}
private
void
PostWrite()
{
if (_progPane != null)
{
_progPane.Show();
}
}
private
void
PostWrite(string value)
{
PostWrite();
if (_parent.IsTranscribing)
{
try
{
_parent.WriteToTranscript(value);
}
catch (Exception e)
{
ConsoleHost.CheckForSevereException(e);
_parent.IsTranscribing = false;
}
}
}
private
void
PreRead()
{
if (_progPane != null)
{
_progPane.Hide();
}
}
private
void
PostRead()
{
if (_progPane != null)
{
_progPane.Show();
}
}
private
void
PostRead(string value)
{
PostRead();
if (_parent.IsTranscribing)
{
try
{
// Reads always terminate with the enter key, so add that.
_parent.WriteToTranscript(value + Crlf);
}
catch (Exception e)
{
ConsoleHost.CheckForSevereException(e);
_parent.IsTranscribing = false;
}
}
}
private ProgressPane _progPane = null;
private PendingProgress _pendingProgress = null;
}
} // namespace