-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutput.cs
More file actions
41 lines (32 loc) · 1.08 KB
/
Copy pathOutput.cs
File metadata and controls
41 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Spectre.Console;
namespace csvcat;
public class OutputTable
{
const string _oddLine = "[blue]";
const string _evenLine = "[orange1]";
const string _lineBreak = "[/]";
public static void PrintTable(CsvObj csvobj)
{
var header = csvobj.Header;
var csvlines = csvobj.CsvLines;
Table table = new()
{
Border = TableBorder.Simple
};
table.AddColumns(header.ToArray());
// Set line colors
Enumerable.Range(0, csvlines.Count)
.Select((line, index) => line % 2 == 0 ? (_oddLine, index) : (_evenLine, index))
.ToList()
.ForEach(x => table.AddRow(FormatTableRow(x.Item1, csvlines[index: x.index])));
AnsiConsole.Write(table);
}
private static Markup[] FormatTableRow(string color, List<string> row)
{
int rowSize = row.Count;
var formattedRow = new Markup[rowSize];
for (int i = 0; i < rowSize; i++)
formattedRow[i] = new Markup(color + Markup.Escape(row[i]) + _lineBreak);
return formattedRow;
}
}