Example #1
0
        static PSConsoleReadLine()
        {
            _singleton = new PSConsoleReadLine();

            _breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler));
            NativeMethods.SetConsoleCtrlHandler((BreakHandler)_breakHandlerGcHandle.Target, true);
            _singleton._readKeyWaitHandle     = new AutoResetEvent(false);
            _singleton._keyReadWaitHandle     = new AutoResetEvent(false);
            _singleton._closingWaitHandle     = new ManualResetEvent(false);
            _singleton._requestKeyWaitHandles = new WaitHandle[] { _singleton._keyReadWaitHandle, _singleton._closingWaitHandle };
            _singleton._threadProcWaitHandles = new WaitHandle[] { _singleton._readKeyWaitHandle, _singleton._closingWaitHandle };

            // This is only used for post-mortem debugging - 200 keys should be enough to reconstruct most command lines.
            _lastNKeys = new HistoryQueue <ConsoleKeyInfo>(200);

            // This is for a "being hosted in an alternate appdomain scenario" (the
            // DomainUnload event is not raised for the default appdomain). It allows us
            // to exit cleanly when the appdomain is unloaded but the process is not going
            // away.
            if (!AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                AppDomain.CurrentDomain.DomainUnload += (x, y) =>
                {
                    _singleton._closingWaitHandle.Set();
                    _singleton._readKeyThread.Join(); // may need to wait for history to be written
                };
            }

            _singleton._readKeyThread = new Thread(_singleton.ReadKeyThreadProc)
            {
                IsBackground = true
            };
            _singleton._readKeyThread.Start();
        }
Example #2
0
        static PSConsoleReadLine()
        {
            _singleton = new PSConsoleReadLine();

            _breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler));
            NativeMethods.SetConsoleCtrlHandler((BreakHandler) _breakHandlerGcHandle.Target, true);
            _singleton._readKeyThread = new Thread(_singleton.ReadKeyThreadProc);
            _singleton._readKeyThread.Start();
            _singleton._readKeyWaitHandle = new AutoResetEvent(false);
            _singleton._keyReadWaitHandle = new AutoResetEvent(false);
            _singleton._closingWaitHandle = new AutoResetEvent(false);
            _singleton._waitHandles = new WaitHandle[] { _singleton._keyReadWaitHandle, _singleton._closingWaitHandle };
        }
Example #3
0
        static PSConsoleReadLine()
        {
            _singleton = new PSConsoleReadLine();

            _breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler));
            NativeMethods.SetConsoleCtrlHandler((BreakHandler) _breakHandlerGcHandle.Target, true);
            _singleton._readKeyThread = new Thread(_singleton.ReadKeyThreadProc) {IsBackground = true};
            _singleton._readKeyThread.Start();
            _singleton._readKeyWaitHandle = new AutoResetEvent(false);
            _singleton._keyReadWaitHandle = new AutoResetEvent(false);
            _singleton._closingWaitHandle = new AutoResetEvent(false);
            _singleton._waitHandles = new WaitHandle[] { _singleton._keyReadWaitHandle, _singleton._closingWaitHandle };

            // This is only used for post-mortem debugging - 200 keys should be enough to reconstruct most command lines.
            _lastNKeys = new HistoryQueue<ConsoleKeyInfo>(200);
        }
Example #4
0
 protected override void EndProcessing()
 {
     if (ParameterSetName.Equals(FunctionParameterSet))
     {
         var function   = (string)_dynamicParameters.Value[FunctionParameter].Value;
         var keyHandler = (Action <ConsoleKeyInfo?, object>)
                          Delegate.CreateDelegate(typeof(Action <ConsoleKeyInfo?, object>),
                                                  typeof(PSConsoleReadLine).GetMethod(function));
         BriefDescription = function;
         PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, BriefDescription, Description);
     }
     else
     {
         PSConsoleReadLine.SetKeyHandler(Chord, ScriptBlock, BriefDescription, Description);
     }
 }
Example #5
0
        static PSConsoleReadLine()
        {
            _singleton = new PSConsoleReadLine();

            _breakHandlerGcHandle = GCHandle.Alloc(new BreakHandler(_singleton.BreakHandler));
            NativeMethods.SetConsoleCtrlHandler((BreakHandler)_breakHandlerGcHandle.Target, true);
            _singleton._readKeyThread = new Thread(_singleton.ReadKeyThreadProc);
            _singleton._readKeyThread.IsBackground = true;
            _singleton._readKeyThread.Start();
            _singleton._readKeyWaitHandle = new AutoResetEvent(false);
            _singleton._keyReadWaitHandle = new AutoResetEvent(false);
            _singleton._closingWaitHandle = new AutoResetEvent(false);
            _singleton._waitHandles       = new WaitHandle[] { _singleton._keyReadWaitHandle, _singleton._closingWaitHandle };

            // This is only used for post-mortem debugging - 200 keys should be enough to reconstruct most command lines.
            _lastNKeys = new HistoryQueue <ConsoleKeyInfo>(200);
        }
Example #6
0
        protected override void EndProcessing()
        {
            bool bound   = true;
            bool unbound = true;

            if (_bound.HasValue && _unbound.HasValue)
            {
                bound   = _bound.Value.IsPresent;
                unbound = _unbound.Value.IsPresent;
            }
            else if (_bound.HasValue)
            {
                bound   = _bound.Value.IsPresent;
                unbound = false;
            }
            else if (_unbound.HasValue)
            {
                bound   = false;
                unbound = _unbound.Value.IsPresent;
            }
            WriteObject(PSConsoleReadLine.GetKeyHandlers(bound, unbound), true);
        }
Example #7
0
 protected override void EndProcessing()
 {
     WriteObject(PSConsoleReadLine.GetKeyHandlers(), true);
 }
Example #8
0
 protected override void EndProcessing()
 {
     WriteObject(PSConsoleReadLine.GetOptions());
 }
Example #9
0
 public abstract void Redo(PSConsoleReadLine singleton);
Example #10
0
 public override void Undo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Insert(_deleteStartPosition, _deletedString);
     _singleton._current = _deleteStartPosition + _deletedString.Length;
 }
Example #11
0
 public override void Redo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Insert(_insertStartPosition, _insertedString);
     _singleton._current += _insertedString.Length;
 }
Example #12
0
 public override void Undo(PSConsoleReadLine singleton)
 {
     Debug.Assert(singleton._buffer[_insertStartPosition] == _insertedCharacter, "Character to undo is not what it should be");
     _singleton._buffer.Remove(_insertStartPosition, 1);
     _singleton._current = _insertStartPosition;
 }
Example #13
0
 public override void Redo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Insert(_insertStartPosition, _insertedCharacter);
     _singleton._current++;
 }
Example #14
0
 public override void Undo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Insert(_deleteStartPosition, _deletedString);
     _singleton._current = _deleteStartPosition + _deletedString.Length;
 }
Example #15
0
 public override void Redo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Remove(_deleteStartPosition, _deletedString.Length);
     _singleton._current = _deleteStartPosition;
 }
Example #16
0
 public override void Redo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Insert(_insertStartPosition, _insertedCharacter);
     _singleton._current++;
 }
Example #17
0
 public override void Redo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Insert(_insertStartPosition, _insertedString);
     _singleton._current += _insertedString.Length;
 }
Example #18
0
 public override void Undo(PSConsoleReadLine singleton)
 {
     Debug.Assert(singleton._buffer.ToString(_insertStartPosition, _insertedString.Length).Equals(_insertedString),
         "Character to undo is not what it should be");
     _singleton._buffer.Remove(_insertStartPosition, _insertedString.Length);
     _singleton._current = _insertStartPosition;
 }
Example #19
0
 public override void Redo(PSConsoleReadLine singleton)
 {
     _singleton._buffer.Remove(_deleteStartPosition, _deletedString.Length);
     _singleton._current = _deleteStartPosition;
 }
Example #20
0
 public override void Redo(PSConsoleReadLine singleton)
 {
     foreach (var editItem in _groupedEditItems)
     {
         editItem.Redo(singleton);
     }
 }
Example #21
0
 public override void Undo(PSConsoleReadLine singleton)
 {
     Debug.Assert(singleton._buffer[_insertStartPosition] == _insertedCharacter, "Character to undo is not what it should be");
     _singleton._buffer.Remove(_insertStartPosition, 1);
     _singleton._current = _insertStartPosition;
 }
Example #22
0
 public override void Undo(PSConsoleReadLine singleton)
 {
     for (int i = _groupedEditItems.Count - 1; i >= 0; i--)
     {
         _groupedEditItems[i].Undo(singleton);
     }
 }
Example #23
0
 protected override void EndProcessing()
 {
     PSConsoleReadLine.SetOptions(this);
 }
Example #24
0
 public abstract void Undo(PSConsoleReadLine singleton);
Example #25
0
 protected override void EndProcessing()
 {
     PSConsoleReadLine.RemoveKeyHandler(Chord);
 }
Example #26
0
 protected override void EndProcessing()
 {
     PSConsoleReadLine.SetKeyHandler(Key, CtrlXPrefix.IsPresent, Handler, BriefDescription, LongDescription);
 }