@@ -23,14 +23,10 @@ public partial class Terminal : AuthComponentBase, IDisposable
23
23
private int _lastCursorIndex ;
24
24
private ScriptingShell _shell ;
25
25
26
- private string _terminalOpenClass ;
27
-
28
26
private ElementReference _terminalInput ;
27
+ private string _terminalOpenClass ;
29
28
private ElementReference _terminalWindow ;
30
29
31
- [ Inject ]
32
- private IModalService ModalService { get ; set ; }
33
-
34
30
[ Inject ]
35
31
private IClientAppState AppState { get ; set ; }
36
32
@@ -40,9 +36,6 @@ public partial class Terminal : AuthComponentBase, IDisposable
40
36
[ Inject ]
41
37
private IDataService DataService { get ; set ; }
42
38
43
- [ Inject ]
44
- private ILogger < Terminal > Logger { get ; set ; }
45
-
46
39
private string InputText
47
40
{
48
41
get => _inputText ;
@@ -59,6 +52,33 @@ private string InputText
59
52
[ Inject ]
60
53
private IJsInterop JsInterop { get ; set ; }
61
54
55
+ [ Inject ]
56
+ private ILogger < Terminal > Logger { get ; set ; }
57
+
58
+ [ Inject ]
59
+ private IModalService ModalService { get ; set ; }
60
+ private EventCallback < SavedScript > RunQuickScript =>
61
+ EventCallback . Factory . Create < SavedScript > ( this , async script =>
62
+ {
63
+ var scriptRun = new ScriptRun ( )
64
+ {
65
+ OrganizationID = User . OrganizationID ,
66
+ RunAt = Time . Now ,
67
+ SavedScriptId = script . Id ,
68
+ RunOnNextConnect = false ,
69
+ Initiator = User . UserName ,
70
+ InputType = ScriptInputType . OneTimeScript
71
+ } ;
72
+
73
+ scriptRun . Devices = DataService . GetDevices ( AppState . DevicesFrameSelectedDevices ) ;
74
+
75
+ await DataService . AddScriptRun ( scriptRun ) ;
76
+
77
+ await CircuitConnection . RunScript ( AppState . DevicesFrameSelectedDevices , script . Id , scriptRun . Id , ScriptInputType . OneTimeScript , false ) ;
78
+
79
+ ToastService . ShowToast ( $ "Running script on { scriptRun . Devices . Count } devices.") ;
80
+ } ) ;
81
+
62
82
[ Inject ]
63
83
private IToastService ToastService { get ; set ; }
64
84
@@ -69,13 +89,6 @@ public void Dispose()
69
89
GC . SuppressFinalize ( this ) ;
70
90
}
71
91
72
- protected override async Task OnInitializedAsync ( )
73
- {
74
- await base . OnInitializedAsync ( ) ;
75
- CircuitConnection . MessageReceived += CircuitConnection_MessageReceived ;
76
- AppState . PropertyChanged += AppState_PropertyChanged ;
77
- }
78
-
79
92
protected override Task OnAfterRenderAsync ( bool firstRender )
80
93
{
81
94
if ( firstRender )
@@ -85,6 +98,12 @@ protected override Task OnAfterRenderAsync(bool firstRender)
85
98
return base . OnAfterRenderAsync ( firstRender ) ;
86
99
}
87
100
101
+ protected override async Task OnInitializedAsync ( )
102
+ {
103
+ await base . OnInitializedAsync ( ) ;
104
+ CircuitConnection . MessageReceived += CircuitConnection_MessageReceived ;
105
+ AppState . PropertyChanged += AppState_PropertyChanged ;
106
+ }
88
107
private void ApplyCompletion ( PwshCommandCompletion completion )
89
108
{
90
109
try
@@ -172,25 +191,6 @@ private void EvaluateInputKeypress(KeyboardEventArgs ev)
172
191
}
173
192
}
174
193
175
- private void ShowTerminalHelp ( )
176
- {
177
- ModalService . ShowModal ( "Terminal Help" , new [ ]
178
- {
179
- "Enter terminal commands that will execute on all selected devices." ,
180
-
181
- "Tab completion is available for PowerShell Core (PSCore) and Windows PowerShell (WinPS). Tab and Shift + Tab " +
182
- "will cycle through potential completions. Ctrl + Space will show all available completions." ,
183
-
184
- "If more than one devices is selected, the first device's file system will be used when " +
185
- "auto-completing file and directory paths." ,
186
-
187
- "PowerShell Core is cross-platform and is available on all client operating systems. Bash is available " +
188
- "on Windows 10 if WSL (Windows Subsystem for Linux) is installed." ,
189
-
190
- "Note: The first PS Core command or tab completion takes a few moments while the service is " +
191
- "starting on the remote device."
192
- } ) ;
193
- }
194
194
private async Task EvaluateKeyDown ( KeyboardEventArgs ev )
195
195
{
196
196
if ( ! ev . Key . Equals ( "Tab" , StringComparison . OrdinalIgnoreCase ) &&
@@ -238,6 +238,11 @@ private async Task EvaluateKeyDown(KeyboardEventArgs ev)
238
238
239
239
await ShowAllCompletions ( ) ;
240
240
}
241
+ else if ( ev . CtrlKey && ev . Key . Equals ( "q" , StringComparison . OrdinalIgnoreCase ) )
242
+ {
243
+ AppState . TerminalLines . Clear ( ) ;
244
+ AppState . InvokePropertyChanged ( nameof ( AppState . TerminalLines ) ) ;
245
+ }
241
246
}
242
247
243
248
private async Task GetNextCompletion ( bool forward )
@@ -261,17 +266,6 @@ private async Task ShowAllCompletions()
261
266
262
267
await CircuitConnection . GetPowerShellCompletions ( _lastCompletionInput , _lastCursorIndex , CompletionIntent . ShowAll , false ) ;
263
268
}
264
- private void ToggleTerminalOpen ( )
265
- {
266
- if ( string . IsNullOrWhiteSpace ( _terminalOpenClass ) )
267
- {
268
- _terminalOpenClass = "open" ;
269
- }
270
- else
271
- {
272
- _terminalOpenClass = string . Empty ;
273
- }
274
- }
275
269
276
270
private async Task ShowQuickScripts ( )
277
271
{
@@ -288,7 +282,7 @@ private async Task ShowQuickScripts()
288
282
return ;
289
283
}
290
284
291
-
285
+
292
286
void showModal ( RenderTreeBuilder builder )
293
287
{
294
288
builder . OpenComponent < QuickScriptsSelector > ( 0 ) ;
@@ -300,28 +294,38 @@ void showModal(RenderTreeBuilder builder)
300
294
await ModalService . ShowModal ( "Quick Scripts" , showModal ) ;
301
295
}
302
296
303
- private EventCallback < SavedScript > RunQuickScript =>
304
- EventCallback . Factory . Create < SavedScript > ( this , async script =>
297
+ private void ShowTerminalHelp ( )
298
+ {
299
+ ModalService . ShowModal ( "Terminal Help" , new [ ]
305
300
{
306
- var scriptRun = new ScriptRun ( )
307
- {
308
- OrganizationID = User . OrganizationID ,
309
- RunAt = Time . Now ,
310
- SavedScriptId = script . Id ,
311
- RunOnNextConnect = false ,
312
- Initiator = User . UserName ,
313
- InputType = ScriptInputType . OneTimeScript
314
- } ;
301
+ "Enter terminal commands that will execute on all selected devices." ,
315
302
316
- scriptRun . Devices = DataService . GetDevices ( AppState . DevicesFrameSelectedDevices ) ;
303
+ "Tab completion is available for PowerShell Core (PSCore) and Windows PowerShell (WinPS). Tab and Shift + Tab " +
304
+ "will cycle through potential completions. Ctrl + Space will show all available completions." ,
317
305
318
- await DataService . AddScriptRun ( scriptRun ) ;
306
+ "If more than one devices is selected, the first device's file system will be used when " +
307
+ "auto-completing file and directory paths." ,
319
308
320
- await CircuitConnection . RunScript ( AppState . DevicesFrameSelectedDevices , script . Id , scriptRun . Id , ScriptInputType . OneTimeScript , false ) ;
309
+ "PowerShell Core is cross-platform and is available on all client operating systems. Bash is available " +
310
+ "on Windows 10 if WSL (Windows Subsystem for Linux) is installed." ,
321
311
322
- ToastService . ShowToast ( $ "Running script on { scriptRun . Devices . Count } devices.") ;
323
- } ) ;
312
+ "Up and down arrow keys will cycle through terminal input history. Ctrl + Q will clear the output window." ,
324
313
314
+ "Note: The first PS Core command or tab completion takes a few moments while the service is " +
315
+ "starting on the remote device."
316
+ } ) ;
317
+ }
318
+ private void ToggleTerminalOpen ( )
319
+ {
320
+ if ( string . IsNullOrWhiteSpace ( _terminalOpenClass ) )
321
+ {
322
+ _terminalOpenClass = "open" ;
323
+ }
324
+ else
325
+ {
326
+ _terminalOpenClass = string . Empty ;
327
+ }
328
+ }
325
329
private bool TryMatchShellShortcuts ( )
326
330
{
327
331
var currentText = InputText ? . Trim ( ) ? . ToLower ( ) ;
0 commit comments