/// <summary> /// Prints global help and list of available commands. /// </summary> /// <param name="commands"></param> /// <param name="arguments">Extra help arguments. Not used at the moment.</param> public void PrintGlobalHelp(IEnumerable <CommandInfo> commands, IEnumerable <string> arguments) { if (commands == null) { throw new ArgumentNullException(nameof(commands)); } this._console.WriteLine(this._helpStyles.HelpHeader, "Available commands:"); // TODO: make this printer and style read-only in constructor - no changes. if style changes, instance changes... var verySimpleStyling = new SimpleTableStyle( this._helpStyles.HelpHeader, this._helpStyles.CommonStyles.OddRowColor) { AtomicPrinting = true, EvenRowColor = this._helpStyles.CommonStyles.EvenRowColor, OverflowBehaviour = TableOverflowContentBehavior.Wrap, ShowHeader = false }; var commandInfos = commands as CommandInfo[] ?? commands.ToArray(); var commandListTable = new DataTable <CommandInfo>( new ColumnInfo("Command Name", ColumnAlignment.Left, commandInfos.Max(cmd => cmd.CommandModelBuilder.CommandName.Length) + 2), new ColumnInfo("Description", ColumnAlignment.Left)); foreach (var cmdInfo in commandInfos) { commandListTable.AddRow(cmdInfo, new[] { " " + cmdInfo.CommandModelBuilder.CommandName, cmdInfo.CommandModelBuilder.CommandDescription }); } var printer = new SimpleTablePrinter(this._console, verySimpleStyling); printer.PrintTable(commandListTable); // TODO: printAt + 2 columns of margin, now simulated by +2 spaces to first column // printAt() or PrintIntended(table, indentation) this._console.WriteLine(); this._console.WriteLine(this._helpStyles.CommonStyles.Default, $"All command names are case {this._options.CommandsSensitivenes.ToString().ToLower()}."); this._console.WriteText(this._helpStyles.CommonStyles.Default, "To receive syntax help about particular command use \""); this._console.WriteText(this._helpStyles.HelpDefinition, $"<commandName> {this._options.FlagCharacters.SelectRandom()}{HelpCommands.SelectRandom()}"); this._console.WriteText(this._helpStyles.CommonStyles.Default, "\" or \""); this._console.WriteText(this._helpStyles.HelpDefinition, $"{this._options.FlagCharacters.SelectRandom()}{HelpCommands.SelectRandom()} <commandName>"); this._console.WriteLine(this._helpStyles.CommonStyles.Default, "\" syntax."); this._console.WriteLine(); }
public void Run(IConsole console) { var tableFrameColor = new ConsoleFontColor(Color.Silver, Color.Black); var tableHeaderColor = new ConsoleFontColor(Color.White, Color.Black); var tableOddRowColor = new ConsoleFontColor(Color.Silver, Color.Black); var tableEvenRowColor = new ConsoleFontColor(Color.DimGray, Color.Black); TableStyle tableStyle = new TableStyle( tableFrameColor, tableHeaderColor, tableOddRowColor, tableEvenRowColor, @"|-||||-||-|--", // simple, ascii table ' ', TableOverflowContentBehavior.Ellipsis); TableStyle wrappingTableStyle = new TableStyle( tableFrameColor, tableHeaderColor, tableOddRowColor, tableEvenRowColor, @"|-||||-||-|--", // simple, ascii table ' ', TableOverflowContentBehavior.Wrap); var headers = new[] { "Row 1", "Longer row 2", "Third row" }; var values = new[] { new[] { "1", "2", "3" }, new[] { "10", "223423", "3" }, new[] { "1", "2", "3" }, new[] { "12332 ", "22332423", "3223434234" }, new[] { "1df ds fsd fsfs fsdf s", "2234 4234 23", "3 23423423" }, }; var simpleTableStyleWithWrap = new SimpleTableStyle( tableHeaderColor, tableEvenRowColor, TableOverflowContentBehavior.Wrap) { EvenRowColor = tableOddRowColor }; var simpleTableStyleWithEllipsis = new SimpleTableStyle(tableHeaderColor, tableEvenRowColor) { EvenRowColor = tableOddRowColor }; // ops.WriteTabelaricData(5, 5, 50, headers, values, tableStyle); console.WriteLine(tableFrameColor, "Small tables"); DataTable <string> dt = new DataTable <string>( new ColumnInfo("Column a", ColumnAlignment.Left), new ColumnInfo("Column B", ColumnAlignment.Left), new ColumnInfo("Column V1", ColumnAlignment.Right), new ColumnInfo("Column V2", ColumnAlignment.Right)); for (int i = 0; i < 20; i++) { dt.AddRow( i.ToString(), new[] { TestTools.AlphanumericIdentifier.BuildRandomStringFrom(5, 10).Trim(), TestTools.AlphaSentence.BuildRandomStringFrom(4, 15).Trim(), TestTools.GetRandomFloat(10000).ToString("N2", CultureInfo.CurrentCulture), TestTools.GetRandomFloat(30000).ToString("N2", CultureInfo.CurrentCulture) }); } SimpleTablePrinter simpleTablePrinter = new SimpleTablePrinter(console, simpleTableStyleWithEllipsis); SimpleTablePrinter simpleTableWithWrapping = new SimpleTablePrinter(console, simpleTableStyleWithWrap); FramedTablePrinter framedPrinter = new FramedTablePrinter(console, tableStyle); SpeflowStyleTablePrinter specflowPrinter = new SpeflowStyleTablePrinter(console, tableStyle); var specflowTableWithWrapping = new SpeflowStyleTablePrinter(console, wrappingTableStyle); simpleTablePrinter.PrintTable(dt); console.WriteLine(); simpleTableWithWrapping.PrintTable(dt); console.WriteLine(); framedPrinter.PrintTable(dt); console.WriteLine(); specflowPrinter.PrintTable(dt); console.WriteLine(); specflowTableWithWrapping.PrintTable(dt); console.WriteLine(); console.WaitForNextPage(); console.Clear(); console.WriteLine(tableFrameColor, "Positioned tables"); console.WriteLine(); // TODO: PrintTableAt(dt, x, y); console.WaitForNextPage(); console.WriteLine(tableFrameColor, "Large tables"); console.WriteLine(); dt = new DataTable <string>( new ColumnInfo("Column A1", ColumnAlignment.Left), new ColumnInfo("Column B", ColumnAlignment.Left), new ColumnInfo("Column C", ColumnAlignment.Left), new ColumnInfo("Column V1", ColumnAlignment.Right, fixedLength: 9), new ColumnInfo("Column V2", ColumnAlignment.Right, fixedLength: 9), new ColumnInfo("Column VXX", ColumnAlignment.Right, fixedLength: 12)); for (int i = 0; i < 20; i++) { dt.AddRow( i.ToString(), new[] { TestTools.UpperAlphanumeric.BuildRandomStringFrom(10, 15).Trim(), TestTools.AlphanumericIdentifier.BuildRandomStringFrom(8, 40).Trim(), TestTools.AlphaSentence.BuildRandomStringFrom(20, 50).Trim(), TestTools.GetRandomFloat(10000).ToString("N2", CultureInfo.CurrentCulture), TestTools.GetRandomFloat(50000).ToString("N2", CultureInfo.CurrentCulture), TestTools.GetRandomFloat(3000000).ToString("N2", CultureInfo.CurrentCulture) }); } simpleTablePrinter.PrintTable(dt); console.WriteLine(); simpleTableWithWrapping.PrintTable(dt); console.WriteLine(); framedPrinter.PrintTable(dt); console.WriteLine(); // TODO: also wrapping framed table specflowPrinter.PrintTable(dt); console.WriteLine(); specflowTableWithWrapping.PrintTable(dt); console.WriteLine(); console.WriteLine(tableFrameColor, ""); console.WaitForNextPage(); }