示例#1
0
        /// <summary>
        /// Creates a new instance of the ConsoleServicePSHostUserInterface
        /// class with the given IConsoleHost implementation.
        /// </summary>
        /// <param name="powerShellContext">The PowerShellContext to use for executing commands.</param>
        /// <param name="logger">An ILogger implementation to use for this host.</param>
        public TerminalPSHostUserInterface(
            PowerShellContext powerShellContext,
            ILogger logger)
            : base(
                powerShellContext,
                new TerminalPSHostRawUserInterface(logger),
                logger)
        {
            this.consoleReadLine = new ConsoleReadLine(powerShellContext);

            // Set the output encoding to UTF-8 so that special
            // characters are written to the console correctly
            System.Console.OutputEncoding = System.Text.Encoding.UTF8;

            System.Console.CancelKeyPress +=
                (obj, args) =>
            {
                if (!this.IsNativeApplicationRunning)
                {
                    // We'll handle Ctrl+C
                    args.Cancel = true;
                    this.SendControlC();
                }
            };
        }
 static void Main(string[] args)
 {
     Console.WriteLine("What is the answer? (5 secs.)");
     try
     {
         var answer = ConsoleReadLine.ReadLine(5000);
         Console.WriteLine("Answer is: {0}", answer);
     }
     catch
     {
         Console.WriteLine("No answer");
     }
     Console.ReadKey();
 }
        internal PSReadLinePromptContext(
            PowerShellContext powerShellContext,
            PromptNest promptNest,
            InvocationEventQueue invocationEventQueue,
            PSReadLineProxy readLineProxy)
        {
            _promptNest           = promptNest;
            _powerShellContext    = powerShellContext;
            _invocationEventQueue = invocationEventQueue;
            _consoleReadLine      = new ConsoleReadLine(powerShellContext);
            _readLineProxy        = readLineProxy;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            _readLineProxy.OverrideReadKey(
                intercept => ConsoleProxy.UnixReadKey(
                    intercept,
                    _readLineCancellationSource.Token));
        }
 internal LegacyReadLineContext(PowerShellContext powerShellContext)
 {
     _legacyReadLine = new ConsoleReadLine(powerShellContext);
 }
示例#5
0
 public ConsolePSSession(IDebugger debugger, ConsoleHost host, IMethodCallDispatch methodCallDispatcher) : base(debugger, host, methodCallDispatcher)
 {
     host.Program     = this;
     _consoleHost     = host;
     _consoleReadLine = new ConsoleReadLine();
 }