/// <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); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="ui"> /// An implementation of the PSHostRawUserInterface with which the pane will be shown and hidden. /// </param> internal ProgressPane(PSKernelHostUserInterface ui) { _ui = ui ?? throw new ArgumentNullException(nameof(ui)); _displayValue = null; }