ConsoleHostRawUserInterface(ConsoleHostUserInterface mshConsole) : base() { defaultForeground = ForegroundColor; defaultBackground = BackgroundColor; parent = mshConsole; // cacheKeyEvent is a value type and initialized automatically // add "Administrator: " prefix into the window title, but don't wait for it to finish // (we may load resources which can take some time) Task.Run(() => { WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); if (principal.IsInRole(WindowsBuiltInRole.Administrator)) { string prefix = ConsoleHostRawUserInterfaceStrings.WindowTitleElevatedPrefix; // check using Regex if the window already has Administrator: prefix // (i.e. from the parent console process) string titlePattern = ConsoleHostRawUserInterfaceStrings.WindowTitleTemplate; titlePattern = Regex.Escape(titlePattern) .Replace(@"\{1}", ".*") .Replace(@"\{0}", Regex.Escape(prefix)); if (!Regex.IsMatch(this.WindowTitle, titlePattern)) { this.WindowTitle = StringUtil.Format(ConsoleHostRawUserInterfaceStrings.WindowTitleTemplate, prefix, this.WindowTitle); } } }); }
ConsoleTextWriter(ConsoleHostUserInterface ui) : base(System.Globalization.CultureInfo.CurrentCulture) { Dbg.Assert(ui != null, "ui needs a value"); _ui = ui; }
ProgressPane(ConsoleHostUserInterface ui) { if (ui == null) { throw new ArgumentNullException(nameof(ui)); } _ui = ui; _rawui = ui.RawUI; }
internal CommandLineParameterParser(ConsoleHost p, Version ver, string bannerText, string helpText) { this.showBanner = true; this.staMode = null; this.noExit = true; this.collectedArgs = new Collection <CommandParameter>(); this.bannerText = bannerText; this.helpText = helpText; this.parent = p; this.ui = (ConsoleHostUserInterface)p.UI; this.ver = ver; }
internal ProgressPane(ConsoleHostUserInterface ui) { this.location = new Coordinates(0, 0); if (ui != null) { this.ui = ui; this.rawui = ui.RawUI; return; } else { throw new ArgumentNullException("ui"); } }
internal ConsoleHostRawUserInterface(ConsoleHostUserInterface mshConsole) { this.defaultForeground = ConsoleColor.Gray; this.defaultForeground = this.ForegroundColor; this.defaultBackground = this.BackgroundColor; this.parent = mshConsole; WindowsIdentity current = WindowsIdentity.GetCurrent(); WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current); if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator)) { string windowTitleElevatedPrefix = ConsoleHostRawUserInterfaceStrings.WindowTitleElevatedPrefix; string windowTitleTemplate = ConsoleHostRawUserInterfaceStrings.WindowTitleTemplate; windowTitleTemplate = Regex.Escape(windowTitleTemplate).Replace("\\{1}", ".*").Replace("\\{0}", Regex.Escape(windowTitleElevatedPrefix)); if (!Regex.IsMatch(this.WindowTitle, windowTitleTemplate)) { this.WindowTitle = StringUtil.Format(ConsoleHostRawUserInterfaceStrings.WindowTitleTemplate, windowTitleElevatedPrefix, this.WindowTitle); } } }
public ConsoleColorProxy(ConsoleHostUserInterface ui) { if (ui == null) throw new ArgumentNullException("ui"); _ui = ui; }
private void Dispose(bool isDisposingNotFinalizing) { if (!this.isDisposed) { if (isDisposingNotFinalizing) { if (this.IsTranscribing) { this.StopTranscribing(); } if (this.outputSerializer != null) { this.outputSerializer.End(); } if (this.errorSerializer != null) { this.errorSerializer.End(); } if (this.runspaceRef != null) { try { this.runspaceRef.Runspace.Dispose(); } catch (InvalidRunspaceStateException invalidRunspaceStateException) { } } this.runspaceRef = null; this.hostGlobalLock = null; this.ui = null; if (this.runspaceOpenedWaitHandle != null) { this.runspaceOpenedWaitHandle.Close(); this.runspaceOpenedWaitHandle = null; } } ConsoleControl.RemoveBreakHandler(); if (this.breakHandlerGcHandle.IsAllocated) this.breakHandlerGcHandle.Free(); } this.isDisposed = true; }
internal ConsoleTextWriter(ConsoleHostUserInterface ui) : base(Thread.CurrentThread.CurrentCulture) { this.ui = ui; }
private void EvaluateSuggestions(ConsoleHostUserInterface ui) { // Output any training suggestions try { ArrayList suggestions = HostUtilities.GetSuggestion(_parent.Runspace); if (suggestions.Count > 0) { ui.WriteLine(); } bool first = true; foreach (string suggestion in suggestions) { if (!first) ui.WriteLine(); ui.WriteLine(suggestion); first = false; } } catch (TerminateException) { // A variable breakpoint may be hit by HostUtilities.GetSuggestion. The debugger throws TerminateExceptions to stop the execution // of the current statement; we do not want to treat these exceptions as errors. } catch (Exception e) { // Catch-all OK. This is a third-party call-out. CommandProcessorBase.CheckForSevereException(e); ui.WriteErrorLine(e.Message); LocalRunspace localRunspace = (LocalRunspace)_parent.Runspace; localRunspace.GetExecutionContext.AppendDollarError(e); } }
internal CommandLineParameterParser(ConsoleHost p, Version ver, string bannerText, string helpText) { this.showBanner = true; this.staMode = null; this.noExit = true; this.collectedArgs = new Collection<CommandParameter>(); this.bannerText = bannerText; this.helpText = helpText; this.parent = p; this.ui = (ConsoleHostUserInterface)p.UI; this.ver = ver; }
internal ConsoleHostRawUserInterface(ConsoleHostUserInterface mshConsole) : base() { _parent = mshConsole; }
public ConsoleColorProxy(ConsoleHostUserInterface ui) { if (ui != null) { this.ui = ui; return; } else { throw new ArgumentNullException("ui"); } }
internal string ReadLine(bool endOnTab, string initialContent, out ConsoleHostUserInterface.ReadLineResult result, bool calledFromPipeline, bool transcribeResult) { ConsoleHostUserInterface.ReadLineResult readLineResult; result = ConsoleHostUserInterface.ReadLineResult.endedOnEnter; string str = ""; if (!this.parent.IsStandardInputRedirected || !this.readFromStdin) { SafeFileHandle inputHandle = ConsoleControl.GetInputHandle(); this.PreRead(); ConsoleControl.ConsoleModes mode = ConsoleControl.GetMode(inputHandle); if ((mode & (ConsoleControl.ConsoleModes.ProcessedInput | ConsoleControl.ConsoleModes.LineInput | ConsoleControl.ConsoleModes.EchoInput | ConsoleControl.ConsoleModes.ProcessedOutput | ConsoleControl.ConsoleModes.WrapEndOfLine)) != (ConsoleControl.ConsoleModes.ProcessedInput | ConsoleControl.ConsoleModes.LineInput | ConsoleControl.ConsoleModes.EchoInput | ConsoleControl.ConsoleModes.ProcessedOutput | ConsoleControl.ConsoleModes.WrapEndOfLine) || (mode & ConsoleControl.ConsoleModes.MouseInput) > 0) { mode = mode & (ConsoleControl.ConsoleModes.ProcessedInput | ConsoleControl.ConsoleModes.LineInput | ConsoleControl.ConsoleModes.EchoInput | ConsoleControl.ConsoleModes.WindowInput | ConsoleControl.ConsoleModes.Insert | ConsoleControl.ConsoleModes.QuickEdit | ConsoleControl.ConsoleModes.Extended | ConsoleControl.ConsoleModes.AutoPosition | ConsoleControl.ConsoleModes.ProcessedOutput | ConsoleControl.ConsoleModes.WrapEndOfLine); mode = mode | ConsoleControl.ConsoleModes.ProcessedInput | ConsoleControl.ConsoleModes.LineInput | ConsoleControl.ConsoleModes.EchoInput | ConsoleControl.ConsoleModes.ProcessedOutput | ConsoleControl.ConsoleModes.WrapEndOfLine; ConsoleControl.SetMode(inputHandle, mode); } int num = 0; string str1 = null; this.rawui.ClearKeyCache(); while (true) { str = string.Concat(str, ConsoleControl.ReadConsole(inputHandle, initialContent, 0x2000, endOnTab, out num)); if (str.Length != 0) { if (!str.EndsWith("\r\n", StringComparison.CurrentCulture)) { int num1 = str.IndexOf("\t", StringComparison.CurrentCulture); if (endOnTab && num1 != -1) { if ((num & 16) != 0) { if ((num & 16) > 0) { result = ConsoleHostUserInterface.ReadLineResult.endedOnShiftTab; } } else { result = ConsoleHostUserInterface.ReadLineResult.endedOnTab; } int num2 = this.RawUI.LengthInBufferCells(str.Substring(num1 + 1)); if (num2 <= 0) { str1 = string.Concat(str1, str[num1]); } else { Coordinates cursorPosition = this.RawUI.CursorPosition; char characterUnderCursor = this.GetCharacterUnderCursor(cursorPosition); this.Write(new string(' ', num2)); this.RawUI.CursorPosition = cursorPosition; str1 = string.Concat(str[num1], characterUnderCursor, str.Substring(num1 + 1)); } str = str.Remove(num1); break; } } else { result = ConsoleHostUserInterface.ReadLineResult.endedOnEnter; str = str.Remove(str.Length - "\r\n".Length); break; } } else { result = ConsoleHostUserInterface.ReadLineResult.endedOnBreak; str = null; if (!calledFromPipeline) { break; } throw new PipelineStoppedException(); } } if (!transcribeResult) { this.PostRead(); } else { this.PostRead(str); } if (str1 != null) { str = string.Concat(str, str1); } return str; } else { str = this.parent.StandardInReader.ReadLine(); if (!endOnTab || string.IsNullOrEmpty(str) || str.IndexOf("\t", StringComparison.OrdinalIgnoreCase) == -1) { return str; } else { ConsoleHostUserInterface.ReadLineResult readLineResultPointer = (ConsoleHostUserInterface.ReadLineResult)result; if (this.isTestingShiftTab) { readLineResult = ConsoleHostUserInterface.ReadLineResult.endedOnShiftTab; } else { readLineResult = ConsoleHostUserInterface.ReadLineResult.endedOnTab; } readLineResultPointer = readLineResult; return str; } } }
private void EvaluateSuggestions(ConsoleHostUserInterface ui) { try { ArrayList suggestion = HostUtilities.GetSuggestion(this.parent.Runspace); if (suggestion.Count > 0) { ui.WriteLine(); } bool flag = true; foreach (string str in suggestion) { if (!flag) { ui.WriteLine(); } ui.WriteLine(str); flag = false; } } catch (TerminateException terminateException) { } catch (Exception exception1) { Exception exception = exception1; CommandProcessorBase.CheckForSevereException(exception); ui.WriteErrorLine(exception.Message); LocalRunspace runspace = (LocalRunspace)this.parent.Runspace; runspace.GetExecutionContext.AppendDollarError(exception); } }
internal ConsoleHost(RunspaceConfiguration configuration) { this.savedWindowTitle = ""; this.id = Guid.NewGuid(); this.ver = PSVersionInfo.PSVersion; this.noExit = true; this.hostGlobalLock = new object(); this.transcriptFileName = string.Empty; this.transcriptionStateLock = new object(); Thread.CurrentThread.CurrentUICulture = this.CurrentUICulture; Thread.CurrentThread.CurrentCulture = this.CurrentCulture; base.ShouldSetThreadUILanguageToZero = true; this.debuggerCommandProcessor = new HostUtilities.DebuggerCommandProcessor(); this.inDebugMode = false; this.displayDebuggerBanner = true; this.configuration = configuration; this.ui = new ConsoleHostUserInterface(this); this.consoleWriter = new ConsoleTextWriter(this.ui); ConsoleHost.exitOnCtrlBreakMessage = ConsoleHostStrings.ExitOnCtrlBreakMessage; UnhandledExceptionEventHandler unhandledExceptionEventHandler = new UnhandledExceptionEventHandler(this.UnhandledExceptionHandler); AppDomain.CurrentDomain.UnhandledException += unhandledExceptionEventHandler; }
ProgressPane(ConsoleHostUserInterface ui) { if (ui == null) throw new ArgumentNullException("ui"); _ui = ui; _rawui = ui.RawUI; }