aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/ConsoleBase.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Framework/Console/ConsoleBase.cs180
1 files changed, 180 insertions, 0 deletions
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
new file mode 100755
index 0000000..2d8e723
--- /dev/null
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -0,0 +1,180 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Diagnostics;
31using System.Reflection;
32using System.Text;
33using System.Threading;
34using log4net;
35
36namespace OpenSim.Framework.Console
37{
38 public class ConsoleBase
39 {
40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41
42 protected string prompt = "# ";
43
44 public object ConsoleScene { get; set; }
45
46 public string DefaultPrompt { get; set; }
47
48 public ConsoleBase(string defaultPrompt)
49 {
50 DefaultPrompt = defaultPrompt;
51 }
52
53 public virtual void LockOutput()
54 {
55 }
56
57 public virtual void UnlockOutput()
58 {
59 }
60
61 public virtual void Output(string text, string level)
62 {
63 Output(text);
64 }
65
66 public virtual void Output(string text)
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 {
92 bool itisdone = false;
93 string ret = String.Empty;
94 while (!itisdone)
95 {
96 itisdone = true;
97 ret = CmdPrompt(p);
98
99 foreach (char c in excludedCharacters)
100 {
101 if (ret.Contains(c.ToString()))
102 {
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
121 if (ret == String.Empty)
122 {
123 ret = def;
124 }
125 else
126 {
127 foreach (char c in excludedCharacters)
128 {
129 if (ret.Contains(c.ToString()))
130 {
131 System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted.");
132 itisdone = false;
133 }
134 }
135 }
136 }
137
138 return ret;
139 }
140
141 // 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)
143 {
144 bool itisdone = false;
145 string optstr = String.Empty;
146 foreach (string s in options)
147 optstr += " " + s;
148
149 string temp = CmdPrompt(prompt, defaultresponse);
150 while (itisdone == false)
151 {
152 if (options.Contains(temp))
153 {
154 itisdone = true;
155 }
156 else
157 {
158 System.Console.WriteLine("Valid options are" + optstr);
159 temp = CmdPrompt(prompt, defaultresponse);
160 }
161 }
162 return temp;
163 }
164
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)
173 {
174 System.Console.Write("{0}", p);
175 string cmdinput = System.Console.ReadLine();
176
177 return cmdinput;
178 }
179 }
180}