aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/ConsoleBase.cs
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/ConsoleBase.cs
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 'OpenSim/Framework/Console/ConsoleBase.cs')
-rwxr-xr-xOpenSim/Framework/Console/ConsoleBase.cs86
1 files changed, 20 insertions, 66 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);