wasSharpNET – Diff between revs 22 and 27

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 22 Rev 27
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6   6  
7 using System; 7 using System;
8 using System.Collections.Generic; 8 using System.Collections.Generic;
9 using System.Linq; 9 using System.Linq;
10   10  
11 namespace wasSharpNET.Console 11 namespace wasSharpNET.Console
12 { 12 {
13 public static class ConsoleExtensions 13 public static class ConsoleExtensions
14 { 14 {
15 public enum ConsoleTextAlignment 15 public enum ConsoleTextAlignment
16 { 16 {
17 TOP_LEFT, 17 TOP_LEFT,
18 TOP_CENTER, 18 TOP_CENTER,
19 TOP_RIGHT 19 TOP_RIGHT
20 } 20 }
21   21  
22 public static void WriteLine(this object data, ConsoleColor foreground, 22 public static void WriteLine(this object data, ConsoleColor foreground,
23 ConsoleColor background) 23 ConsoleColor background)
24 { 24 {
25 var cFG = System.Console.ForegroundColor; 25 var cFG = System.Console.ForegroundColor;
26 var cBG = System.Console.BackgroundColor; 26 var cBG = System.Console.BackgroundColor;
27 System.Console.ForegroundColor = foreground; 27 System.Console.ForegroundColor = foreground;
28 System.Console.BackgroundColor = background; 28 System.Console.BackgroundColor = background;
29 System.Console.WriteLine(data); 29 System.Console.WriteLine(data);
30 System.Console.ForegroundColor = cFG; 30 System.Console.ForegroundColor = cFG;
31 System.Console.BackgroundColor = cBG; 31 System.Console.BackgroundColor = cBG;
32 } 32 }
33   33  
34 public static void WriteLine(this object data, ConsoleColor foreground) 34 public static void WriteLine(this object data, ConsoleColor foreground)
35 { 35 {
36 var cFG = System.Console.ForegroundColor; 36 var cFG = System.Console.ForegroundColor;
37 System.Console.ForegroundColor = foreground; 37 System.Console.ForegroundColor = foreground;
38 System.Console.WriteLine(data); 38 System.Console.WriteLine(data);
39 System.Console.ForegroundColor = cFG; 39 System.Console.ForegroundColor = cFG;
40 } 40 }
41   41  
42 public static void WriteLine(this object data) 42 public static void WriteLine(this object data)
43 { 43 {
44 System.Console.WriteLine(data); 44 System.Console.WriteLine(data);
45 } 45 }
46   46  
47 public static void Write(this object data, ConsoleColor foreground, 47 public static void Write(this object data, ConsoleColor foreground,
48 ConsoleColor background) 48 ConsoleColor background)
49 { 49 {
50 var cFG = System.Console.ForegroundColor; 50 var cFG = System.Console.ForegroundColor;
51 var cBG = System.Console.BackgroundColor; 51 var cBG = System.Console.BackgroundColor;
52 System.Console.ForegroundColor = foreground; 52 System.Console.ForegroundColor = foreground;
53 System.Console.BackgroundColor = background; 53 System.Console.BackgroundColor = background;
54 System.Console.Write(data); 54 System.Console.Write(data);
55 System.Console.ForegroundColor = cFG; 55 System.Console.ForegroundColor = cFG;
56 System.Console.BackgroundColor = cBG; 56 System.Console.BackgroundColor = cBG;
57 } 57 }
58   58  
59 public static void Write(this object data, ConsoleColor foreground) 59 public static void Write(this object data, ConsoleColor foreground)
60 { 60 {
61 var cFG = System.Console.ForegroundColor; 61 var cFG = System.Console.ForegroundColor;
62 System.Console.ForegroundColor = foreground; 62 System.Console.ForegroundColor = foreground;
63 System.Console.Write(data); 63 System.Console.Write(data);
64 System.Console.ForegroundColor = cFG; 64 System.Console.ForegroundColor = cFG;
65 } 65 }
66   66  
67 public static void WriteLine(this object data, ConsoleTextAlignment alignment) 67 public static void WriteLine(this object data, ConsoleTextAlignment alignment)
68 { 68 {
69 switch (alignment) 69 switch (alignment)
70 { 70 {
71 case ConsoleTextAlignment.TOP_CENTER: 71 case ConsoleTextAlignment.TOP_CENTER:
72 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); 72 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2,
-   73 0);
73 System.Console.WriteLine(data); 74 System.Console.WriteLine(data);
74 break; 75 break;
75   76  
76 default: 77 default:
77 throw new NotImplementedException(); 78 throw new NotImplementedException();
78 } 79 }
79 } 80 }
80   81  
81 public static void WriteLine(this object data, ConsoleTextAlignment alignment, ConsoleColor foregroundColor) 82 public static void WriteLine(this object data, ConsoleTextAlignment alignment, ConsoleColor foregroundColor)
82 { 83 {
83 switch (alignment) 84 switch (alignment)
84 { 85 {
85 case ConsoleTextAlignment.TOP_CENTER: 86 case ConsoleTextAlignment.TOP_CENTER:
86 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); 87 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2,
-   88 0);
87 WriteLine(data, foregroundColor); 89 WriteLine(data, foregroundColor);
88 break; 90 break;
89   91  
90 case ConsoleTextAlignment.TOP_LEFT: 92 case ConsoleTextAlignment.TOP_LEFT:
91 WriteLine(data, foregroundColor); 93 WriteLine(data, foregroundColor);
92 break; 94 break;
93   95  
94 default: 96 default:
95 throw new NotImplementedException(); 97 throw new NotImplementedException();
96 } 98 }
97 } 99 }
98   100  
99 public static void Write(this object data, ConsoleTextAlignment alignment) 101 public static void Write(this object data, ConsoleTextAlignment alignment)
100 { 102 {
101 switch (alignment) 103 switch (alignment)
102 { 104 {
103 case ConsoleTextAlignment.TOP_CENTER: 105 case ConsoleTextAlignment.TOP_CENTER:
104 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); 106 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2,
-   107 0);
105 System.Console.Write(data); 108 System.Console.Write(data);
106 break; 109 break;
107   110  
108 case ConsoleTextAlignment.TOP_LEFT: 111 case ConsoleTextAlignment.TOP_LEFT:
109 System.Console.Write(data); 112 System.Console.Write(data);
110 break; 113 break;
111   114  
112 default: 115 default:
113 throw new NotImplementedException(); 116 throw new NotImplementedException();
114 } 117 }
115 } 118 }
116   119  
117 public static void WriteLine(this IEnumerable<object> data, ConsoleTextAlignment alignment) 120 public static void WriteLine(this IEnumerable<object> data, ConsoleTextAlignment alignment)
118 { 121 {
119 switch (alignment) 122 switch (alignment)
120 { 123 {
121 case ConsoleTextAlignment.TOP_CENTER: 124 case ConsoleTextAlignment.TOP_CENTER:
122 var enumerable = data as IList<object> ?? data.ToList(); 125 var enumerable = data as IList<object> ?? data.ToList();
123 var textBlock = enumerable.Select(o => o.ToString()).ToArray(); 126 var textBlock = enumerable.Select(o => o.ToString()).ToArray();
124 var padding = Math.Max(System.Console.WindowWidth / 2 - textBlock.Select(o => o.Length).Max() / 2, 0); 127 var padding = Math.Max(System.Console.WindowWidth / 2 - textBlock.Select(o => o.Length).Max() / 2,
-   128 0);
125 foreach (var line in enumerable) 129 foreach (var line in enumerable)
126 { 130 {
127 System.Console.CursorLeft = padding; 131 System.Console.CursorLeft = padding;
128 WriteLine(line, System.Console.ForegroundColor); 132 WriteLine(line, System.Console.ForegroundColor);
129 } 133 }
130 break; 134 break;
131   135  
132 case ConsoleTextAlignment.TOP_LEFT: 136 case ConsoleTextAlignment.TOP_LEFT:
133 foreach (var line in data) 137 foreach (var line in data)
134 { -  
135 WriteLine(line, System.Console.ForegroundColor); 138 WriteLine(line, System.Console.ForegroundColor);
136 } -  
137 break; 139 break;
138   140  
139 default: 141 default:
140 throw new NotImplementedException(); 142 throw new NotImplementedException();
141 } 143 }
142 } 144 }
143 } 145 }
144 } 146 }
145   147  
-   148
Generated by GNU Enscript 1.6.5.90.
-   149  
-   150  
-   151