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(); }
private PSConsoleReadLine() { _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) { OnDequeue = HistoryOnDequeueHandler, OnEnqueue = HistoryOnEnqueueHandler }; _currentHistoryIndex = 0; _hashedHistory = new HashSet <string>(); _killIndex = -1; // So first add indexes 0. _killRing = new List <string>(Options.MaximumKillRingCount); }
public QueueDebugView(HistoryQueue <T> queue) { if (queue == null) { throw new ArgumentNullException("queue"); } this._queue = queue; }
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); }
private void DelayedOneTimeInitialize() { // Delayed initialization is needed so that options can be set // after the constuctor but have an affect before the user starts // editing their first command line. For example, if the user // specifies a custom history save file, we don't want to try reading // from the default one. _historyFileMutex = new Mutex(false, GetHistorySaveFileMutexName()); _history = new HistoryQueue <HistoryItem>(Options.MaximumHistoryCount); _currentHistoryIndex = 0; ReadHistoryFile(); _killIndex = -1; // So first add indexes 0. _killRing = new List <string>(Options.MaximumKillRingCount); }
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); }
private void SetOptionsInternal(SetPSReadlineOption options) { if (options.ContinuationPrompt != null) { Options.ContinuationPrompt = options.ContinuationPrompt; } if (options._continuationPromptForegroundColor.HasValue) { Options.ContinuationPromptForegroundColor = options.ContinuationPromptForegroundColor; } if (options._continuationPromptBackgroundColor.HasValue) { Options.ContinuationPromptBackgroundColor = options.ContinuationPromptBackgroundColor; } if (options._emphasisBackgroundColor.HasValue) { Options.EmphasisBackgroundColor = options.EmphasisBackgroundColor; } if (options._emphasisForegroundColor.HasValue) { Options.EmphasisForegroundColor = options.EmphasisForegroundColor; } if (options._errorBackgroundColor.HasValue) { Options.ErrorBackgroundColor = options.ErrorBackgroundColor; } if (options._errorForegroundColor.HasValue) { Options.ErrorForegroundColor = options.ErrorForegroundColor; } if (options._historyNoDuplicates.HasValue) { Options.HistoryNoDuplicates = options.HistoryNoDuplicates; } if (options._historySearchCursorMovesToEnd.HasValue) { Options.HistorySearchCursorMovesToEnd = options.HistorySearchCursorMovesToEnd; } if (options._addToHistoryHandlerSpecified) { Options.AddToHistoryHandler = options.AddToHistoryHandler; } if (options._commandValidationHandlerSpecified) { Options.CommandValidationHandler = options.CommandValidationHandler; } if (options._maximumHistoryCount.HasValue) { Options.MaximumHistoryCount = options.MaximumHistoryCount; if (_history != null) { var newHistory = new HistoryQueue <HistoryItem>(Options.MaximumHistoryCount); while (_history.Count > Options.MaximumHistoryCount) { _history.Dequeue(); } while (_history.Count > 0) { newHistory.Enqueue(_history.Dequeue()); } _history = newHistory; _currentHistoryIndex = _history.Count; } } if (options._maximumKillRingCount.HasValue) { Options.MaximumKillRingCount = options.MaximumKillRingCount; // TODO - make _killRing smaller } if (options._editMode.HasValue) { Options.EditMode = options.EditMode; // Switching/resetting modes - clear out chord dispatch table _chordDispatchTable.Clear(); switch (options._editMode) { case EditMode.Emacs: SetDefaultEmacsBindings(); break; #if FALSE case EditMode.Vi: //TODO: _dispatchTable = _viKeyMap; break; #endif case EditMode.Windows: SetDefaultWindowsBindings(); break; } } if (options._showToolTips.HasValue) { Options.ShowToolTips = options.ShowToolTips; } if (options._extraPromptLineCount.HasValue) { Options.ExtraPromptLineCount = options.ExtraPromptLineCount; } if (options._dingTone.HasValue) { Options.DingTone = options.DingTone; } if (options._dingDuration.HasValue) { Options.DingDuration = options.DingDuration; } if (options._bellStyle.HasValue) { Options.BellStyle = options.BellStyle; } if (options._completionQueryItems.HasValue) { Options.CompletionQueryItems = options.CompletionQueryItems; } if (options.WordDelimiters != null) { Options.WordDelimiters = options.WordDelimiters; } if (options._historySearchCaseSensitive.HasValue) { Options.HistorySearchCaseSensitive = options.HistorySearchCaseSensitive; } if (options._historySaveStyle.HasValue) { Options.HistorySaveStyle = options.HistorySaveStyle; } if (options.HistorySavePath != null) { Options.HistorySavePath = options.HistorySavePath; if (_historyFileMutex != null) { _historyFileMutex.Dispose(); } _historyFileMutex = new Mutex(false, GetHistorySaveFileMutexName()); _historyFileLastSavedSize = 0; } if (options.ResetTokenColors) { Options.ResetColors(); } if (options._tokenKind.HasValue) { if (options._foregroundColor.HasValue) { Options.SetForegroundColor(options.TokenKind, options.ForegroundColor); } if (options._backgroundColor.HasValue) { Options.SetBackgroundColor(options.TokenKind, options.BackgroundColor); } } }