Ejemplo n.º 1
0
        private void ProcessMessageAtSessionInitialization(string line)
        {
            // Handle incoming messages at session startup.
            if (line.Contains("MOTD:"))
            {
                // Let's display the message-of-the-day from PowerShell Azure Shell.
                Console.WriteLine("\n" + line);
                // Also, seeing this message means we are now in pwsh.
                _codeExecutedTaskSource?.SetResult(null);
            }
            else if (line.Contains("VERBOSE: "))
            {
                // Let's show the verbose message generated from the profile.
                Console.Write(line);
            }
            else if (line.Contains(CommandToSetPrompt))
            {
                // pwsh will echo the command passed to it.
                // It's okay to show incoming messages after this very first command is echoed back.
                _sessionInitialized = true;

                string color = VTColorUtils.CombineColorSequences(ConsoleColor.Green, VTColorUtils.DefaultConsoleColor);
                Console.WriteLine($"\n{color}Welcome to Azure Cloud Shell!{VTColorUtils.ResetColor}");
                Console.WriteLine($"{color}Submitted code will run in the Azure Cloud Shell, type 'exit' to quit.{VTColorUtils.ResetColor}");
            }
        }
Ejemplo n.º 2
0
        internal async Task ExitSession()
        {
            await SendCommand(_exitSessionCommand, waitForExecutionCompletion : false);

            _tokenRenewTimer.Stop();

            string color = VTColorUtils.CombineColorSequences(ConsoleColor.Green, VTColorUtils.DefaultConsoleColor);

            Console.Write($"{color}Azure Cloud Shell session ended.{VTColorUtils.ResetColor}\n");
            Console.Write($"{color}Submitted code will run in the local PowerShell sub kernel.{VTColorUtils.ResetColor}\n");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates an array of strings representing as much of the outstanding progress activities as possible within the given
        /// space.  As more outstanding activities are collected, nodes are "compressed" (i.e. rendered in an increasing terse
        /// fashion) in order to display as many as possible.  Ultimately, some nodes may be compressed to the point of
        /// invisibility. The oldest nodes are compressed first.
        /// </summary>
        /// <param name="maxWidth">
        /// The maximum width (in BufferCells) that the rendering may consume.
        /// </param>
        /// <param name="maxHeight">
        /// The maximum height (in BufferCells) that the rendering may consume.
        /// </param>
        /// <param name="ui">
        /// The PSHostRawUserInterface used to gauge string widths in the rendering.
        /// </param>
        /// <returns>
        /// An array of strings containing the textual representation of the outstanding progress activities.
        /// </returns>
        internal List <string> Render(int maxWidth, int maxHeight, PSKernelHostUserInterface ui)
        {
            if (_topLevelNodes == null || _topLevelNodes.Count == 0)
            {
                // we have nothing to render.
                return(null);
            }

            int invisible = 0;
            PSHostRawUserInterface rawUI = ui.RawUI;

            if (TallyHeight(rawUI, maxHeight, maxWidth) > maxHeight)
            {
                // This will smash down nodes until the tree will fit into the alloted number of lines.  If in the
                // process some nodes were made invisible, we will add a line to the display to say so.
                invisible = CompressToFit(rawUI, maxHeight, maxWidth);
            }

            var    result = new List <string>(capacity: 5);
            string border = StringUtil.Padding(maxWidth);
            string vtSeqs = VTColorUtils.CombineColorSequences(ui.ProgressForegroundColor, ui.ProgressBackgroundColor);

            result.Add(string.IsNullOrEmpty(vtSeqs) ? border : vtSeqs + border);
            RenderHelper(result, _topLevelNodes, indentation: 0, maxWidth, rawUI);
            if (invisible == 1)
            {
                result.Add(" 1 activity not shown...");
            }
            else if (invisible > 1)
            {
                result.Add(StringUtil.Format(" {0} activities not shown...", invisible));
            }

            result.Add(string.IsNullOrEmpty(vtSeqs) ? border : border + VTColorUtils.ResetColor);
            return(result);
        }