Add persistent command history in console
Signed-off-by: BlueWall <jamesh@bluewallgroup.com>mb-throttle-test
parent
1e22091193
commit
bde60cc92e
|
@ -32,6 +32,8 @@ using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.IO;
|
||||||
|
using Nini.Config;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
|
||||||
namespace OpenSim.Framework.Console
|
namespace OpenSim.Framework.Console
|
||||||
|
@ -41,7 +43,9 @@ namespace OpenSim.Framework.Console
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LocalConsole : CommandConsole
|
public class LocalConsole : CommandConsole
|
||||||
{
|
{
|
||||||
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
private string m_historyPath;
|
||||||
|
private bool m_historyEnable;
|
||||||
|
|
||||||
// private readonly object m_syncRoot = new object();
|
// private readonly object m_syncRoot = new object();
|
||||||
private const string LOGLEVEL_NONE = "(none)";
|
private const string LOGLEVEL_NONE = "(none)";
|
||||||
|
@ -79,8 +83,54 @@ namespace OpenSim.Framework.Console
|
||||||
return Colors[(Math.Abs(input.ToUpper().GetHashCode()) % Colors.Length)];
|
return Colors[(Math.Abs(input.ToUpper().GetHashCode()) % Colors.Length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalConsole(string defaultPrompt) : base(defaultPrompt)
|
public LocalConsole(string defaultPrompt, IConfig startupConfig = null) : base(defaultPrompt)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (startupConfig == null) return;
|
||||||
|
|
||||||
|
m_historyEnable = startupConfig.GetBoolean("ConsoleHistoryFileEnabled", false);
|
||||||
|
if (!m_historyEnable)
|
||||||
|
{
|
||||||
|
m_log.Info("[LOCAL CONSOLE]: Persistent command line history from file is Disabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string m_historyFile = startupConfig.GetString("ConsoleHistoryFile", "OpenSimConsoleHistory.txt");
|
||||||
|
int m_historySize = startupConfig.GetInt("ConsoleHistoryFileLines", 100);
|
||||||
|
m_historyPath = Path.GetFullPath(Path.Combine(Util.configDir(), m_historyFile));
|
||||||
|
m_log.InfoFormat("[LOCAL CONSOLE]: Persistent command line history is Enabled, up to {0} lines from file {1}", m_historySize, m_historyPath);
|
||||||
|
|
||||||
|
if (File.Exists(m_historyPath))
|
||||||
|
{
|
||||||
|
using (StreamReader history_file = new StreamReader(m_historyPath))
|
||||||
|
{
|
||||||
|
string line;
|
||||||
|
while ((line = history_file.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
m_history.Add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_history.Count > m_historySize)
|
||||||
|
{
|
||||||
|
while (m_history.Count > m_historySize)
|
||||||
|
m_history.RemoveAt(0);
|
||||||
|
|
||||||
|
using (StreamWriter history_file = new StreamWriter(m_historyPath))
|
||||||
|
{
|
||||||
|
foreach (string line in m_history)
|
||||||
|
{
|
||||||
|
history_file.WriteLine(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_log.InfoFormat("[LOCAL CONSOLE]: Read {0} lines of command line history from file {1}", m_history.Count, m_historyPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.InfoFormat("[LOCAL CONSOLE]: Creating new empty command line history file {0}", m_historyPath);
|
||||||
|
File.Create(m_historyPath).Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddToHistory(string text)
|
private void AddToHistory(string text)
|
||||||
|
@ -89,6 +139,10 @@ namespace OpenSim.Framework.Console
|
||||||
m_history.RemoveAt(0);
|
m_history.RemoveAt(0);
|
||||||
|
|
||||||
m_history.Add(text);
|
m_history.Add(text);
|
||||||
|
if (m_historyEnable)
|
||||||
|
{
|
||||||
|
File.AppendAllText(m_historyPath, text + Environment.NewLine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -155,7 +155,7 @@ namespace OpenSim
|
||||||
((RemoteConsole)m_console).ReadConfig(Config);
|
((RemoteConsole)m_console).ReadConfig(Config);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_console = new LocalConsole("Region");
|
m_console = new LocalConsole("Region", Config.Configs["Startup"]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ namespace OpenSim.Server.Base
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MainConsole.Instance = new LocalConsole(prompt);
|
MainConsole.Instance = new LocalConsole(prompt, startupConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_console = MainConsole.Instance;
|
m_console = MainConsole.Instance;
|
||||||
|
|
|
@ -51,6 +51,19 @@
|
||||||
;; \\ - substitute \
|
;; \\ - substitute \
|
||||||
; ConsolePrompt = "Region (\R) "
|
; ConsolePrompt = "Region (\R) "
|
||||||
|
|
||||||
|
;# {ConsoleHistoryFileEnabled} {} {Save console commands to a history file?} {true false} true
|
||||||
|
;; Console commands can be saved to a file, so the command history persists after a restart. (default is false)
|
||||||
|
; ConsoleHistoryFileEnabled = true
|
||||||
|
|
||||||
|
;# {ConsoleHistoryFile} {} {Filename in which to save history} {} OpenSimConsoleHistory.txt
|
||||||
|
;; The history file can be just a filename (relative to OpenSim's bin/ directory
|
||||||
|
;; or it can be a full path to somewhere else. (default is OpenSimConsoleHistory.txt in bin/)
|
||||||
|
; ConsoleHistoryFile = "OpenSimConsoleHistory.txt"
|
||||||
|
|
||||||
|
;# {ConsoleHistoryFileLines} {} {How many lines of history to save?} {} 100
|
||||||
|
;; How many lines of command history should we keep? (default is 100)
|
||||||
|
; ConsoleHistoryFileLines = 100
|
||||||
|
|
||||||
;# {save_crashes} {} {Save crashes to disk?} {true false} false
|
;# {save_crashes} {} {Save crashes to disk?} {true false} false
|
||||||
;; Set this to true if you want to log crashes to disk
|
;; Set this to true if you want to log crashes to disk
|
||||||
;; this can be useful when submitting bug reports.
|
;; this can be useful when submitting bug reports.
|
||||||
|
|
|
@ -9,6 +9,16 @@
|
||||||
; \\ - substtitue \
|
; \\ - substtitue \
|
||||||
ConsolePrompt = "Region (\R) "
|
ConsolePrompt = "Region (\R) "
|
||||||
|
|
||||||
|
; Console commands can be saved to a file, so the command history persists after a restart. (default is true)
|
||||||
|
ConsoleHistoryFileEnabled = true
|
||||||
|
|
||||||
|
; The history file can be just a filename (relative to OpenSim's bin/ directory
|
||||||
|
; or it can be a full path to somewhere else. (default is OpenSimConsoleHistory.txt in bin/)
|
||||||
|
ConsoleHistoryFile = "OpenSimConsoleHistory.txt"
|
||||||
|
|
||||||
|
; How many lines of command history should we keep? (default is 100)
|
||||||
|
ConsoleHistoryFileLines = 100
|
||||||
|
|
||||||
; Set this to true if you want to log crashes to disk
|
; Set this to true if you want to log crashes to disk
|
||||||
; this can be useful when submitting bug reports.
|
; this can be useful when submitting bug reports.
|
||||||
; However, this will only log crashes within OpenSimulator that cause the entire program to exit
|
; However, this will only log crashes within OpenSimulator that cause the entire program to exit
|
||||||
|
|
|
@ -37,6 +37,16 @@
|
||||||
; The Robust.exe process must have R/W access to the location
|
; The Robust.exe process must have R/W access to the location
|
||||||
ConfigDirectory = "."
|
ConfigDirectory = "."
|
||||||
|
|
||||||
|
; Console commands can be saved to a file, so the command history persists after a restart. (default is true)
|
||||||
|
ConsoleHistoryFileEnabled = true
|
||||||
|
|
||||||
|
; The history file can be just a filename (relative to OpenSim's bin/ directory
|
||||||
|
; or it can be a full path to somewhere else. (default is OpenSimConsoleHistory.txt in bin/)
|
||||||
|
ConsoleHistoryFile = "RobustConsoleHistory.txt"
|
||||||
|
|
||||||
|
; How many lines of command history should we keep? (default is 100)
|
||||||
|
ConsoleHistoryFileLines = 100
|
||||||
|
|
||||||
[ServiceList]
|
[ServiceList]
|
||||||
|
|
||||||
AssetServiceConnector = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector"
|
AssetServiceConnector = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector"
|
||||||
|
|
|
@ -28,7 +28,17 @@
|
||||||
; Set path to directory for modular ini files...
|
; Set path to directory for modular ini files...
|
||||||
; The Robust.exe process must have R/W access to the location
|
; The Robust.exe process must have R/W access to the location
|
||||||
ConfigDirectory = "."
|
ConfigDirectory = "."
|
||||||
|
|
||||||
|
; Console commands can be saved to a file, so the command history persists after a restart. (default is true)
|
||||||
|
ConsoleHistoryFileEnabled = true
|
||||||
|
|
||||||
|
; The history file can be just a filename (relative to OpenSim's bin/ directory
|
||||||
|
; or it can be a full path to somewhere else. (default is OpenSimConsoleHistory.txt in bin/)
|
||||||
|
ConsoleHistoryFile = "RobustConsoleHistory.txt"
|
||||||
|
|
||||||
|
; How many lines of command history should we keep? (default is 100)
|
||||||
|
ConsoleHistoryFileLines = 100
|
||||||
|
|
||||||
[ServiceList]
|
[ServiceList]
|
||||||
AssetServiceConnector = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector"
|
AssetServiceConnector = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector"
|
||||||
InventoryInConnector = "8003/OpenSim.Server.Handlers.dll:XInventoryInConnector"
|
InventoryInConnector = "8003/OpenSim.Server.Handlers.dll:XInventoryInConnector"
|
||||||
|
|
Loading…
Reference in New Issue