wasSharpNET – Diff between revs 9 and 11

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 9 Rev 11
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   -  
22   21  
23 public static void WriteLine(this object data, ConsoleColor foreground, 22 public static void WriteLine(this object data, ConsoleColor foreground,
24 ConsoleColor background) 23 ConsoleColor background)
25 { 24 {
26 var cFG = System.Console.ForegroundColor; 25 var cFG = System.Console.ForegroundColor;
27 var cBG = System.Console.BackgroundColor; 26 var cBG = System.Console.BackgroundColor;
28 System.Console.ForegroundColor = foreground; 27 System.Console.ForegroundColor = foreground;
29 System.Console.BackgroundColor = background; 28 System.Console.BackgroundColor = background;
30 System.Console.WriteLine(data); 29 System.Console.WriteLine(data);
31 System.Console.ForegroundColor = cFG; 30 System.Console.ForegroundColor = cFG;
32 System.Console.BackgroundColor = cBG; 31 System.Console.BackgroundColor = cBG;
33 } 32 }
34   33  
35 public static void WriteLine(this object data, ConsoleColor foreground) 34 public static void WriteLine(this object data, ConsoleColor foreground)
36 { 35 {
37 var cFG = System.Console.ForegroundColor; 36 var cFG = System.Console.ForegroundColor;
38 System.Console.ForegroundColor = foreground; 37 System.Console.ForegroundColor = foreground;
39 System.Console.WriteLine(data); 38 System.Console.WriteLine(data);
40 System.Console.ForegroundColor = cFG; 39 System.Console.ForegroundColor = cFG;
41 } 40 }
42   41  
43 public static void Write(this object data, ConsoleColor foreground, 42 public static void Write(this object data, ConsoleColor foreground,
44 ConsoleColor background) 43 ConsoleColor background)
45 { 44 {
46 var cFG = System.Console.ForegroundColor; 45 var cFG = System.Console.ForegroundColor;
47 var cBG = System.Console.BackgroundColor; 46 var cBG = System.Console.BackgroundColor;
48 System.Console.ForegroundColor = foreground; 47 System.Console.ForegroundColor = foreground;
49 System.Console.BackgroundColor = background; 48 System.Console.BackgroundColor = background;
50 System.Console.Write(data); 49 System.Console.Write(data);
51 System.Console.ForegroundColor = cFG; 50 System.Console.ForegroundColor = cFG;
52 System.Console.BackgroundColor = cBG; 51 System.Console.BackgroundColor = cBG;
53 } 52 }
54   53  
55 public static void WriteLine(this object data, ConsoleTextAlignment alignment) 54 public static void WriteLine(this object data, ConsoleTextAlignment alignment)
56 { 55 {
57 switch (alignment) 56 switch (alignment)
58 { 57 {
59 case ConsoleTextAlignment.TOP_CENTER: 58 case ConsoleTextAlignment.TOP_CENTER:
60 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth/2 - data.ToString().Length/2, 0); 59 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0);
61 WriteLine(data, System.Console.ForegroundColor, System.Console.BackgroundColor); 60 WriteLine(data, System.Console.ForegroundColor, System.Console.BackgroundColor);
62 break; 61 break;
-   62  
63 default: 63 default:
64 throw new NotImplementedException(); 64 throw new NotImplementedException();
65 } 65 }
66 } 66 }
67   67  
68 public static void WriteLine(this object data, ConsoleTextAlignment alignment, ConsoleColor foregroundColor) 68 public static void WriteLine(this object data, ConsoleTextAlignment alignment, ConsoleColor foregroundColor)
69 { 69 {
70 switch (alignment) 70 switch (alignment)
71 { 71 {
72 case ConsoleTextAlignment.TOP_CENTER: 72 case ConsoleTextAlignment.TOP_CENTER:
73 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); 73 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0);
74 WriteLine(data, foregroundColor, System.Console.BackgroundColor); 74 WriteLine(data, foregroundColor, System.Console.BackgroundColor);
75 break; 75 break;
-   76  
76 default: 77 default:
77 throw new NotImplementedException(); 78 throw new NotImplementedException();
78 } 79 }
79 } 80 }
80   81  
81 public static void Write(this object data, ConsoleTextAlignment alignment) 82 public static void Write(this object data, ConsoleTextAlignment alignment)
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, 0);
87 Write(data, System.Console.ForegroundColor, System.Console.BackgroundColor); 88 Write(data, System.Console.ForegroundColor, System.Console.BackgroundColor);
88 break; 89 break;
-   90  
89 default: 91 default:
90 throw new NotImplementedException(); 92 throw new NotImplementedException();
91 } 93 }
92 } 94 }
93   95  
94 public static void WriteLine(this IEnumerable<object> data, ConsoleTextAlignment alignment) 96 public static void WriteLine(this IEnumerable<object> data, ConsoleTextAlignment alignment)
95 { 97 {
96 switch (alignment) 98 switch (alignment)
97 { 99 {
98 case ConsoleTextAlignment.TOP_CENTER: 100 case ConsoleTextAlignment.TOP_CENTER:
99 var textBlock = data.Select(o => o.ToString()).ToArray(); 101 var textBlock = data.Select(o => o.ToString()).ToArray();
100 var padding = Math.Max(System.Console.WindowWidth/2 - textBlock.Select(o => o.Length).Max()/2, 0); 102 var padding = Math.Max(System.Console.WindowWidth / 2 - textBlock.Select(o => o.Length).Max() / 2, 0);
101 foreach (var line in data) 103 foreach (var line in data)
102 { 104 {
103 System.Console.CursorLeft = padding; 105 System.Console.CursorLeft = padding;
104 WriteLine(line, System.Console.ForegroundColor, System.Console.BackgroundColor); 106 WriteLine(line, System.Console.ForegroundColor, System.Console.BackgroundColor);
105 } 107 }
106 break; 108 break;
-   109  
107 default: 110 default:
108 throw new NotImplementedException(); 111 throw new NotImplementedException();
109 } 112 }
110 } 113 }
111 } 114 }
112 } -  
113   115 }
-   116  
114
Generated by GNU Enscript 1.6.5.90.
-  
115   -  
116   -  
117   -