From 0fd17c08ae642fac17b24dfad06c61cfe5739483 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 20 Aug 2019 23:28:59 +0100 Subject: Massive console refactor. Greatly simplify interface. --- OpenSim/Framework/Console/ConsoleBase.cs | 86 +++++++----------------------- OpenSim/Framework/Console/ConsoleUtil.cs | 20 +++---- OpenSim/Framework/Console/LocalConsole.cs | 15 ++---- OpenSim/Framework/Console/MockConsole.cs | 14 ++--- OpenSim/Framework/Console/RemoteConsole.cs | 16 +++--- 5 files changed, 48 insertions(+), 103 deletions(-) mode change 100644 => 100755 OpenSim/Framework/Console/ConsoleUtil.cs mode change 100644 => 100755 OpenSim/Framework/Console/LocalConsole.cs mode change 100644 => 100755 OpenSim/Framework/Console/MockConsole.cs mode change 100644 => 100755 OpenSim/Framework/Console/RemoteConsole.cs (limited to 'OpenSim/Framework/Console') 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; 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 excludedCharacters) + public virtual string Prompt(string p, string def = null, List 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; - } - } - } - - return ret; - } - - public string CmdPrompt(string p, string def, List excludedCharacters) - { - bool itisdone = false; - string ret = String.Empty; - while (!itisdone) - { - itisdone = true; - ret = CmdPrompt(p, def); + if (def != null) + ret = ReadLine(String.Format("{0}: ", p), false, echo); + else + ret = ReadLine(String.Format("{0} [{1}]: ", p, def), false, echo); - 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 options) + public virtual string Prompt(string prompt, string defaultresponse, List 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); diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs old mode 100644 new mode 100755 index bfa05a2..5342a29 --- a/OpenSim/Framework/Console/ConsoleUtil.cs +++ b/OpenSim/Framework/Console/ConsoleUtil.cs @@ -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; } diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs old mode 100644 new mode 100755 index ba32f50..55c5c7e --- a/OpenSim/Framework/Console/LocalConsole.cs +++ b/OpenSim/Framework/Console/LocalConsole.cs @@ -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; diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs old mode 100644 new mode 100755 index e1ff720..d68b066 --- a/OpenSim/Framework/Console/MockConsole.cs +++ b/OpenSim/Framework/Console/MockConsole.cs @@ -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 excludedCharacters) { return ""; } - public string CmdPrompt(string p, string def, List excludedCharacters) { return ""; } + public string Prompt(string p) { return ""; } + public string Prompt(string p, string def, List excludedCharacters, bool echo) { return ""; } - public string CmdPrompt(string prompt, string defaultresponse, List options) { return ""; } + public string Prompt(string prompt, string defaultresponse, List options) { return ""; } public string PasswdPrompt(string p) { return ""; } } diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs old mode 100644 new mode 100755 index b90b75f..16b4636 --- a/OpenSim/Framework/Console/RemoteConsole.cs +++ b/OpenSim/Framework/Console/RemoteConsole.cs @@ -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 -- cgit v1.1