Skip to content

Commit

Permalink
Merge pull request #47 from HalcyonGrid/disable-quick-edit
Browse files Browse the repository at this point in the history
Added ConsoleMode class and call to disable Quick Edit mode on consoles.
  • Loading branch information
kf6kjg committed Dec 23, 2018
2 parents 792485c + 0e05b8f commit 131d357
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
15 changes: 7 additions & 8 deletions OpenSim/Framework/Console/CommandConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@
using System;
using System.Xml;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using log4net;
using OpenSim.Framework;

namespace OpenSim.Framework.Console
{
Expand Down Expand Up @@ -717,6 +709,13 @@ public CommandConsole(string defaultPrompt) : base(defaultPrompt)
Commands.AddCommand(
"Help", false, "help", "help [<item>]",
"Display help on a particular command or on a list of commands in a category", Help);

// Windows consoles have a Quick Edit mode that halts the process on a mouse click while the user interacts.
// We need to disable that unless the user does an Edit->Mark to select some text.
if (Util.IsWindows)
{
ConsoleMode.DisableQuickEdit();
}
}

private void Help(string module, string[] cmd)
Expand Down
36 changes: 36 additions & 0 deletions OpenSim/Framework/Console/ConsoleMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Runtime.InteropServices;

namespace OpenSim.Framework.Console
{
public static class ConsoleMode
{
const uint ENABLE_QUICK_EDIT = 0x0040;
const uint ENABLE_EXTENDED_FLAGS = 0x0080;

[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int nStdHandle);

[DllImport("kernel32.dll")]
static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);

[DllImport("kernel32.dll")]
static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);

private const int STDIN_HANDLE = -10;
internal static bool DisableQuickEdit()
{
IntPtr consoleHandle = GetStdHandle(STDIN_HANDLE);

uint consoleMode;
// get current console mode
if (!GetConsoleMode(consoleHandle, out consoleMode))
return false;

// setting QUICK_EDIT mode either way requires EXTENDED
consoleMode |= ENABLE_EXTENDED_FLAGS;
consoleMode &= ~ENABLE_QUICK_EDIT;
return SetConsoleMode(consoleHandle, consoleMode);
}
}
}
1 change: 1 addition & 0 deletions OpenSim/Framework/Console/OpenSim.Framework.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ConsoleMode.cs" />
<Compile Include="CommandConsole.cs">
<SubType>Code</SubType>
</Compile>
Expand Down

0 comments on commit 131d357

Please sign in to comment.