-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable.cs
More file actions
123 lines (105 loc) · 3.9 KB
/
Table.cs
File metadata and controls
123 lines (105 loc) · 3.9 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Zyxel
{
class Table
{
public const uint Padding = 3;
public const uint SubPadding = 2;
public const string PaddingLine = " ";
public string Data
{
get;
set;
}
private List<List<string>> data = new List<List<string>>();
private string[] title;
/// <summary>
/// Добавить заголовочную строку
/// </summary>
public void AddTitle(params string[] data)
{
AddLine(data);
title = data;
}
/// <summary>
/// Добавить пустую строку
/// </summary>
public void AddLine()
{
data.Add(new List<string>());
}
/// <summary>
/// Добавить строку из списка
/// </summary>
/// <param name="line">Список строки</param>
public void AddLine(List<string> line)
{
data.Add(line);
}
/// <summary>
/// Добавляет строку из массива
/// </summary>
/// <param name="data">Массив строк</param>
public void AddLine(params string[] data)
{
var tmp = new List<string>();
foreach (var item in data)
tmp.Add(item);
AddLine(tmp);
}
/// <summary>
/// Очищает таблицу, но оставляет заглавие
/// </summary>
/// <param name="data">Массив строк</param>
public void Clear()
{
data.Clear();
AddLine(title);
}
/// <summary>
/// Печать таблицы
/// </summary>
public void Print(string[] WP)
{
int[] bufer = new int[data[0].Count];
bufer.Select(s => s = 0);
for (int i = 0; i < data.Count; i++)
for (int a = 0; a < data[i].Count; a++)
if (data[i][a].Length > bufer[a])
bufer[a] = data[i][a].Length;
Console.Clear();
Data = "";
Console.BufferHeight = (data.Count + 5) <= Console.WindowHeight ? Console.WindowHeight + 1 : (data.Count + 5);
//Console.BufferWidth = data.Max(s => s.Max(a => a.Length)) * bufer.Length;
int width = Console.WindowWidth;
for (int i = 0; i < width - Padding; i++) if (i < (int)Padding) Console.Write(' '); else Console.Write('-');
Console.WriteLine();
Console.WriteLine();
for (int i = 0; i < data.Count; i++)
{
for (int p = 0; p < Padding + SubPadding; p++) Console.Write(' ');
for (int ia = 0; ia < data[i].Count; ia++)
{
if (WP.Contains(data[i][3].Split('/')[1]))
Console.BackgroundColor = ConsoleColor.Red;
else
Console.BackgroundColor = ConsoleColor.Black;
Console.Write(data[i][ia]);
Data += data[i][ia];
for (int q = 0; q < (bufer[ia] - data[i][ia].Length) + SubPadding; q++)
{
Console.Write(' ');
Data += " ";
};
Console.BackgroundColor = ConsoleColor.Black;
}
Console.WriteLine();
Data += Environment.NewLine;
}
for (int i = 0; i < width - Padding; i++) if (i < (int)Padding) Console.Write(' '); else Console.Write('-');
}
}
}