aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console
diff options
context:
space:
mode:
authorMelanie2019-08-20 23:28:59 +0100
committerMelanie2019-08-20 23:28:59 +0100
commit0fd17c08ae642fac17b24dfad06c61cfe5739483 (patch)
tree4871c96eab2f5b118cb09d670a3a4ba024cf1210 /OpenSim/Framework/Console
parentchange PGSQL migration (diff)
downloadopensim-SC-0fd17c08ae642fac17b24dfad06c61cfe5739483.zip
opensim-SC-0fd17c08ae642fac17b24dfad06c61cfe5739483.tar.gz
opensim-SC-0fd17c08ae642fac17b24dfad06c61cfe5739483.tar.bz2
opensim-SC-0fd17c08ae642fac17b24dfad06c61cfe5739483.tar.xz
Massive console refactor. Greatly simplify interface.
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Framework/Console/ConsoleBase.cs86
-rwxr-xr-x[-rw-r--r--]OpenSim/Framework/Console/ConsoleUtil.cs20
-rwxr-xr-x[-rw-r--r--]OpenSim/Framework/Console/LocalConsole.cs15
-rwxr-xr-x[-rw-r--r--]OpenSim/Framework/Console/MockConsole.cs14
-rwxr-xr-x[-rw-r--r--]OpenSim/Framework/Console/RemoteConsole.cs16
5 files changed, 48 insertions, 103 deletions
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 64cddea..56bda05 100755
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -35,13 +35,13 @@ using log4net;
35 35
36namespace OpenSim.Framework.Console 36namespace OpenSim.Framework.Console
37{ 37{
38 public class ConsoleBase 38 public class ConsoleBase : IConsole
39 { 39 {
40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 41
42 protected string prompt = "# "; 42 protected string prompt = "# ";
43 43
44 public object ConsoleScene { get; set; } 44 public IScene ConsoleScene { get; set; }
45 45
46 public string DefaultPrompt { get; set; } 46 public string DefaultPrompt { get; set; }
47 47
@@ -58,78 +58,39 @@ namespace OpenSim.Framework.Console
58 { 58 {
59 } 59 }
60 60
61 public virtual void Output(string text, string level) 61 public virtual void Output(string format, string level = null, params object[] components)
62 { 62 {
63 Output(text); 63 System.Console.WriteLine(format, components);
64 } 64 }
65 65
66 public virtual void Output(string text) 66 public virtual string Prompt(string p, string def = null, List<char> excludedCharacters = null, bool echo = true)
67 {
68 System.Console.WriteLine(text);
69 }
70
71 public virtual void OutputFormat(string format, params object[] components)
72 {
73 Output(string.Format(format, components));
74 }
75
76 public string CmdPrompt(string p)
77 {
78 return ReadLine(String.Format("{0}: ", p), false, true);
79 }
80
81 public string CmdPrompt(string p, string def)
82 {
83 string ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, true);
84 if (ret == String.Empty)
85 ret = def;
86
87 return ret;
88 }
89
90 public string CmdPrompt(string p, List<char> excludedCharacters)
91 { 67 {
92 bool itisdone = false; 68 bool itisdone = false;
93 string ret = String.Empty; 69 string ret = String.Empty;
94 while (!itisdone) 70 while (!itisdone)
95 { 71 {
96 itisdone = true; 72 itisdone = true;
97 ret = CmdPrompt(p);
98 73
99 foreach (char c in excludedCharacters) 74 if (def != null)
100 { 75 ret = ReadLine(String.Format("{0}: ", p), false, echo);
101 if (ret.Contains(c.ToString())) 76 else
102 { 77 ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, echo);
103 System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted.");
104 itisdone = false;
105 }
106 }
107 }
108
109 return ret;
110 }
111
112 public string CmdPrompt(string p, string def, List<char> excludedCharacters)
113 {
114 bool itisdone = false;
115 string ret = String.Empty;
116 while (!itisdone)
117 {
118 itisdone = true;
119 ret = CmdPrompt(p, def);
120 78
121 if (ret == String.Empty) 79 if (ret == String.Empty && def != null)
122 { 80 {
123 ret = def; 81 ret = def;
124 } 82 }
125 else 83 else
126 { 84 {
127 foreach (char c in excludedCharacters) 85 if (excludedCharacters != null)
128 { 86 {
129 if (ret.Contains(c.ToString())) 87 foreach (char c in excludedCharacters)
130 { 88 {
131 System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted."); 89 if (ret.Contains(c.ToString()))
132 itisdone = false; 90 {
91 System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted.");
92 itisdone = false;
93 }
133 } 94 }
134 } 95 }
135 } 96 }
@@ -139,14 +100,14 @@ namespace OpenSim.Framework.Console
139 } 100 }
140 101
141 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options 102 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
142 public string CmdPrompt(string prompt, string defaultresponse, List<string> options) 103 public virtual string Prompt(string prompt, string defaultresponse, List<string> options)
143 { 104 {
144 bool itisdone = false; 105 bool itisdone = false;
145 string optstr = String.Empty; 106 string optstr = String.Empty;
146 foreach (string s in options) 107 foreach (string s in options)
147 optstr += " " + s; 108 optstr += " " + s;
148 109
149 string temp = CmdPrompt(prompt, defaultresponse); 110 string temp = Prompt(prompt, defaultresponse);
150 while (itisdone == false) 111 while (itisdone == false)
151 { 112 {
152 if (options.Contains(temp)) 113 if (options.Contains(temp))
@@ -156,19 +117,12 @@ namespace OpenSim.Framework.Console
156 else 117 else
157 { 118 {
158 System.Console.WriteLine("Valid options are" + optstr); 119 System.Console.WriteLine("Valid options are" + optstr);
159 temp = CmdPrompt(prompt, defaultresponse); 120 temp = Prompt(prompt, defaultresponse);
160 } 121 }
161 } 122 }
162 return temp; 123 return temp;
163 } 124 }
164 125
165 // Displays a prompt and waits for the user to enter a string, then returns that string
166 // (Done with no echo and suitable for passwords)
167 public string PasswdPrompt(string p)
168 {
169 return ReadLine(String.Format("{0}: ", p), false, false);
170 }
171
172 public virtual string ReadLine(string p, bool isCommand, bool e) 126 public virtual string ReadLine(string p, bool isCommand, bool e)
173 { 127 {
174 System.Console.Write("{0}", p); 128 System.Console.Write("{0}", p);
diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs
index bfa05a2..5342a29 100644..100755
--- a/OpenSim/Framework/Console/ConsoleUtil.cs
+++ b/OpenSim/Framework/Console/ConsoleUtil.cs
@@ -75,7 +75,7 @@ namespace OpenSim.Framework.Console
75 { 75 {
76 if (File.Exists(path)) 76 if (File.Exists(path))
77 { 77 {
78 console.OutputFormat("File {0} already exists. Please move or remove it.", path); 78 console.Output("File {0} already exists. Please move or remove it.", null, path);
79 return false; 79 return false;
80 } 80 }
81 81
@@ -97,7 +97,7 @@ namespace OpenSim.Framework.Console
97 if (!UUID.TryParse(rawUuid, out uuid)) 97 if (!UUID.TryParse(rawUuid, out uuid))
98 { 98 {
99 if (console != null) 99 if (console != null)
100 console.OutputFormat("ERROR: {0} is not a valid uuid", rawUuid); 100 console.Output("ERROR: {0} is not a valid uuid", null, rawUuid);
101 101
102 return false; 102 return false;
103 } 103 }
@@ -110,7 +110,7 @@ namespace OpenSim.Framework.Console
110 if (!uint.TryParse(rawLocalId, out localId)) 110 if (!uint.TryParse(rawLocalId, out localId))
111 { 111 {
112 if (console != null) 112 if (console != null)
113 console.OutputFormat("ERROR: {0} is not a valid local id", localId); 113 console.Output("ERROR: {0} is not a valid local id", null, localId);
114 114
115 return false; 115 return false;
116 } 116 }
@@ -118,7 +118,7 @@ namespace OpenSim.Framework.Console
118 if (localId == 0) 118 if (localId == 0)
119 { 119 {
120 if (console != null) 120 if (console != null)
121 console.OutputFormat("ERROR: {0} is not a valid local id - it must be greater than 0", localId); 121 console.Output("ERROR: {0} is not a valid local id - it must be greater than 0", null, localId);
122 122
123 return false; 123 return false;
124 } 124 }
@@ -150,7 +150,7 @@ namespace OpenSim.Framework.Console
150 } 150 }
151 151
152 if (console != null) 152 if (console != null)
153 console.OutputFormat("ERROR: {0} is not a valid UUID or local id", rawId); 153 console.Output("ERROR: {0} is not a valid UUID or local id", null, rawId);
154 154
155 return false; 155 return false;
156 } 156 }
@@ -167,7 +167,7 @@ namespace OpenSim.Framework.Console
167 if (!bool.TryParse(rawConsoleString, out b)) 167 if (!bool.TryParse(rawConsoleString, out b))
168 { 168 {
169 if (console != null) 169 if (console != null)
170 console.OutputFormat("ERROR: {0} is not a true or false value", rawConsoleString); 170 console.Output("ERROR: {0} is not a true or false value", null, rawConsoleString);
171 171
172 return false; 172 return false;
173 } 173 }
@@ -187,7 +187,7 @@ namespace OpenSim.Framework.Console
187 if (!int.TryParse(rawConsoleInt, out i)) 187 if (!int.TryParse(rawConsoleInt, out i))
188 { 188 {
189 if (console != null) 189 if (console != null)
190 console.OutputFormat("ERROR: {0} is not a valid integer", rawConsoleInt); 190 console.Output("ERROR: {0} is not a valid integer", null, rawConsoleInt);
191 191
192 return false; 192 return false;
193 } 193 }
@@ -207,7 +207,7 @@ namespace OpenSim.Framework.Console
207 if (!float.TryParse(rawConsoleInput, out i)) 207 if (!float.TryParse(rawConsoleInput, out i))
208 { 208 {
209 if (console != null) 209 if (console != null)
210 console.OutputFormat("ERROR: {0} is not a valid float", rawConsoleInput); 210 console.Output("ERROR: {0} is not a valid float", null, rawConsoleInput);
211 211
212 return false; 212 return false;
213 } 213 }
@@ -227,7 +227,7 @@ namespace OpenSim.Framework.Console
227 if (!double.TryParse(rawConsoleInput, out i)) 227 if (!double.TryParse(rawConsoleInput, out i))
228 { 228 {
229 if (console != null) 229 if (console != null)
230 console.OutputFormat("ERROR: {0} is not a valid double", rawConsoleInput); 230 console.Output("ERROR: {0} is not a valid double", null, rawConsoleInput);
231 231
232 return false; 232 return false;
233 } 233 }
@@ -249,7 +249,7 @@ namespace OpenSim.Framework.Console
249 if (i < 0) 249 if (i < 0)
250 { 250 {
251 if (console != null) 251 if (console != null)
252 console.OutputFormat("ERROR: {0} is not a positive integer", rawConsoleInt); 252 console.Output("ERROR: {0} is not a positive integer", null, rawConsoleInt);
253 253
254 return false; 254 return false;
255 } 255 }
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs
index ba32f50..55c5c7e 100644..100755
--- a/OpenSim/Framework/Console/LocalConsole.cs
+++ b/OpenSim/Framework/Console/LocalConsole.cs
@@ -359,7 +359,7 @@ namespace OpenSim.Framework.Console
359 { 359 {
360 string outText = text; 360 string outText = text;
361 361
362 if (level != LOGLEVEL_NONE) 362 if (level != null)
363 { 363 {
364 MatchCollection matches = m_categoryRegex.Matches(text); 364 MatchCollection matches = m_categoryRegex.Matches(text);
365 365
@@ -389,20 +389,15 @@ namespace OpenSim.Framework.Console
389 System.Console.WriteLine(); 389 System.Console.WriteLine();
390 } 390 }
391 391
392 public override void Output(string text) 392 public override void Output(string format, string level = null, params object[] components)
393 { 393 {
394 Output(text, LOGLEVEL_NONE); 394 FireOnOutput(format);
395 }
396
397 public override void Output(string text, string level)
398 {
399 FireOnOutput(text);
400 395
401 lock (m_commandLine) 396 lock (m_commandLine)
402 { 397 {
403 if (m_cursorYPosition == -1) 398 if (m_cursorYPosition == -1)
404 { 399 {
405 WriteLocalText(text, level); 400 WriteLocalText(format, level);
406 401
407 return; 402 return;
408 } 403 }
@@ -418,7 +413,7 @@ namespace OpenSim.Framework.Console
418 m_cursorYPosition = SetCursorTop(m_cursorYPosition); 413 m_cursorYPosition = SetCursorTop(m_cursorYPosition);
419 SetCursorLeft(0); 414 SetCursorLeft(0);
420 415
421 WriteLocalText(text, level); 416 WriteLocalText(format, level);
422 417
423 m_cursorYPosition = System.Console.CursorTop; 418 m_cursorYPosition = System.Console.CursorTop;
424 419
diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs
index e1ff720..d68b066 100644..100755
--- a/OpenSim/Framework/Console/MockConsole.cs
+++ b/OpenSim/Framework/Console/MockConsole.cs
@@ -56,21 +56,17 @@ namespace OpenSim.Framework.Console
56 56
57 public string ReadLine(string p, bool isCommand, bool e) { return ""; } 57 public string ReadLine(string p, bool isCommand, bool e) { return ""; }
58 58
59 public object ConsoleScene { 59 public IScene ConsoleScene {
60 get { return null; } 60 get { return null; }
61 set {} 61 set {}
62 } 62 }
63 63
64 public void Output(string text, string level) {} 64 public void Output(string format, string level, params object[] components) {}
65 public void Output(string text) {}
66 public void OutputFormat(string format, params object[] components) {}
67 65
68 public string CmdPrompt(string p) { return ""; } 66 public string Prompt(string p) { return ""; }
69 public string CmdPrompt(string p, string def) { return ""; } 67 public string Prompt(string p, string def, List<char> excludedCharacters, bool echo) { return ""; }
70 public string CmdPrompt(string p, List<char> excludedCharacters) { return ""; }
71 public string CmdPrompt(string p, string def, List<char> excludedCharacters) { return ""; }
72 68
73 public string CmdPrompt(string prompt, string defaultresponse, List<string> options) { return ""; } 69 public string Prompt(string prompt, string defaultresponse, List<string> options) { return ""; }
74 70
75 public string PasswdPrompt(string p) { return ""; } 71 public string PasswdPrompt(string p) { return ""; }
76 } 72 }
diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs
index b90b75f..16b4636 100644..100755
--- a/OpenSim/Framework/Console/RemoteConsole.cs
+++ b/OpenSim/Framework/Console/RemoteConsole.cs
@@ -188,13 +188,19 @@ namespace OpenSim.Framework.Console
188 m_Server.AddHTTPHandler("/SessionCommand/", HandleHttpSessionCommand); 188 m_Server.AddHTTPHandler("/SessionCommand/", HandleHttpSessionCommand);
189 } 189 }
190 190
191 public override void Output(string text, string level) 191 public override void Output(string format, string level = null, params object[] components)
192 { 192 {
193 Output(text, level, false, false, false); 193 if (components.Length == 0)
194 Output(format, level, false, false, false);
195 else
196 Output(String.Format(format, components), level, false, false, false);
194 } 197 }
195 198
196 protected void Output(string text, string level, bool isPrompt, bool isCommand, bool isInput) 199 protected void Output(string text, string level, bool isPrompt, bool isCommand, bool isInput)
197 { 200 {
201 if (level == null)
202 level = String.Empty;
203
198 // Increment the line number. It was 0 and they start at 1 204 // Increment the line number. It was 0 and they start at 1
199 // so we need to pre-increment. 205 // so we need to pre-increment.
200 m_lineNumber++; 206 m_lineNumber++;
@@ -228,12 +234,6 @@ namespace OpenSim.Framework.Console
228 System.Console.WriteLine(text.Trim()); 234 System.Console.WriteLine(text.Trim());
229 } 235 }
230 236
231 public override void Output(string text)
232 {
233 // Output plain (non-logging style) text.
234 Output(text, String.Empty, false, false, false);
235 }
236
237 public override string ReadLine(string p, bool isCommand, bool e) 237 public override string ReadLine(string p, bool isCommand, bool e)
238 { 238 {
239 // Output the prompt an prepare to wait. This 239 // Output the prompt an prepare to wait. This