예제 #1
0
        private PSConsoleReadLine()
        {
            _mockableMethods = this;

            _captureKeys = false;
            _savedKeys = new Queue<ConsoleKeyInfo>();
            _demoStrings = new HistoryQueue<string>(100);
            _demoMode = false;

            SetDefaultWindowsBindings();

            _buffer = new StringBuilder(8 * 1024);
            _statusBuffer = new StringBuilder(256);
            _savedCurrentLine = new HistoryItem();
            _queuedKeys = new Queue<ConsoleKeyInfo>();

            _pushedEditGroupCount = new Stack<int>();

            _options = new PSConsoleReadlineOptions();

            _history = new HistoryQueue<HistoryItem>(Options.MaximumHistoryCount);
            _currentHistoryIndex = 0;

            _killIndex = -1;    // So first add indexes 0.
            _killRing = new List<string>(Options.MaximumKillRingCount);
        }
예제 #2
0
        private PSConsoleReadLine()
        {
            _mockableMethods = this;
            _console         = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                ? PlatformWindows.OneTimeInit(this)
                : new VirtualTerminal();
            _charMap = new DotNetCharMap();

            _buffer           = new StringBuilder(8 * 1024);
            _statusBuffer     = new StringBuilder(256);
            _savedCurrentLine = new HistoryItem();
            _queuedKeys       = new Queue <ConsoleKeyInfo>();

            string hostName = null;

            // This works mostly by luck - we're not doing anything to guarantee the constructor for our
            // singleton is called on a thread with a runspace, but it is happening by coincidence.
            using (var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
            {
                try
                {
                    ps.AddCommand("Get-Variable").AddParameter("Name", "host").AddParameter("ValueOnly");
                    var     results = ps.Invoke();
                    dynamic host    = results.Count == 1 ? results[0] : null;
                    if (host != null)
                    {
                        hostName = host.Name as string;
                    }
                }
                catch
                {
                }
            }
            if (hostName == null)
            {
                hostName = "PSReadLine";
            }
            _options = new PSConsoleReadLineOptions(hostName);
            SetDefaultBindings(_options.EditMode);
        }
예제 #3
0
        private PSConsoleReadLine()
        {
            _mockableMethods = this;
            _console         = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                ? PlatformWindows.OneTimeInit(this)
                : new VirtualTerminal();
            _charMap = new DotNetCharMap();

            _buffer           = new StringBuilder(8 * 1024);
            _statusBuffer     = new StringBuilder(256);
            _savedCurrentLine = new HistoryItem();
            _queuedKeys       = new Queue <PSKeyInfo>();

            // Initialize this event handler early because it could be used by PowerShell
            // Editor Services before 'DelayedOneTimeInitialize' runs.
            _forceEventWaitHandle = new AutoResetEvent(false);

            string hostName = null;

            // This works mostly by luck - we're not doing anything to guarantee the constructor for our
            // singleton is called on a thread with a runspace, but it is happening by coincidence.
            using (var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
            {
                try
                {
                    var    results = ps.AddScript("$Host").Invoke <PSHost>();
                    PSHost host    = results.Count == 1 ? results[0] : null;
                    hostName = host?.Name;
                }
                catch
                {
                }
            }
            if (hostName == null)
            {
                hostName = "PSReadLine";
            }
            _options = new PSConsoleReadLineOptions(hostName);
            SetDefaultBindings(_options.EditMode);
        }
예제 #4
0
        private PSConsoleReadLine()
        {
            _mockableMethods = this;

            _captureKeys = false;
            _savedKeys   = new Queue <ConsoleKeyInfo>();
            _demoStrings = new HistoryQueue <string>(100);
            _demoMode    = false;

            SetDefaultWindowsBindings();

            _buffer           = new StringBuilder(8 * 1024);
            _statusBuffer     = new StringBuilder(256);
            _savedCurrentLine = new HistoryItem();
            _queuedKeys       = new Queue <ConsoleKeyInfo>();

            string hostName = null;

            try
            {
                var ps = PowerShell.Create(RunspaceMode.CurrentRunspace)
                         .AddCommand("Get-Variable").AddParameter("Name", "host").AddParameter("ValueOnly");
                var     results = ps.Invoke();
                dynamic host    = results.Count == 1 ? results[0] : null;
                if (host != null)
                {
                    hostName = host.Name as string;
                }
            }
            catch
            {
            }
            if (hostName == null)
            {
                hostName = "PSReadline";
            }
            _options = new PSConsoleReadlineOptions(hostName);
        }
예제 #5
0
        private PSConsoleReadLine()
        {
            _mockableMethods = this;

            _captureKeys = false;
            _savedKeys = new Queue<ConsoleKeyInfo>();
            _demoStrings = new HistoryQueue<string>(100);
            _demoMode = false;

            SetDefaultWindowsBindings();

            _buffer = new StringBuilder(8 * 1024);
            _statusBuffer = new StringBuilder(256);
            _savedCurrentLine = new HistoryItem();
            _queuedKeys = new Queue<ConsoleKeyInfo>();

            string hostName = null;
            try
            {
                var ps = PowerShell.Create(RunspaceMode.CurrentRunspace)
                    .AddCommand("Get-Variable").AddParameter("Name", "host").AddParameter("ValueOnly");
                var results = ps.Invoke();
                dynamic host = results.Count == 1 ? results[0] : null;
                if (host != null)
                {
                    hostName = host.Name as string;
                }
            }
            catch
            {
            }
            if (hostName == null)
            {
                hostName = "PSReadline";
            }
            _options = new PSConsoleReadlineOptions(hostName);
        }