private string PrintListType(List <int> ColumnsMaxLengths) { StringBuilder toPrint = new StringBuilder(); toPrint.Append(EliteConsole.PrintInfo(Spacer)); for (int i = 0; i < Columns.Count; i++) { toPrint.Append(EliteConsole.PrintInfo(Columns[i])); toPrint.Append(EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - Columns[i].Length + 1))); } toPrint.Append(EliteConsole.PrintInfoLine()); toPrint.Append(EliteConsole.PrintInfo(Spacer)); for (int i = 0; i < Columns.Count; i++) { toPrint.Append(EliteConsole.PrintInfo(new String('-', Columns[i].Length))); toPrint.Append(EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - Columns[i].Length + 1))); } toPrint.Append(EliteConsole.PrintInfoLine()); foreach (List <string> row in Rows) { toPrint.Append(EliteConsole.PrintInfo(Spacer)); for (int i = 0; i < row.Count; i++) { toPrint.Append(EliteConsole.PrintInfo(row[i])); toPrint.Append(EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - row[i].Length + 1))); } toPrint.Append(EliteConsole.PrintInfoLine()); } return(toPrint.ToString()); }
public async Task <string> History(Grunt grunt, List <ParsedParameter> parameters) { string Name = "History"; if (parameters.Count() != 2 || !parameters[0].Value.Equals(Name, StringComparison.OrdinalIgnoreCase)) { StringBuilder toPrint1 = new StringBuilder(); toPrint1.Append(EliteConsole.PrintFormattedErrorLine("Usage: History <tasking_name>")); return(toPrint1.ToString()); } StringBuilder toPrint = new StringBuilder(); GruntTasking tasking = await _context.GruntTaskings.FirstOrDefaultAsync(GT => GT.Name == parameters[1].Value); if (tasking == null) { toPrint.Append(EliteConsole.PrintFormattedErrorLine("Invalid History command, invalid tasking name. Usage is: History [ <tasking_name> ]")); } else { GruntCommand command = await _context.GruntCommands .Include(GC => GC.CommandOutput) .Include(GC => GC.User) .FirstOrDefaultAsync(GC => GC.Id == tasking.GruntCommandId); toPrint.Append(EliteConsole.PrintFormattedInfoLine("[" + tasking.CompletionTime + " UTC] Grunt: " + grunt.Name + " " + "GruntTasking: " + tasking.Name)); toPrint.Append(EliteConsole.PrintInfoLine("(" + command.User.UserName + ") > " + command.Command)); toPrint.Append(EliteConsole.PrintInfoLine(command.CommandOutput.Output)); } return(toPrint.ToString()); }
private string PrintParameterType(List <int> ColumnsMaxLengths) { StringBuilder toPrint = new StringBuilder(); toPrint.Append(EliteConsole.PrintInfo(Spacer)); toPrint.Append(EliteConsole.PrintHighlightLine(this.Title)); toPrint.Append(EliteConsole.PrintInfo(Spacer)); toPrint.Append(EliteConsole.PrintInfoLine(new String('=', ColumnsMaxLengths.Sum() + Columns.Count - 1))); foreach (List <string> row in Rows) { toPrint.Append(EliteConsole.PrintInfo(Spacer)); for (int i = 0; i < row.Count; i++) { toPrint.Append(EliteConsole.PrintInfo(row[i])); toPrint.Append(EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - row[i].Length + 1))); } toPrint.Append(EliteConsole.PrintInfoLine()); } return(toPrint.ToString()); }
public string Print() { StringBuilder toPrint = new StringBuilder(); // Ensure enough columns for given rows if (Rows.Count > 0) { while (Rows.Select(R => R.Count).Max() > Columns.Count) { Columns.Add(""); } // Shortens overly lengthy fields this.ShortenFields(); } // Calculate max Column Lengths List <int> ColumnsMaxLengths = Columns.Select(C => 0).ToList(); for (int i = 0; i < Rows.Count; i++) { for (int j = 0; j < Rows[i].Count; j++) { ColumnsMaxLengths[j] = Math.Max(ColumnsMaxLengths[j], Rows[i][j].Length); } } bool empty = !(ColumnsMaxLengths.Max() > 0); for (int i = 0; i < ColumnsMaxLengths.Count; i++) { // Remove empty columns, if it is not a completely empty menu if (ColumnsMaxLengths[i] == 0 && !empty) { Rows.ForEach(R => R.RemoveAt(i)); Columns.RemoveAt(i); ColumnsMaxLengths.RemoveAt(i); i--; } else { // Column name is the max, if longer than all the column's fields ColumnsMaxLengths[i] = Math.Max(ColumnsMaxLengths[i], Columns[i].Length); } } toPrint.Append(EliteConsole.PrintInfoLine()); toPrint.Append(EliteConsole.PrintInfoLine()); switch (this.MenuType) { case EliteConsoleMenuType.Menu: toPrint.Append(PrintMenuType(ColumnsMaxLengths)); break; case EliteConsoleMenuType.Parameter: toPrint.Append(PrintParameterType(ColumnsMaxLengths)); break; case EliteConsoleMenuType.List: toPrint.Append(PrintListType(ColumnsMaxLengths)); break; } if (this.PrintEndBuffer) { toPrint.Append(EliteConsole.PrintInfoLine()); toPrint.Append(EliteConsole.PrintInfoLine()); } return(toPrint.ToString()); }