wasSharpNET – Blame information for rev 27

Subversion Repositories:
Rev:
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  
12 office 42 public static void WriteLine(this object data)
43 {
44 System.Console.WriteLine(data);
45 }
46  
9 office 47 public static void Write(this object data, ConsoleColor foreground,
48 ConsoleColor background)
49 {
50 var cFG = System.Console.ForegroundColor;
51 var cBG = System.Console.BackgroundColor;
52 System.Console.ForegroundColor = foreground;
53 System.Console.BackgroundColor = background;
54 System.Console.Write(data);
55 System.Console.ForegroundColor = cFG;
56 System.Console.BackgroundColor = cBG;
57 }
58  
12 office 59 public static void Write(this object data, ConsoleColor foreground)
60 {
61 var cFG = System.Console.ForegroundColor;
62 System.Console.ForegroundColor = foreground;
63 System.Console.Write(data);
64 System.Console.ForegroundColor = cFG;
65 }
66  
9 office 67 public static void WriteLine(this object data, ConsoleTextAlignment alignment)
68 {
69 switch (alignment)
70 {
71 case ConsoleTextAlignment.TOP_CENTER:
27 office 72 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2,
73 0);
12 office 74 System.Console.WriteLine(data);
9 office 75 break;
11 office 76  
9 office 77 default:
78 throw new NotImplementedException();
79 }
80 }
81  
82 public static void WriteLine(this object data, ConsoleTextAlignment alignment, ConsoleColor foregroundColor)
83 {
84 switch (alignment)
85 {
86 case ConsoleTextAlignment.TOP_CENTER:
27 office 87 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2,
88 0);
12 office 89 WriteLine(data, foregroundColor);
9 office 90 break;
11 office 91  
12 office 92 case ConsoleTextAlignment.TOP_LEFT:
93 WriteLine(data, foregroundColor);
94 break;
95  
9 office 96 default:
97 throw new NotImplementedException();
98 }
99 }
100  
101 public static void Write(this object data, ConsoleTextAlignment alignment)
102 {
103 switch (alignment)
104 {
105 case ConsoleTextAlignment.TOP_CENTER:
27 office 106 System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2,
107 0);
12 office 108 System.Console.Write(data);
9 office 109 break;
11 office 110  
12 office 111 case ConsoleTextAlignment.TOP_LEFT:
112 System.Console.Write(data);
113 break;
114  
9 office 115 default:
116 throw new NotImplementedException();
117 }
118 }
119  
120 public static void WriteLine(this IEnumerable<object> data, ConsoleTextAlignment alignment)
121 {
122 switch (alignment)
123 {
124 case ConsoleTextAlignment.TOP_CENTER:
22 office 125 var enumerable = data as IList<object> ?? data.ToList();
126 var textBlock = enumerable.Select(o => o.ToString()).ToArray();
27 office 127 var padding = Math.Max(System.Console.WindowWidth / 2 - textBlock.Select(o => o.Length).Max() / 2,
128 0);
22 office 129 foreach (var line in enumerable)
9 office 130 {
131 System.Console.CursorLeft = padding;
12 office 132 WriteLine(line, System.Console.ForegroundColor);
9 office 133 }
134 break;
11 office 135  
12 office 136 case ConsoleTextAlignment.TOP_LEFT:
137 foreach (var line in data)
138 WriteLine(line, System.Console.ForegroundColor);
139 break;
140  
9 office 141 default:
142 throw new NotImplementedException();
143 }
144 }
145 }
27 office 146 }