示例#1
0
 public PSTable(ColumnDefinition[] columns, PSHost host)
 {
     mColumns = columns;
     mHost = host;
 }
示例#2
0
        Action<ItemStatus, string> GetPrinter(bool showIndex, bool showWorking)
        {
            const string WORKING = "Working";
            const string INDEX = "Index";

            var padding = new ColumnDefinition(string.Empty, 1, Alignment.Left);

            int totWidth = base.Host.UI.RawUI.WindowSize.Width;
            PSTable table = null;
            Action<ItemStatus, string> result;

            if (showIndex && showWorking) { // show the "index" and "working" columns
                ColumnDefinition[] cols = new ColumnDefinition[] {
                    // the tree
                    new ColumnDefinition(string.Empty, totWidth - (WORKING.Length + INDEX.Length) - 3 /* padding */),

                    padding,

                    // the index/staged items
                    new ColumnDefinition(INDEX, INDEX.Length, Alignment.Center),

                    padding,

                    // the working/unstaged items
                    new ColumnDefinition(WORKING, WORKING.Length, Alignment.Center),

                    padding
                };

                table = new PSTable(cols, base.Host);
                result = new Action<ItemStatus, string>(
                    (x, y) => table.PrintLine(
                        PrepPrintPathCell(x.IsDefault, cols[0], y),
                        string.Empty, PrepPrintIndexCell(x.IndexStatus, cols[2]),
                        string.Empty, PrepPrintWorkingCell(x.WorkingStatus, cols[4]),
                        string.Empty));

            } else if (showIndex) { // show the "index" column only
                ColumnDefinition[] cols = new ColumnDefinition[] {
                    // the tree
                    new ColumnDefinition(string.Empty, totWidth - INDEX.Length - 2),

                    padding,

                    // the index/staged items
                    new ColumnDefinition(INDEX, INDEX.Length, Alignment.Center),

                    padding
                };

                table = new PSTable(cols, base.Host);
                result = new Action<ItemStatus, string>(
                    (x, y) => table.PrintLine(
                        PrepPrintPathCell(x.IsDefault, cols[0], y),
                        string.Empty, PrepPrintIndexCell(x.IndexStatus, cols[2]),
                        string.Empty));

            } else if (showWorking) { // show the working column only
                ColumnDefinition[] cols = new ColumnDefinition[] {
                    // the tree
                    new ColumnDefinition(string.Empty, totWidth - WORKING.Length - 2),

                    padding,

                    // the working/unstaged items
                    new ColumnDefinition(WORKING, WORKING.Length, Alignment.Center),

                    padding
                };

                table = new PSTable(cols, base.Host);
                result = new Action<ItemStatus, string>(
                    (x, y) => table.PrintLine(
                        PrepPrintPathCell(x.IsDefault, cols[0], y),
                        string.Empty, PrepPrintWorkingCell(x.WorkingStatus, cols[2]),
                        string.Empty));

            } else
                result = new Action<ItemStatus, string>((x, y) => { });

            if (table != null) table.PrintHeaders();
            return result;
        }
示例#3
0
        string PrepPrintWorkingCell(WorkingStatus stats, ColumnDefinition col)
        {
            ConsoleColor color;
            string symbol;

            switch (stats) {
                case WorkingStatus.Added:
                    symbol = "+"; color = ConsoleColor.Green; break;

                case WorkingStatus.Modified:
                    symbol = "~"; color = ConsoleColor.Cyan; break;

                case WorkingStatus.Removed:
                    symbol = "-"; color = ConsoleColor.Yellow; break;

                case WorkingStatus.Unmerged:
                    symbol = "!"; color = ConsoleColor.White; break;

                default:
                    symbol = string.Empty;
                    color = ConsoleColor.Gray;
                    break;
            }

            col.Foreground = color;
            return symbol;
        }
示例#4
0
 private static string PrepPrintPathCell(bool isPhysical, ColumnDefinition col, string path)
 {
     //			col.Foreground = isPhysical ? ConsoleColor.Gray : ConsoleColor.White;
     return isPhysical ? path : CreateDottedPadding(path, col.Width);
 }