aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/LocalConsole.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Framework/Console/LocalConsole.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Framework/Console/LocalConsole.cs')
-rw-r--r--OpenSim/Framework/Console/LocalConsole.cs85
1 files changed, 78 insertions, 7 deletions
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs
index d41481f..28293c0 100644
--- a/OpenSim/Framework/Console/LocalConsole.cs
+++ b/OpenSim/Framework/Console/LocalConsole.cs
@@ -32,6 +32,8 @@ using System.Reflection;
32using System.Text; 32using System.Text;
33using System.Text.RegularExpressions; 33using System.Text.RegularExpressions;
34using System.Threading; 34using System.Threading;
35using System.IO;
36using Nini.Config;
35using log4net; 37using log4net;
36 38
37namespace OpenSim.Framework.Console 39namespace OpenSim.Framework.Console
@@ -41,11 +43,18 @@ namespace OpenSim.Framework.Console
41 /// </summary> 43 /// </summary>
42 public class LocalConsole : CommandConsole 44 public class LocalConsole : CommandConsole
43 { 45 {
44// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private string m_historyPath;
48 private bool m_historyEnable;
45 49
46 // private readonly object m_syncRoot = new object(); 50 // private readonly object m_syncRoot = new object();
47 private const string LOGLEVEL_NONE = "(none)"; 51 private const string LOGLEVEL_NONE = "(none)";
48 52
53 // Used to extract categories for colourization.
54 private Regex m_categoryRegex
55 = new Regex(
56 @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)", RegexOptions.Singleline | RegexOptions.Compiled);
57
49 private int m_cursorYPosition = -1; 58 private int m_cursorYPosition = -1;
50 private int m_cursorXPosition = 0; 59 private int m_cursorXPosition = 0;
51 private StringBuilder m_commandLine = new StringBuilder(); 60 private StringBuilder m_commandLine = new StringBuilder();
@@ -74,8 +83,54 @@ namespace OpenSim.Framework.Console
74 return Colors[(Math.Abs(input.ToUpper().GetHashCode()) % Colors.Length)]; 83 return Colors[(Math.Abs(input.ToUpper().GetHashCode()) % Colors.Length)];
75 } 84 }
76 85
77 public LocalConsole(string defaultPrompt) : base(defaultPrompt) 86 public LocalConsole(string defaultPrompt, IConfig startupConfig = null) : base(defaultPrompt)
78 { 87 {
88
89 if (startupConfig == null) return;
90
91 m_historyEnable = startupConfig.GetBoolean("ConsoleHistoryFileEnabled", false);
92 if (!m_historyEnable)
93 {
94 m_log.Info("[LOCAL CONSOLE]: Persistent command line history from file is Disabled");
95 return;
96 }
97
98 string m_historyFile = startupConfig.GetString("ConsoleHistoryFile", "OpenSimConsoleHistory.txt");
99 int m_historySize = startupConfig.GetInt("ConsoleHistoryFileLines", 100);
100 m_historyPath = Path.GetFullPath(Path.Combine(Util.configDir(), m_historyFile));
101 m_log.InfoFormat("[LOCAL CONSOLE]: Persistent command line history is Enabled, up to {0} lines from file {1}", m_historySize, m_historyPath);
102
103 if (File.Exists(m_historyPath))
104 {
105 using (StreamReader history_file = new StreamReader(m_historyPath))
106 {
107 string line;
108 while ((line = history_file.ReadLine()) != null)
109 {
110 m_history.Add(line);
111 }
112 }
113
114 if (m_history.Count > m_historySize)
115 {
116 while (m_history.Count > m_historySize)
117 m_history.RemoveAt(0);
118
119 using (StreamWriter history_file = new StreamWriter(m_historyPath))
120 {
121 foreach (string line in m_history)
122 {
123 history_file.WriteLine(line);
124 }
125 }
126 }
127 m_log.InfoFormat("[LOCAL CONSOLE]: Read {0} lines of command line history from file {1}", m_history.Count, m_historyPath);
128 }
129 else
130 {
131 m_log.InfoFormat("[LOCAL CONSOLE]: Creating new empty command line history file {0}", m_historyPath);
132 File.Create(m_historyPath).Dispose();
133 }
79 } 134 }
80 135
81 private void AddToHistory(string text) 136 private void AddToHistory(string text)
@@ -84,6 +139,10 @@ namespace OpenSim.Framework.Console
84 m_history.RemoveAt(0); 139 m_history.RemoveAt(0);
85 140
86 m_history.Add(text); 141 m_history.Add(text);
142 if (m_historyEnable)
143 {
144 File.AppendAllText(m_historyPath, text + Environment.NewLine);
145 }
87 } 146 }
88 147
89 /// <summary> 148 /// <summary>
@@ -280,11 +339,8 @@ namespace OpenSim.Framework.Console
280 string outText = text; 339 string outText = text;
281 340
282 if (level != LOGLEVEL_NONE) 341 if (level != LOGLEVEL_NONE)
283 { 342 {
284 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)"; 343 MatchCollection matches = m_categoryRegex.Matches(text);
285
286 Regex RE = new Regex(regex, RegexOptions.Multiline);
287 MatchCollection matches = RE.Matches(text);
288 344
289 if (matches.Count == 1) 345 if (matches.Count == 1)
290 { 346 {
@@ -426,6 +482,21 @@ namespace OpenSim.Framework.Console
426 System.Console.Write("{0}", prompt); 482 System.Console.Write("{0}", prompt);
427 483
428 break; 484 break;
485 case ConsoleKey.Delete:
486 if (m_cursorXPosition == m_commandLine.Length)
487 break;
488
489 m_commandLine.Remove(m_cursorXPosition, 1);
490
491 SetCursorLeft(0);
492 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
493
494 if (m_echo)
495 System.Console.Write("{0}{1} ", prompt, m_commandLine);
496 else
497 System.Console.Write("{0}", prompt);
498
499 break;
429 case ConsoleKey.End: 500 case ConsoleKey.End:
430 m_cursorXPosition = m_commandLine.Length; 501 m_cursorXPosition = m_commandLine.Length;
431 break; 502 break;