aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKevin Houlihan2011-09-14 23:02:35 +0100
committerJustin Clark-Casey (justincc)2011-09-16 20:24:47 +0100
commit903d5c02cb372af3fef5884d95312110229fbc1e (patch)
tree984bfe1856a0f8338c65b3b0cbbd9ff49d242843
parentPasswords could be revealed in console by pressing backspace. (diff)
downloadopensim-SC-903d5c02cb372af3fef5884d95312110229fbc1e.zip
opensim-SC-903d5c02cb372af3fef5884d95312110229fbc1e.tar.gz
opensim-SC-903d5c02cb372af3fef5884d95312110229fbc1e.tar.bz2
opensim-SC-903d5c02cb372af3fef5884d95312110229fbc1e.tar.xz
Updated some variables to be closer to the coding standards (and easier to understand).
There were a few variables in LocalConsole with single character names, and the class fields did not use the m_ prefix. I also removed a redundant variable, h. It was being set to 1 in a couple of places, and incremented in another, but never actually used.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/LocalConsole.cs179
1 files changed, 88 insertions, 91 deletions
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs
index 05a3aee..7c8626d 100644
--- a/OpenSim/Framework/Console/LocalConsole.cs
+++ b/OpenSim/Framework/Console/LocalConsole.cs
@@ -46,12 +46,11 @@ namespace OpenSim.Framework.Console
46 // private readonly object m_syncRoot = new object(); 46 // private readonly object m_syncRoot = new object();
47 private const string LOGLEVEL_NONE = "(none)"; 47 private const string LOGLEVEL_NONE = "(none)";
48 48
49 private int y = -1; 49 private int m_cursorYPosition = -1;
50 private int cp = 0; 50 private int m_cursorXPosition = 0;
51 private int h = 1; 51 private StringBuilder m_commandLine = new StringBuilder();
52 private StringBuilder cmdline = new StringBuilder(); 52 private bool m_echo = true;
53 private bool echo = true; 53 private List<string> m_history = new List<string>();
54 private List<string> history = new List<string>();
55 54
56 private static readonly ConsoleColor[] Colors = { 55 private static readonly ConsoleColor[] Colors = {
57 // the dark colors don't seem to be visible on some black background terminals like putty :( 56 // the dark colors don't seem to be visible on some black background terminals like putty :(
@@ -81,10 +80,10 @@ namespace OpenSim.Framework.Console
81 80
82 private void AddToHistory(string text) 81 private void AddToHistory(string text)
83 { 82 {
84 while (history.Count >= 100) 83 while (m_history.Count >= 100)
85 history.RemoveAt(0); 84 m_history.RemoveAt(0);
86 85
87 history.Add(text); 86 m_history.Add(text);
88 } 87 }
89 88
90 /// <summary> 89 /// <summary>
@@ -111,11 +110,11 @@ namespace OpenSim.Framework.Console
111 } 110 }
112 else 111 else
113 { 112 {
114 int bw = System.Console.BufferWidth; 113 int bufferWidth = System.Console.BufferWidth;
115 114
116 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657) 115 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657)
117 if (bw > 0 && left >= bw) 116 if (bufferWidth > 0 && left >= bufferWidth)
118 System.Console.CursorLeft = bw - 1; 117 System.Console.CursorLeft = bufferWidth - 1;
119 } 118 }
120 119
121 if (top < 0) 120 if (top < 0)
@@ -124,11 +123,11 @@ namespace OpenSim.Framework.Console
124 } 123 }
125 else 124 else
126 { 125 {
127 int bh = System.Console.BufferHeight; 126 int bufferHeight = System.Console.BufferHeight;
128 127
129 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657) 128 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657)
130 if (bh > 0 && top >= bh) 129 if (bufferHeight > 0 && top >= bufferHeight)
131 top = bh - 1; 130 top = bufferHeight - 1;
132 } 131 }
133 132
134 System.Console.CursorTop = top; 133 System.Console.CursorTop = top;
@@ -160,10 +159,10 @@ namespace OpenSim.Framework.Console
160 } 159 }
161 else 160 else
162 { 161 {
163 int bh = System.Console.BufferHeight; 162 int bufferHeight = System.Console.BufferHeight;
164 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657) 163 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657)
165 if (bh > 0 && top >= bh) 164 if (bufferHeight > 0 && top >= bufferHeight)
166 System.Console.CursorTop = bh - 1; 165 System.Console.CursorTop = bufferHeight - 1;
167 } 166 }
168 167
169 if (left < 0) 168 if (left < 0)
@@ -172,11 +171,11 @@ namespace OpenSim.Framework.Console
172 } 171 }
173 else 172 else
174 { 173 {
175 int bw = System.Console.BufferWidth; 174 int bufferWidth = System.Console.BufferWidth;
176 175
177 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657) 176 // On Mono 2.4.2.3 (and possibly above), the buffer value is sometimes erroneously zero (Mantis 4657)
178 if (bw > 0 && left >= bw) 177 if (bufferWidth > 0 && left >= bufferWidth)
179 left = bw - 1; 178 left = bufferWidth - 1;
180 } 179 }
181 180
182 System.Console.CursorLeft = left; 181 System.Console.CursorLeft = left;
@@ -186,31 +185,30 @@ namespace OpenSim.Framework.Console
186 185
187 private void Show() 186 private void Show()
188 { 187 {
189 lock (cmdline) 188 lock (m_commandLine)
190 { 189 {
191 if (y == -1 || System.Console.BufferWidth == 0) 190 if (m_cursorYPosition == -1 || System.Console.BufferWidth == 0)
192 return; 191 return;
193 192
194 int xc = prompt.Length + cp; 193 int xc = prompt.Length + m_cursorXPosition;
195 int new_x = xc % System.Console.BufferWidth; 194 int new_x = xc % System.Console.BufferWidth;
196 int new_y = y + xc / System.Console.BufferWidth; 195 int new_y = m_cursorYPosition + xc / System.Console.BufferWidth;
197 int end_y = y + (cmdline.Length + prompt.Length) / System.Console.BufferWidth; 196 int end_y = m_cursorYPosition + (m_commandLine.Length + prompt.Length) / System.Console.BufferWidth;
198 if (end_y / System.Console.BufferWidth >= h) 197
199 h++;
200 if (end_y >= System.Console.BufferHeight) // wrap 198 if (end_y >= System.Console.BufferHeight) // wrap
201 { 199 {
202 y--; 200 m_cursorYPosition--;
203 new_y--; 201 new_y--;
204 SetCursorLeft(0); 202 SetCursorLeft(0);
205 SetCursorTop(System.Console.BufferHeight - 1); 203 SetCursorTop(System.Console.BufferHeight - 1);
206 System.Console.WriteLine(" "); 204 System.Console.WriteLine(" ");
207 } 205 }
208 206
209 y = SetCursorTop(y); 207 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
210 SetCursorLeft(0); 208 SetCursorLeft(0);
211 209
212 if (echo) 210 if (m_echo)
213 System.Console.Write("{0}{1}", prompt, cmdline); 211 System.Console.Write("{0}{1}", prompt, m_commandLine);
214 else 212 else
215 System.Console.Write("{0}", prompt); 213 System.Console.Write("{0}", prompt);
216 214
@@ -221,20 +219,20 @@ namespace OpenSim.Framework.Console
221 219
222 public override void LockOutput() 220 public override void LockOutput()
223 { 221 {
224 Monitor.Enter(cmdline); 222 Monitor.Enter(m_commandLine);
225 try 223 try
226 { 224 {
227 if (y != -1) 225 if (m_cursorYPosition != -1)
228 { 226 {
229 y = SetCursorTop(y); 227 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
230 System.Console.CursorLeft = 0; 228 System.Console.CursorLeft = 0;
231 229
232 int count = cmdline.Length + prompt.Length; 230 int count = m_commandLine.Length + prompt.Length;
233 231
234 while (count-- > 0) 232 while (count-- > 0)
235 System.Console.Write(" "); 233 System.Console.Write(" ");
236 234
237 y = SetCursorTop(y); 235 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
238 SetCursorLeft(0); 236 SetCursorLeft(0);
239 } 237 }
240 } 238 }
@@ -245,12 +243,12 @@ namespace OpenSim.Framework.Console
245 243
246 public override void UnlockOutput() 244 public override void UnlockOutput()
247 { 245 {
248 if (y != -1) 246 if (m_cursorYPosition != -1)
249 { 247 {
250 y = System.Console.CursorTop; 248 m_cursorYPosition = System.Console.CursorTop;
251 Show(); 249 Show();
252 } 250 }
253 Monitor.Exit(cmdline); 251 Monitor.Exit(m_commandLine);
254 } 252 }
255 253
256 private void WriteColorText(ConsoleColor color, string sender) 254 private void WriteColorText(ConsoleColor color, string sender)
@@ -317,29 +315,29 @@ namespace OpenSim.Framework.Console
317 315
318 public override void Output(string text, string level) 316 public override void Output(string text, string level)
319 { 317 {
320 lock (cmdline) 318 lock (m_commandLine)
321 { 319 {
322 if (y == -1) 320 if (m_cursorYPosition == -1)
323 { 321 {
324 WriteLocalText(text, level); 322 WriteLocalText(text, level);
325 323
326 return; 324 return;
327 } 325 }
328 326
329 y = SetCursorTop(y); 327 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
330 SetCursorLeft(0); 328 SetCursorLeft(0);
331 329
332 int count = cmdline.Length + prompt.Length; 330 int count = m_commandLine.Length + prompt.Length;
333 331
334 while (count-- > 0) 332 while (count-- > 0)
335 System.Console.Write(" "); 333 System.Console.Write(" ");
336 334
337 y = SetCursorTop(y); 335 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
338 SetCursorLeft(0); 336 SetCursorLeft(0);
339 337
340 WriteLocalText(text, level); 338 WriteLocalText(text, level);
341 339
342 y = System.Console.CursorTop; 340 m_cursorYPosition = System.Console.CursorTop;
343 341
344 Show(); 342 Show();
345 } 343 }
@@ -347,9 +345,9 @@ namespace OpenSim.Framework.Console
347 345
348 private bool ContextHelp() 346 private bool ContextHelp()
349 { 347 {
350 string[] words = Parser.Parse(cmdline.ToString()); 348 string[] words = Parser.Parse(m_commandLine.ToString());
351 349
352 bool trailingSpace = cmdline.ToString().EndsWith(" "); 350 bool trailingSpace = m_commandLine.ToString().EndsWith(" ");
353 351
354 // Allow ? through while typing a URI 352 // Allow ? through while typing a URI
355 // 353 //
@@ -368,19 +366,18 @@ namespace OpenSim.Framework.Console
368 366
369 public override string ReadLine(string p, bool isCommand, bool e) 367 public override string ReadLine(string p, bool isCommand, bool e)
370 { 368 {
371 h = 1; 369 m_cursorXPosition = 0;
372 cp = 0;
373 prompt = p; 370 prompt = p;
374 echo = e; 371 m_echo = e;
375 int historyLine = history.Count; 372 int historyLine = m_history.Count;
376 373
377 SetCursorLeft(0); // Needed for mono 374 SetCursorLeft(0); // Needed for mono
378 System.Console.Write(" "); // Needed for mono 375 System.Console.Write(" "); // Needed for mono
379 376
380 lock (cmdline) 377 lock (m_commandLine)
381 { 378 {
382 y = System.Console.CursorTop; 379 m_cursorYPosition = System.Console.CursorTop;
383 cmdline.Remove(0, cmdline.Length); 380 m_commandLine.Remove(0, m_commandLine.Length);
384 } 381 }
385 382
386 while (true) 383 while (true)
@@ -388,95 +385,95 @@ namespace OpenSim.Framework.Console
388 Show(); 385 Show();
389 386
390 ConsoleKeyInfo key = System.Console.ReadKey(true); 387 ConsoleKeyInfo key = System.Console.ReadKey(true);
391 char c = key.KeyChar; 388 char enteredChar = key.KeyChar;
392 389
393 if (!Char.IsControl(c)) 390 if (!Char.IsControl(enteredChar))
394 { 391 {
395 if (cp >= 318) 392 if (m_cursorXPosition >= 318)
396 continue; 393 continue;
397 394
398 if (c == '?' && isCommand) 395 if (enteredChar == '?' && isCommand)
399 { 396 {
400 if (ContextHelp()) 397 if (ContextHelp())
401 continue; 398 continue;
402 } 399 }
403 400
404 cmdline.Insert(cp, c); 401 m_commandLine.Insert(m_cursorXPosition, enteredChar);
405 cp++; 402 m_cursorXPosition++;
406 } 403 }
407 else 404 else
408 { 405 {
409 switch (key.Key) 406 switch (key.Key)
410 { 407 {
411 case ConsoleKey.Backspace: 408 case ConsoleKey.Backspace:
412 if (cp == 0) 409 if (m_cursorXPosition == 0)
413 break; 410 break;
414 cmdline.Remove(cp-1, 1); 411 m_commandLine.Remove(m_cursorXPosition-1, 1);
415 cp--; 412 m_cursorXPosition--;
416 413
417 SetCursorLeft(0); 414 SetCursorLeft(0);
418 y = SetCursorTop(y); 415 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
419 416
420 if (echo) 417 if (m_echo)
421 System.Console.Write("{0}{1} ", prompt, cmdline); 418 System.Console.Write("{0}{1} ", prompt, m_commandLine);
422 else 419 else
423 System.Console.Write("{0}", prompt); 420 System.Console.Write("{0}", prompt);
424 421
425 break; 422 break;
426 case ConsoleKey.End: 423 case ConsoleKey.End:
427 cp = cmdline.Length; 424 m_cursorXPosition = m_commandLine.Length;
428 break; 425 break;
429 case ConsoleKey.Home: 426 case ConsoleKey.Home:
430 cp = 0; 427 m_cursorXPosition = 0;
431 break; 428 break;
432 case ConsoleKey.UpArrow: 429 case ConsoleKey.UpArrow:
433 if (historyLine < 1) 430 if (historyLine < 1)
434 break; 431 break;
435 historyLine--; 432 historyLine--;
436 LockOutput(); 433 LockOutput();
437 cmdline.Remove(0, cmdline.Length); 434 m_commandLine.Remove(0, m_commandLine.Length);
438 cmdline.Append(history[historyLine]); 435 m_commandLine.Append(m_history[historyLine]);
439 cp = cmdline.Length; 436 m_cursorXPosition = m_commandLine.Length;
440 UnlockOutput(); 437 UnlockOutput();
441 break; 438 break;
442 case ConsoleKey.DownArrow: 439 case ConsoleKey.DownArrow:
443 if (historyLine >= history.Count) 440 if (historyLine >= m_history.Count)
444 break; 441 break;
445 historyLine++; 442 historyLine++;
446 LockOutput(); 443 LockOutput();
447 if (historyLine == history.Count) 444 if (historyLine == m_history.Count)
448 { 445 {
449 cmdline.Remove(0, cmdline.Length); 446 m_commandLine.Remove(0, m_commandLine.Length);
450 } 447 }
451 else 448 else
452 { 449 {
453 cmdline.Remove(0, cmdline.Length); 450 m_commandLine.Remove(0, m_commandLine.Length);
454 cmdline.Append(history[historyLine]); 451 m_commandLine.Append(m_history[historyLine]);
455 } 452 }
456 cp = cmdline.Length; 453 m_cursorXPosition = m_commandLine.Length;
457 UnlockOutput(); 454 UnlockOutput();
458 break; 455 break;
459 case ConsoleKey.LeftArrow: 456 case ConsoleKey.LeftArrow:
460 if (cp > 0) 457 if (m_cursorXPosition > 0)
461 cp--; 458 m_cursorXPosition--;
462 break; 459 break;
463 case ConsoleKey.RightArrow: 460 case ConsoleKey.RightArrow:
464 if (cp < cmdline.Length) 461 if (m_cursorXPosition < m_commandLine.Length)
465 cp++; 462 m_cursorXPosition++;
466 break; 463 break;
467 case ConsoleKey.Enter: 464 case ConsoleKey.Enter:
468 SetCursorLeft(0); 465 SetCursorLeft(0);
469 y = SetCursorTop(y); 466 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
470 467
471 System.Console.WriteLine(); 468 System.Console.WriteLine();
472 //Show(); 469 //Show();
473 470
474 lock (cmdline) 471 lock (m_commandLine)
475 { 472 {
476 y = -1; 473 m_cursorYPosition = -1;
477 } 474 }
478 475
479 string commandLine = cmdline.ToString(); 476 string commandLine = m_commandLine.ToString();
480 477
481 if (isCommand) 478 if (isCommand)
482 { 479 {
@@ -484,12 +481,12 @@ namespace OpenSim.Framework.Console
484 481
485 if (cmd.Length != 0) 482 if (cmd.Length != 0)
486 { 483 {
487 int i; 484 int index;
488 485
489 for (i=0 ; i < cmd.Length ; i++) 486 for (index=0 ; index < cmd.Length ; index++)
490 { 487 {
491 if (cmd[i].Contains(" ")) 488 if (cmd[index].Contains(" "))
492 cmd[i] = "\"" + cmd[i] + "\""; 489 cmd[index] = "\"" + cmd[index] + "\"";
493 } 490 }
494 AddToHistory(String.Join(" ", cmd)); 491 AddToHistory(String.Join(" ", cmd));
495 return String.Empty; 492 return String.Empty;
@@ -497,7 +494,7 @@ namespace OpenSim.Framework.Console
497 } 494 }
498 495
499 // If we're not echoing to screen (e.g. a password) then we probably don't want it in history 496 // If we're not echoing to screen (e.g. a password) then we probably don't want it in history
500 if (echo && commandLine != "") 497 if (m_echo && commandLine != "")
501 AddToHistory(commandLine); 498 AddToHistory(commandLine);
502 499
503 return commandLine; 500 return commandLine;