wasSharpNET – Blame information for rev 11
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
9 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System; |
||
8 | using System.Collections.Generic; |
||
9 | using System.Linq; |
||
10 | |||
11 | namespace wasSharpNET.Console |
||
12 | { |
||
13 | public static class ConsoleExtensions |
||
14 | { |
||
15 | public enum ConsoleTextAlignment |
||
16 | { |
||
17 | TOP_LEFT, |
||
18 | TOP_CENTER, |
||
19 | TOP_RIGHT |
||
20 | } |
||
21 | |||
22 | public static void WriteLine(this object data, ConsoleColor foreground, |
||
23 | ConsoleColor background) |
||
24 | { |
||
25 | var cFG = System.Console.ForegroundColor; |
||
26 | var cBG = System.Console.BackgroundColor; |
||
27 | System.Console.ForegroundColor = foreground; |
||
28 | System.Console.BackgroundColor = background; |
||
29 | System.Console.WriteLine(data); |
||
30 | System.Console.ForegroundColor = cFG; |
||
31 | System.Console.BackgroundColor = cBG; |
||
32 | } |
||
33 | |||
34 | public static void WriteLine(this object data, ConsoleColor foreground) |
||
35 | { |
||
36 | var cFG = System.Console.ForegroundColor; |
||
37 | System.Console.ForegroundColor = foreground; |
||
38 | System.Console.WriteLine(data); |
||
39 | System.Console.ForegroundColor = cFG; |
||
40 | } |
||
41 | |||
42 | public static void Write(this object data, ConsoleColor foreground, |
||
43 | ConsoleColor background) |
||
44 | { |
||
45 | var cFG = System.Console.ForegroundColor; |
||
46 | var cBG = System.Console.BackgroundColor; |
||
47 | System.Console.ForegroundColor = foreground; |
||
48 | System.Console.BackgroundColor = background; |
||
49 | System.Console.Write(data); |
||
50 | System.Console.ForegroundColor = cFG; |
||
51 | System.Console.BackgroundColor = cBG; |
||
52 | } |
||
53 | |||
54 | public static void WriteLine(this object data, ConsoleTextAlignment alignment) |
||
55 | { |
||
56 | switch (alignment) |
||
57 | { |
||
58 | case ConsoleTextAlignment.TOP_CENTER: |
||
11 | office | 59 | System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); |
9 | office | 60 | WriteLine(data, System.Console.ForegroundColor, System.Console.BackgroundColor); |
61 | break; |
||
11 | office | 62 | |
9 | office | 63 | default: |
64 | throw new NotImplementedException(); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | public static void WriteLine(this object data, ConsoleTextAlignment alignment, ConsoleColor foregroundColor) |
||
69 | { |
||
70 | switch (alignment) |
||
71 | { |
||
72 | case ConsoleTextAlignment.TOP_CENTER: |
||
73 | System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); |
||
74 | WriteLine(data, foregroundColor, System.Console.BackgroundColor); |
||
75 | break; |
||
11 | office | 76 | |
9 | office | 77 | default: |
78 | throw new NotImplementedException(); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public static void Write(this object data, ConsoleTextAlignment alignment) |
||
83 | { |
||
84 | switch (alignment) |
||
85 | { |
||
86 | case ConsoleTextAlignment.TOP_CENTER: |
||
11 | office | 87 | System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); |
9 | office | 88 | Write(data, System.Console.ForegroundColor, System.Console.BackgroundColor); |
89 | break; |
||
11 | office | 90 | |
9 | office | 91 | default: |
92 | throw new NotImplementedException(); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | public static void WriteLine(this IEnumerable<object> data, ConsoleTextAlignment alignment) |
||
97 | { |
||
98 | switch (alignment) |
||
99 | { |
||
100 | case ConsoleTextAlignment.TOP_CENTER: |
||
101 | var textBlock = data.Select(o => o.ToString()).ToArray(); |
||
11 | office | 102 | var padding = Math.Max(System.Console.WindowWidth / 2 - textBlock.Select(o => o.Length).Max() / 2, 0); |
9 | office | 103 | foreach (var line in data) |
104 | { |
||
105 | System.Console.CursorLeft = padding; |
||
106 | WriteLine(line, System.Console.ForegroundColor, System.Console.BackgroundColor); |
||
107 | } |
||
108 | break; |
||
11 | office | 109 | |
9 | office | 110 | default: |
111 | throw new NotImplementedException(); |
||
112 | } |
||
113 | } |
||
114 | } |
||
11 | office | 115 | } |