test: try handle cntr-c another way

This commit is contained in:
UbitUmarov
2020-09-30 02:28:40 +01:00
parent 51c654fb70
commit 69e12f537f
6 changed files with 65 additions and 88 deletions

View File

@@ -720,9 +720,10 @@ namespace OpenSim.Framework.Console
/// </summary>
public class CommandConsole : ConsoleBase, ICommandConsole
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public event OnOutputDelegate OnOutput;
public static event OnCntrCCelegate OnCntrC;
public ICommands Commands { get; private set; }
@@ -794,5 +795,28 @@ namespace OpenSim.Framework.Console
public virtual void ReadConfig(IConfigSource configSource)
{
}
public virtual void SetCntrCHandler(OnCntrCCelegate handler)
{
if(OnCntrC == null)
{
OnCntrC += handler;
System.Console.CancelKeyPress += CancelKeyPressed;
}
}
protected static void CancelKeyPressed(object sender, ConsoleCancelEventArgs args)
{
if (OnCntrC != null && args.SpecialKey == ConsoleSpecialKey.ControlC)
{
OnCntrC?.Invoke();
args.Cancel = false;
}
}
protected static void LocalCancelKeyPressed()
{
OnCntrC?.Invoke();
}
}
}

View File

@@ -150,6 +150,8 @@ namespace OpenSim.Framework.Console
m_log.InfoFormat("[LOCAL CONSOLE]: Creating new empty command line history file {0}", m_historyPath);
File.Create(m_historyPath).Dispose();
}
System.Console.TreatControlCAsInput = true;
}
private void AddToHistory(string text)
@@ -413,7 +415,6 @@ namespace OpenSim.Framework.Console
else
components = null;
}
}
string text;
if (components == null || components.Length == 0)
@@ -492,6 +493,12 @@ namespace OpenSim.Framework.Console
Show();
ConsoleKeyInfo key = System.Console.ReadKey(true);
if((key.Modifiers & ConsoleModifiers.Control) != 0 && key.Key == ConsoleKey.C)
{
LocalCancelKeyPressed();
return string.Empty;
}
char enteredChar = key.KeyChar;
if (!Char.IsControl(enteredChar))

View File

@@ -75,6 +75,7 @@ namespace OpenSim.Framework.Console
public string PasswdPrompt(string p) { return ""; }
public void ReadConfig(IConfigSource configSource) { }
public void SetCntrCHandler(OnCntrCCelegate handler) { }
}
public class MockCommands : ICommands