diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Console/ConsoleBase.cs | 108 |
1 files changed, 77 insertions, 31 deletions
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs index 64cddea..8748b25 100644 --- a/OpenSim/Framework/Console/ConsoleBase.cs +++ b/OpenSim/Framework/Console/ConsoleBase.cs | |||
@@ -35,13 +35,39 @@ using log4net; | |||
35 | 35 | ||
36 | namespace OpenSim.Framework.Console | 36 | namespace OpenSim.Framework.Console |
37 | { | 37 | { |
38 | public class ConsoleBase | 38 | public class ConsoleLevel |
39 | { | ||
40 | public string m_string; | ||
41 | |||
42 | ConsoleLevel(string v) | ||
43 | { | ||
44 | m_string = v; | ||
45 | } | ||
46 | |||
47 | static public implicit operator ConsoleLevel(string s) | ||
48 | { | ||
49 | return new ConsoleLevel(s); | ||
50 | } | ||
51 | |||
52 | public static string ToString(ConsoleLevel s) | ||
53 | { | ||
54 | return s.m_string; | ||
55 | } | ||
56 | |||
57 | public override string ToString() | ||
58 | { | ||
59 | return m_string; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | |||
64 | public class ConsoleBase : IConsole | ||
39 | { | 65 | { |
40 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 66 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | 67 | ||
42 | protected string prompt = "# "; | 68 | protected string prompt = "# "; |
43 | 69 | ||
44 | public object ConsoleScene { get; set; } | 70 | public IScene ConsoleScene { get; set; } |
45 | 71 | ||
46 | public string DefaultPrompt { get; set; } | 72 | public string DefaultPrompt { get; set; } |
47 | 73 | ||
@@ -58,27 +84,47 @@ namespace OpenSim.Framework.Console | |||
58 | { | 84 | { |
59 | } | 85 | } |
60 | 86 | ||
61 | public virtual void Output(string text, string level) | 87 | public void Output(string format) |
62 | { | 88 | { |
63 | Output(text); | 89 | System.Console.WriteLine(format); |
64 | } | 90 | } |
65 | 91 | ||
66 | public virtual void Output(string text) | 92 | public virtual void Output(string format, params object[] components) |
67 | { | 93 | { |
68 | System.Console.WriteLine(text); | 94 | string level = null; |
69 | } | 95 | if (components != null && components.Length > 0) |
96 | { | ||
97 | if (components[0] == null || components[0] is ConsoleLevel) | ||
98 | { | ||
99 | if (components[0] is ConsoleLevel) | ||
100 | level = ((ConsoleLevel)components[0]).ToString(); | ||
70 | 101 | ||
71 | public virtual void OutputFormat(string format, params object[] components) | 102 | if (components.Length > 1) |
72 | { | 103 | { |
73 | Output(string.Format(format, components)); | 104 | object[] tmp = new object[components.Length - 1]; |
105 | Array.Copy(components, 1, tmp, 0, components.Length - 1); | ||
106 | components = tmp; | ||
107 | } | ||
108 | else | ||
109 | components = null; | ||
110 | } | ||
111 | |||
112 | } | ||
113 | string text; | ||
114 | if (components == null || components.Length == 0) | ||
115 | text = format; | ||
116 | else | ||
117 | text = String.Format(format, components); | ||
118 | |||
119 | System.Console.WriteLine(text); | ||
74 | } | 120 | } |
75 | 121 | ||
76 | public string CmdPrompt(string p) | 122 | public string Prompt(string p) |
77 | { | 123 | { |
78 | return ReadLine(String.Format("{0}: ", p), false, true); | 124 | return ReadLine(String.Format("{0}: ", p), false, true); |
79 | } | 125 | } |
80 | 126 | ||
81 | public string CmdPrompt(string p, string def) | 127 | public string Prompt(string p, string def) |
82 | { | 128 | { |
83 | string ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, true); | 129 | string ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, true); |
84 | if (ret == String.Empty) | 130 | if (ret == String.Empty) |
@@ -87,14 +133,14 @@ namespace OpenSim.Framework.Console | |||
87 | return ret; | 133 | return ret; |
88 | } | 134 | } |
89 | 135 | ||
90 | public string CmdPrompt(string p, List<char> excludedCharacters) | 136 | public string Prompt(string p, List<char> excludedCharacters) |
91 | { | 137 | { |
92 | bool itisdone = false; | 138 | bool itisdone = false; |
93 | string ret = String.Empty; | 139 | string ret = String.Empty; |
94 | while (!itisdone) | 140 | while (!itisdone) |
95 | { | 141 | { |
96 | itisdone = true; | 142 | itisdone = true; |
97 | ret = CmdPrompt(p); | 143 | ret = Prompt(p); |
98 | 144 | ||
99 | foreach (char c in excludedCharacters) | 145 | foreach (char c in excludedCharacters) |
100 | { | 146 | { |
@@ -109,27 +155,34 @@ namespace OpenSim.Framework.Console | |||
109 | return ret; | 155 | return ret; |
110 | } | 156 | } |
111 | 157 | ||
112 | public string CmdPrompt(string p, string def, List<char> excludedCharacters) | 158 | public virtual string Prompt(string p, string def, List<char> excludedCharacters, bool echo = true) |
113 | { | 159 | { |
114 | bool itisdone = false; | 160 | bool itisdone = false; |
115 | string ret = String.Empty; | 161 | string ret = String.Empty; |
116 | while (!itisdone) | 162 | while (!itisdone) |
117 | { | 163 | { |
118 | itisdone = true; | 164 | itisdone = true; |
119 | ret = CmdPrompt(p, def); | ||
120 | 165 | ||
121 | if (ret == String.Empty) | 166 | if (def == null) |
167 | ret = ReadLine(String.Format("{0}: ", p), false, echo); | ||
168 | else | ||
169 | ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, echo); | ||
170 | |||
171 | if (ret == String.Empty && def != null) | ||
122 | { | 172 | { |
123 | ret = def; | 173 | ret = def; |
124 | } | 174 | } |
125 | else | 175 | else |
126 | { | 176 | { |
127 | foreach (char c in excludedCharacters) | 177 | if (excludedCharacters != null) |
128 | { | 178 | { |
129 | if (ret.Contains(c.ToString())) | 179 | foreach (char c in excludedCharacters) |
130 | { | 180 | { |
131 | System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted."); | 181 | if (ret.Contains(c.ToString())) |
132 | itisdone = false; | 182 | { |
183 | System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted."); | ||
184 | itisdone = false; | ||
185 | } | ||
133 | } | 186 | } |
134 | } | 187 | } |
135 | } | 188 | } |
@@ -139,14 +192,14 @@ namespace OpenSim.Framework.Console | |||
139 | } | 192 | } |
140 | 193 | ||
141 | // Displays a command prompt and returns a default value, user may only enter 1 of 2 options | 194 | // 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) | 195 | public virtual string Prompt(string prompt, string defaultresponse, List<string> options) |
143 | { | 196 | { |
144 | bool itisdone = false; | 197 | bool itisdone = false; |
145 | string optstr = String.Empty; | 198 | string optstr = String.Empty; |
146 | foreach (string s in options) | 199 | foreach (string s in options) |
147 | optstr += " " + s; | 200 | optstr += " " + s; |
148 | 201 | ||
149 | string temp = CmdPrompt(prompt, defaultresponse); | 202 | string temp = Prompt(prompt, defaultresponse); |
150 | while (itisdone == false) | 203 | while (itisdone == false) |
151 | { | 204 | { |
152 | if (options.Contains(temp)) | 205 | if (options.Contains(temp)) |
@@ -156,19 +209,12 @@ namespace OpenSim.Framework.Console | |||
156 | else | 209 | else |
157 | { | 210 | { |
158 | System.Console.WriteLine("Valid options are" + optstr); | 211 | System.Console.WriteLine("Valid options are" + optstr); |
159 | temp = CmdPrompt(prompt, defaultresponse); | 212 | temp = Prompt(prompt, defaultresponse); |
160 | } | 213 | } |
161 | } | 214 | } |
162 | return temp; | 215 | return temp; |
163 | } | 216 | } |
164 | 217 | ||
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) | 218 | public virtual string ReadLine(string p, bool isCommand, bool e) |
173 | { | 219 | { |
174 | System.Console.Write("{0}", p); | 220 | System.Console.Write("{0}", p); |