* First steps of ConPty support * Added resize functionality * fix cwd, args, hide console window * Handle shell process exited * Make ConPTY optional
57 lines
2.3 KiB
C#
57 lines
2.3 KiB
C#
using Microsoft.Win32.SafeHandles;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace FluentTerminal.SystemTray.Services.ConPty.Native
|
|
{
|
|
/// <summary>
|
|
/// PInvoke signatures for Win32's Console API.
|
|
/// </summary>
|
|
internal static class ConsoleApi
|
|
{
|
|
internal const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
|
|
internal const uint DISABLE_NEWLINE_AUTO_RETURN = 0x0008;
|
|
internal const uint GENERIC_WRITE = 0x40000000;
|
|
internal const uint GENERIC_READ = 0x80000000;
|
|
internal const uint FILE_SHARE_WRITE = 0x00000002;
|
|
internal const uint OPEN_EXISTING = 0x00000003;
|
|
internal const uint FILE_ATTRIBUTE_NORMAL = 0x80;
|
|
internal const string ConsoleOutPseudoFilename = "CONOUT$";
|
|
|
|
[DllImport("kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern bool AllocConsole();
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
internal static extern IntPtr GetConsoleWindow();
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
internal static extern bool SetConsoleMode(SafeFileHandle hConsoleHandle, uint mode);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
internal static extern bool GetConsoleMode(SafeFileHandle handle, out uint mode);
|
|
|
|
[DllImport("kernel32.dll", EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern IntPtr CreateFileW(
|
|
string lpFileName,
|
|
uint dwDesiredAccess,
|
|
uint dwShareMode,
|
|
IntPtr lpSecurityAttributes,
|
|
uint dwCreationDisposition,
|
|
uint dwFlagsAndAttributes,
|
|
IntPtr hTemplateFile);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
internal static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
|
|
internal delegate bool ConsoleEventDelegate(CtrlTypes ctrlType);
|
|
|
|
internal enum CtrlTypes : uint
|
|
{
|
|
CTRL_C_EVENT = 0,
|
|
CTRL_BREAK_EVENT,
|
|
CTRL_CLOSE_EVENT,
|
|
CTRL_LOGOFF_EVENT = 5,
|
|
CTRL_SHUTDOWN_EVENT
|
|
}
|
|
}
|
|
}
|