PowerArgs.Cli.PageStack.GetSegments C# (CSharp) Method

GetSegments() public static method

public static GetSegments ( string path ) : string[]
path string
return string[]
        public static string[] GetSegments(string path)
        {
            var segments = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            return segments;
        }

Usage Example

Example #1
0
        internal void Compose()
        {
            var  pageStack = (Application as ConsolePageApp).PageStack;
            bool hadFocus  = this.Controls.Where(c => c.HasFocus).Count() > 0;

            this.Controls.Clear();

            string builtUpPath = "";

            foreach (var s in PageStack.GetSegments(pageStack.CurrentPath))
            {
                string myPath;

                if (builtUpPath == "")
                {
                    builtUpPath = s;
                    myPath      = s;
                }
                else
                {
                    var label = Add(new Label()
                    {
                        Mode = LabelRenderMode.SingleLineAutoSize, Text = "->".ToConsoleString(DefaultColors.H1Color)
                    });
                    builtUpPath += "/" + s;
                    myPath       = builtUpPath;
                }

                var crumb = Add(new BreadcrumbElement(() => { pageStack.TryNavigate(myPath); })
                {
                    Text = s.ToConsoleString()
                });
                crumb.Width = 10;
                if (hadFocus && builtUpPath.Contains("/") == false)
                {
                    var worked = crumb.TryFocus();
                }
            }

            this.Width = Layout.StackHorizontally(1, this.Controls);
        }