mirror of
https://github.com/opensim/opensim.git
synced 2026-08-12 04:05:42 +08:00
Massive console refactor. Greatly simplify interface.
This commit is contained in:
@@ -35,13 +35,13 @@ using log4net;
|
||||
|
||||
namespace OpenSim.Framework.Console
|
||||
{
|
||||
public class ConsoleBase
|
||||
public class ConsoleBase : IConsole
|
||||
{
|
||||
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected string prompt = "# ";
|
||||
|
||||
public object ConsoleScene { get; set; }
|
||||
public IScene ConsoleScene { get; set; }
|
||||
|
||||
public string DefaultPrompt { get; set; }
|
||||
|
||||
@@ -58,78 +58,39 @@ namespace OpenSim.Framework.Console
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Output(string text, string level)
|
||||
public virtual void Output(string format, string level = null, params object[] components)
|
||||
{
|
||||
Output(text);
|
||||
System.Console.WriteLine(format, components);
|
||||
}
|
||||
|
||||
public virtual void Output(string text)
|
||||
{
|
||||
System.Console.WriteLine(text);
|
||||
}
|
||||
|
||||
public virtual void OutputFormat(string format, params object[] components)
|
||||
{
|
||||
Output(string.Format(format, components));
|
||||
}
|
||||
|
||||
public string CmdPrompt(string p)
|
||||
{
|
||||
return ReadLine(String.Format("{0}: ", p), false, true);
|
||||
}
|
||||
|
||||
public string CmdPrompt(string p, string def)
|
||||
{
|
||||
string ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, true);
|
||||
if (ret == String.Empty)
|
||||
ret = def;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public string CmdPrompt(string p, List<char> excludedCharacters)
|
||||
public virtual string Prompt(string p, string def = null, List<char> excludedCharacters = null, bool echo = true)
|
||||
{
|
||||
bool itisdone = false;
|
||||
string ret = String.Empty;
|
||||
while (!itisdone)
|
||||
{
|
||||
itisdone = true;
|
||||
ret = CmdPrompt(p);
|
||||
|
||||
foreach (char c in excludedCharacters)
|
||||
{
|
||||
if (ret.Contains(c.ToString()))
|
||||
{
|
||||
System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted.");
|
||||
itisdone = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (def != null)
|
||||
ret = ReadLine(String.Format("{0}: ", p), false, echo);
|
||||
else
|
||||
ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, echo);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public string CmdPrompt(string p, string def, List<char> excludedCharacters)
|
||||
{
|
||||
bool itisdone = false;
|
||||
string ret = String.Empty;
|
||||
while (!itisdone)
|
||||
{
|
||||
itisdone = true;
|
||||
ret = CmdPrompt(p, def);
|
||||
|
||||
if (ret == String.Empty)
|
||||
if (ret == String.Empty && def != null)
|
||||
{
|
||||
ret = def;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (char c in excludedCharacters)
|
||||
if (excludedCharacters != null)
|
||||
{
|
||||
if (ret.Contains(c.ToString()))
|
||||
foreach (char c in excludedCharacters)
|
||||
{
|
||||
System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted.");
|
||||
itisdone = false;
|
||||
if (ret.Contains(c.ToString()))
|
||||
{
|
||||
System.Console.WriteLine("The character \"" + c.ToString() + "\" is not permitted.");
|
||||
itisdone = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,14 +100,14 @@ namespace OpenSim.Framework.Console
|
||||
}
|
||||
|
||||
// Displays a command prompt and returns a default value, user may only enter 1 of 2 options
|
||||
public string CmdPrompt(string prompt, string defaultresponse, List<string> options)
|
||||
public virtual string Prompt(string prompt, string defaultresponse, List<string> options)
|
||||
{
|
||||
bool itisdone = false;
|
||||
string optstr = String.Empty;
|
||||
foreach (string s in options)
|
||||
optstr += " " + s;
|
||||
|
||||
string temp = CmdPrompt(prompt, defaultresponse);
|
||||
string temp = Prompt(prompt, defaultresponse);
|
||||
while (itisdone == false)
|
||||
{
|
||||
if (options.Contains(temp))
|
||||
@@ -156,19 +117,12 @@ namespace OpenSim.Framework.Console
|
||||
else
|
||||
{
|
||||
System.Console.WriteLine("Valid options are" + optstr);
|
||||
temp = CmdPrompt(prompt, defaultresponse);
|
||||
temp = Prompt(prompt, defaultresponse);
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
// Displays a prompt and waits for the user to enter a string, then returns that string
|
||||
// (Done with no echo and suitable for passwords)
|
||||
public string PasswdPrompt(string p)
|
||||
{
|
||||
return ReadLine(String.Format("{0}: ", p), false, false);
|
||||
}
|
||||
|
||||
public virtual string ReadLine(string p, bool isCommand, bool e)
|
||||
{
|
||||
System.Console.Write("{0}", p);
|
||||
|
||||
20
OpenSim/Framework/Console/ConsoleUtil.cs
Normal file → Executable file
20
OpenSim/Framework/Console/ConsoleUtil.cs
Normal file → Executable file
@@ -75,7 +75,7 @@ namespace OpenSim.Framework.Console
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
console.OutputFormat("File {0} already exists. Please move or remove it.", path);
|
||||
console.Output("File {0} already exists. Please move or remove it.", null, path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenSim.Framework.Console
|
||||
if (!UUID.TryParse(rawUuid, out uuid))
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a valid uuid", rawUuid);
|
||||
console.Output("ERROR: {0} is not a valid uuid", null, rawUuid);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace OpenSim.Framework.Console
|
||||
if (!uint.TryParse(rawLocalId, out localId))
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a valid local id", localId);
|
||||
console.Output("ERROR: {0} is not a valid local id", null, localId);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ namespace OpenSim.Framework.Console
|
||||
if (localId == 0)
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a valid local id - it must be greater than 0", localId);
|
||||
console.Output("ERROR: {0} is not a valid local id - it must be greater than 0", null, localId);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ namespace OpenSim.Framework.Console
|
||||
}
|
||||
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a valid UUID or local id", rawId);
|
||||
console.Output("ERROR: {0} is not a valid UUID or local id", null, rawId);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ namespace OpenSim.Framework.Console
|
||||
if (!bool.TryParse(rawConsoleString, out b))
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a true or false value", rawConsoleString);
|
||||
console.Output("ERROR: {0} is not a true or false value", null, rawConsoleString);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ namespace OpenSim.Framework.Console
|
||||
if (!int.TryParse(rawConsoleInt, out i))
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a valid integer", rawConsoleInt);
|
||||
console.Output("ERROR: {0} is not a valid integer", null, rawConsoleInt);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ namespace OpenSim.Framework.Console
|
||||
if (!float.TryParse(rawConsoleInput, out i))
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a valid float", rawConsoleInput);
|
||||
console.Output("ERROR: {0} is not a valid float", null, rawConsoleInput);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -227,7 +227,7 @@ namespace OpenSim.Framework.Console
|
||||
if (!double.TryParse(rawConsoleInput, out i))
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a valid double", rawConsoleInput);
|
||||
console.Output("ERROR: {0} is not a valid double", null, rawConsoleInput);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ namespace OpenSim.Framework.Console
|
||||
if (i < 0)
|
||||
{
|
||||
if (console != null)
|
||||
console.OutputFormat("ERROR: {0} is not a positive integer", rawConsoleInt);
|
||||
console.Output("ERROR: {0} is not a positive integer", null, rawConsoleInt);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
15
OpenSim/Framework/Console/LocalConsole.cs
Normal file → Executable file
15
OpenSim/Framework/Console/LocalConsole.cs
Normal file → Executable file
@@ -359,7 +359,7 @@ namespace OpenSim.Framework.Console
|
||||
{
|
||||
string outText = text;
|
||||
|
||||
if (level != LOGLEVEL_NONE)
|
||||
if (level != null)
|
||||
{
|
||||
MatchCollection matches = m_categoryRegex.Matches(text);
|
||||
|
||||
@@ -389,20 +389,15 @@ namespace OpenSim.Framework.Console
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
|
||||
public override void Output(string text)
|
||||
public override void Output(string format, string level = null, params object[] components)
|
||||
{
|
||||
Output(text, LOGLEVEL_NONE);
|
||||
}
|
||||
|
||||
public override void Output(string text, string level)
|
||||
{
|
||||
FireOnOutput(text);
|
||||
FireOnOutput(format);
|
||||
|
||||
lock (m_commandLine)
|
||||
{
|
||||
if (m_cursorYPosition == -1)
|
||||
{
|
||||
WriteLocalText(text, level);
|
||||
WriteLocalText(format, level);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -418,7 +413,7 @@ namespace OpenSim.Framework.Console
|
||||
m_cursorYPosition = SetCursorTop(m_cursorYPosition);
|
||||
SetCursorLeft(0);
|
||||
|
||||
WriteLocalText(text, level);
|
||||
WriteLocalText(format, level);
|
||||
|
||||
m_cursorYPosition = System.Console.CursorTop;
|
||||
|
||||
|
||||
14
OpenSim/Framework/Console/MockConsole.cs
Normal file → Executable file
14
OpenSim/Framework/Console/MockConsole.cs
Normal file → Executable file
@@ -56,21 +56,17 @@ namespace OpenSim.Framework.Console
|
||||
|
||||
public string ReadLine(string p, bool isCommand, bool e) { return ""; }
|
||||
|
||||
public object ConsoleScene {
|
||||
public IScene ConsoleScene {
|
||||
get { return null; }
|
||||
set {}
|
||||
}
|
||||
|
||||
public void Output(string text, string level) {}
|
||||
public void Output(string text) {}
|
||||
public void OutputFormat(string format, params object[] components) {}
|
||||
public void Output(string format, string level, params object[] components) {}
|
||||
|
||||
public string CmdPrompt(string p) { return ""; }
|
||||
public string CmdPrompt(string p, string def) { return ""; }
|
||||
public string CmdPrompt(string p, List<char> excludedCharacters) { return ""; }
|
||||
public string CmdPrompt(string p, string def, List<char> excludedCharacters) { return ""; }
|
||||
public string Prompt(string p) { return ""; }
|
||||
public string Prompt(string p, string def, List<char> excludedCharacters, bool echo) { return ""; }
|
||||
|
||||
public string CmdPrompt(string prompt, string defaultresponse, List<string> options) { return ""; }
|
||||
public string Prompt(string prompt, string defaultresponse, List<string> options) { return ""; }
|
||||
|
||||
public string PasswdPrompt(string p) { return ""; }
|
||||
}
|
||||
|
||||
16
OpenSim/Framework/Console/RemoteConsole.cs
Normal file → Executable file
16
OpenSim/Framework/Console/RemoteConsole.cs
Normal file → Executable file
@@ -188,13 +188,19 @@ namespace OpenSim.Framework.Console
|
||||
m_Server.AddHTTPHandler("/SessionCommand/", HandleHttpSessionCommand);
|
||||
}
|
||||
|
||||
public override void Output(string text, string level)
|
||||
public override void Output(string format, string level = null, params object[] components)
|
||||
{
|
||||
Output(text, level, false, false, false);
|
||||
if (components.Length == 0)
|
||||
Output(format, level, false, false, false);
|
||||
else
|
||||
Output(String.Format(format, components), level, false, false, false);
|
||||
}
|
||||
|
||||
protected void Output(string text, string level, bool isPrompt, bool isCommand, bool isInput)
|
||||
{
|
||||
if (level == null)
|
||||
level = String.Empty;
|
||||
|
||||
// Increment the line number. It was 0 and they start at 1
|
||||
// so we need to pre-increment.
|
||||
m_lineNumber++;
|
||||
@@ -228,12 +234,6 @@ namespace OpenSim.Framework.Console
|
||||
System.Console.WriteLine(text.Trim());
|
||||
}
|
||||
|
||||
public override void Output(string text)
|
||||
{
|
||||
// Output plain (non-logging style) text.
|
||||
Output(text, String.Empty, false, false, false);
|
||||
}
|
||||
|
||||
public override string ReadLine(string p, bool isCommand, bool e)
|
||||
{
|
||||
// Output the prompt an prepare to wait. This
|
||||
|
||||
Reference in New Issue
Block a user