aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/LocalConsole.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/LocalConsole.cs86
1 files changed, 84 insertions, 2 deletions
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs
index ca57bd6..4d768b9 100644
--- a/OpenSim/Framework/Console/LocalConsole.cs
+++ b/OpenSim/Framework/Console/LocalConsole.cs
@@ -30,6 +30,7 @@ using System.Collections.Generic;
30using System.Diagnostics; 30using System.Diagnostics;
31using System.Reflection; 31using System.Reflection;
32using System.Text; 32using System.Text;
33using System.Text.RegularExpressions;
33using System.Threading; 34using System.Threading;
34using log4net; 35using log4net;
35 36
@@ -50,6 +51,28 @@ namespace OpenSim.Framework.Console
50 private bool echo = true; 51 private bool echo = true;
51 private List<string> history = new List<string>(); 52 private List<string> history = new List<string>();
52 53
54 private static readonly ConsoleColor[] Colors = {
55 // the dark colors don't seem to be visible on some black background terminals like putty :(
56 //ConsoleColor.DarkBlue,
57 //ConsoleColor.DarkGreen,
58 //ConsoleColor.DarkCyan,
59 //ConsoleColor.DarkMagenta,
60 //ConsoleColor.DarkYellow,
61 ConsoleColor.Gray,
62 //ConsoleColor.DarkGray,
63 ConsoleColor.Blue,
64 ConsoleColor.Green,
65 ConsoleColor.Cyan,
66 ConsoleColor.Magenta,
67 ConsoleColor.Yellow
68 };
69
70 private static ConsoleColor DeriveColor(string input)
71 {
72 // it is important to do Abs, hash values can be negative
73 return Colors[(Math.Abs(input.ToUpper().GetHashCode()) % Colors.Length)];
74 }
75
53 public LocalConsole(string defaultPrompt) : base(defaultPrompt) 76 public LocalConsole(string defaultPrompt) : base(defaultPrompt)
54 { 77 {
55 } 78 }
@@ -158,13 +181,72 @@ namespace OpenSim.Framework.Console
158 Monitor.Exit(cmdline); 181 Monitor.Exit(cmdline);
159 } 182 }
160 183
184 private void WriteColorText(ConsoleColor color, string sender)
185 {
186 try
187 {
188 lock (this)
189 {
190 try
191 {
192 System.Console.ForegroundColor = color;
193 System.Console.Write(sender);
194 System.Console.ResetColor();
195 }
196 catch (ArgumentNullException)
197 {
198 // Some older systems dont support coloured text.
199 System.Console.WriteLine(sender);
200 }
201 }
202 }
203 catch (ObjectDisposedException)
204 {
205 }
206 }
207
208 private void WriteLocalText(string text, string level)
209 {
210 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)";
211
212 Regex RE = new Regex(regex, RegexOptions.Multiline);
213 MatchCollection matches = RE.Matches(text);
214
215 string outText = text;
216 ConsoleColor color = ConsoleColor.White;
217
218 if (matches.Count == 1)
219 {
220 outText = matches[0].Groups["End"].Value;
221 System.Console.Write(matches[0].Groups["Front"].Value);
222
223 System.Console.Write("[");
224 WriteColorText(DeriveColor(matches[0].Groups["Category"].Value),
225 matches[0].Groups["Category"].Value);
226 System.Console.Write("]:");
227 }
228
229 if (level == "error")
230 color = ConsoleColor.Red;
231 else if (level == "warn")
232 color = ConsoleColor.Yellow;
233
234 WriteColorText(color, outText);
235 System.Console.WriteLine();
236 }
237
161 public override void Output(string text) 238 public override void Output(string text)
162 { 239 {
240 Output(text, "normal");
241 }
242
243 public override void Output(string text, string level)
244 {
163 lock (cmdline) 245 lock (cmdline)
164 { 246 {
165 if (y == -1) 247 if (y == -1)
166 { 248 {
167 System.Console.WriteLine(text); 249 WriteLocalText(text, level);
168 250
169 return; 251 return;
170 } 252 }
@@ -180,7 +262,7 @@ namespace OpenSim.Framework.Console
180 y = SetCursorTop(y); 262 y = SetCursorTop(y);
181 System.Console.CursorLeft = 0; 263 System.Console.CursorLeft = 0;
182 264
183 System.Console.WriteLine(text); 265 WriteLocalText(text, level);
184 266
185 y = System.Console.CursorTop; 267 y = System.Console.CursorTop;
186 268