Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
80 lines (71 loc) · 3.81 KB

File metadata and controls

80 lines (71 loc) · 3.81 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;
namespace TestPSReadLine
{
class Program
{
static void CauseCrash(ConsoleKeyInfo? key = null, object arg = null)
{
throw new Exception("intentional crash for test purposes");
}
[STAThread]
static void Main()
{
//Box(new List<string> {"abc", " def", "this is something coo"});
var iss = InitialSessionState.CreateDefault2();
var rs = RunspaceFactory.CreateRunspace(iss);
rs.Open();
Runspace.DefaultRunspace = rs;
PSConsoleReadLine.SetOptions(new SetPSReadlineOption
{
EditMode = EditMode.Emacs,
HistoryNoDuplicates = true,
});
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+LeftArrow"}, PSConsoleReadLine.ShellBackwardWord, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+RightArrow"}, PSConsoleReadLine.ShellNextWord, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"F4"}, PSConsoleReadLine.HistorySearchBackward, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"F5"}, PSConsoleReadLine.HistorySearchForward, "", "");
//PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+E"}, PSConsoleReadLine.EnableDemoMode, "", "");
//PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+D"}, PSConsoleReadLine.DisableDemoMode, "", "");
// PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+C"}, PSConsoleReadLine.CaptureScreen, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+P"}, PSConsoleReadLine.InvokePrompt, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+X"}, CauseCrash, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"F6"}, PSConsoleReadLine.PreviousLine, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"F7"}, PSConsoleReadLine.NextLine, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"F2"}, PSConsoleReadLine.ValidateAndAcceptLine, "", "");
PSConsoleReadLine.SetKeyHandler(new[] {"Enter"}, PSConsoleReadLine.AcceptLine, "", "");
EngineIntrinsics executionContext;
using (var ps = PowerShell.Create(RunspaceMode.CurrentRunspace))
{
executionContext =
ps.AddScript("$ExecutionContext").Invoke<EngineIntrinsics>().FirstOrDefault();
// This is a workaround to ensure the command analysis cache has been created before
// we enter into ReadLine. It's a little slow and infrequently needed, so just
// uncomment if you hit a hang, run it once, then comment it out again.
//ps.Commands.Clear();
//ps.AddCommand("Get-Command").Invoke();
}
while (true)
{
Console.Write("TestHostPS> ");
var line = PSConsoleReadLine.ReadLine(null, executionContext);
Console.WriteLine(line);
line = line.Trim();
if (line.Equals("exit"))
Environment.Exit(0);
if (line.Equals("cmd"))
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Windows});
if (line.Equals("emacs"))
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Emacs});
if (line.Equals("vi"))
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Vi});
if (line.Equals("nodupes"))
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {HistoryNoDuplicates = true});
}
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.