Example #1
0
        public static ConsoleKeyInfo ReadKey()
        {
            NativeConsole.INPUT_RECORD[] keyInfo = new NativeConsole.INPUT_RECORD[1];
            //var test = Console.ReadKey();

            uint nRead;

            while (NativeConsole.ReadConsoleInput(NativeConsole.GetStdHandle(NativeConsole.STD_INPUT_HANDLE), keyInfo, 1, out nRead) && nRead != 0)
            {
                //Debug.WriteLine("{0} {1} {2}", keyInfo[0].EventType, keyInfo[0].KeyEvent.bKeyDown, (int)keyInfo[0].KeyEvent.UnicodeChar);

                if (keyInfo[0].EventType == NativeConsole.InputEventType.Key &&
                    keyInfo[0].KeyEvent.bKeyDown &&
                    keyInfo[0].KeyEvent.UnicodeChar != 0)
                {
                    var test1 = new ConsoleKeyInfo(keyInfo[0].KeyEvent.UnicodeChar,
                                                   (ConsoleKey)keyInfo[0].KeyEvent.wVirtualKeyCode,
                                                   (keyInfo[0].KeyEvent.dwControlKeyState & NativeConsole.ControlKeyStates.ShiftPressed) != 0,
                                                   (keyInfo[0].KeyEvent.dwControlKeyState & (NativeConsole.ControlKeyStates.LeftAltPressed | NativeConsole.ControlKeyStates.RightAltPressed)) != 0,
                                                   (keyInfo[0].KeyEvent.dwControlKeyState & (NativeConsole.ControlKeyStates.LeftCtrlPressed | NativeConsole.ControlKeyStates.RightAltPressed)) != 0
                                                   );
                    return(test1);
                }
            }

            throw new NotImplementedException();
        }
Example #2
0
 private static async Task NativeConsoleTest()
 {
     NativeConsole.Write(
         "123 GGG",
         "456 A B C D",
         "789 EFG");
 }
Example #3
0
        void RebuildConsole()
        {
            _console?.Dispose();

            _console           = new NativeConsole(_width, _height, Material);
            _filter.sharedMesh = _console.Mesh;

            _resized = true;
        }
Example #4
0
        public static void SwitchBuffer()
        {
            NativeConsole.SetConsoleActiveScreenBuffer(buffers[currentBuffer]);

            currentBuffer = (currentBuffer + 1) % 2;
            currentHandle = buffers[currentBuffer];

            NativeConsole.CHAR_INFO[] ci   = new NativeConsole.CHAR_INFO[bufferSize.X * bufferSize.Y];
            NativeConsole.SMALL_RECT  rect = new NativeConsole.SMALL_RECT(0, 0, (short)(bufferSize.X - 1), (short)(bufferSize.Y - 1));
            NativeConsole.WriteConsoleOutput(currentHandle, ci, bufferSize, new NativeConsole.COORD(), ref rect);

            NativeConsole.SetConsoleCursorPosition(currentHandle, new NativeConsole.COORD(0, 0));
        }
Example #5
0
        private static IntPtr CreateBuffer()
        {
            var buffer = NativeConsole.CreateConsoleScreenBuffer(
                NativeConsole.GENERIC_READ | NativeConsole.GENERIC_WRITE,
                1, IntPtr.Zero, NativeConsole.CONSOLE_TEXTMODE_BUFFER, IntPtr.Zero);

            NativeConsole.CONSOLE_SCREEN_BUFFER_INFO_EX info = NativeConsole.CONSOLE_SCREEN_BUFFER_INFO_EX.Create();
            // info.cbSize = sizeof(NativeConsole.CONSOLE_SCREEN_BUFFER_INFO_EX);
            NativeConsole.GetConsoleScreenBufferInfoEx(defaultHandle, ref info);
            info.dwSize = bufferSize;
            NativeConsole.SetConsoleScreenBufferInfoEx(buffer, info);
            //NativeConsole.SetConsoleScreenBufferSize(buffer, new NativeConsole.COORD(80, 40));

            return(buffer);
        }
Example #6
0
        static Console2()
        {
            defaultHandle = NativeConsole.GetStdHandle(NativeConsole.STD_OUTPUT_HANDLE);
            currentHandle = defaultHandle;


            NativeConsole.CONSOLE_SCREEN_BUFFER_INFO info;
            NativeConsole.GetConsoleScreenBufferInfo(currentHandle, out info);


            foregroundColor = (ConsoleColor)(info.wAttributes & 0x0F);
            backgroundColor = (ConsoleColor)((info.wAttributes & 0xF0) >> 4);

            bufferSize = new NativeConsole.COORD(80, 35);
        }
Example #7
0
        public static int Main()
        {
            NativeConsole console = NativeConsole.Instance;

            var launcher = new TestLauncher
            {
                EchoResults             = true,
                Logger                  = new FilteredLogger(new RichConsoleLogger(console), Verbosity.Normal),
                ProgressMonitorProvider = new RichConsoleProgressMonitorProvider(console),
                RuntimeSetup            = new RuntimeSetup(),
                TestProject             = { TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local }
            };

            string gallioBin =
                Environment.GetEnvironmentVariable(GallioBinEnvironmentVariable) ??
                InstallationConfiguration.LoadFromRegistry().InstallationFolder;

            if (string.IsNullOrEmpty(gallioBin))
            {
                Console.Error.WriteLine("Cannot find Gallio installation directory.");
                Console.Error.WriteLine("Specify it with \"{0}\" environment variable.", GallioBinEnvironmentVariable);
                return(1);
            }

            launcher.AddFilePattern(typeof(Driver).Assembly.Location);
            launcher.RuntimeSetup.AddPluginDirectory(gallioBin);

            TestLauncherResult result = launcher.Run();

            ConsoleColor originalConsoleColor = console.ForegroundColor;

            console.ForegroundColor = result.ResultCode == ResultCode.Success
                                ? ConsoleColor.DarkGreen
                                : ConsoleColor.Red;

            console.WriteLine();
            console.WriteLine(result.ResultSummary);
            console.WriteLine();

            console.ForegroundColor = originalConsoleColor;

            if (result.ResultCode != ResultCode.Success && Debugger.IsAttached)
            {
                Debugger.Break();
            }

            return(result.ResultCode);
        }
Example #8
0
    public void ScheduleWriteParallelRead()
    {
        int w       = 40;
        int h       = 15;
        var console = new NativeConsole(w, h);

        string str = "Hello";

        var jobs = console.SchedulePrint(0, 0, str);

        NativeArray <JobHandle> readJobs = new NativeArray <JobHandle>(5, Allocator.TempJob);

        List <NativeArray <Tile> > buffers = new List <NativeArray <Tile> >();

        for (int i = 0; i < 5; ++i)
        {
            buffers.Add(new NativeArray <Tile>(5, Allocator.TempJob));

            var readJob = console.ScheduleReadTiles(0, 0, 5, buffers[i], jobs);

            readJobs[i] = readJob;
        }

        jobs = JobHandle.CombineDependencies(readJobs);

        readJobs.Dispose();

        jobs.Complete();

        for (int i = 0; i < 5; ++i)
        {
            Assert.AreEqual('H', ToChar(buffers[i][0].glyph));
            Assert.AreEqual('e', ToChar(buffers[i][1].glyph));
            Assert.AreEqual('l', ToChar(buffers[i][2].glyph));
            Assert.AreEqual('l', ToChar(buffers[i][3].glyph));
            Assert.AreEqual('o', ToChar(buffers[i][4].glyph));
        }

        for (int i = 0; i < buffers.Count; ++i)
        {
            buffers[i].Dispose();
        }


        console.Dispose();
    }
Example #9
0
 private void MakeConsole()
 {
     if (_nativeConsole == null)
     {
         try
         {
             // don't initialize in the constructor
             _nativeConsole = new NativeConsole(false);
             // this way, we can handle (report) any exception...
             _nativeConsole.Initialize();
             _nativeConsole.WriteOutput += (source, args) => WriteNativeOutput(args.Text.TrimEnd('\n'));
             _nativeConsole.WriteError  += (source, args) => WriteNativeError(args.Text.TrimEnd('\n'));
         }
         catch (ConsoleInteropException cie)
         {
             WriteNativeError("Couldn't initialize the Native Console: " + cie.Message);
         }
     }
 }
Example #10
0
    public void ScheduleWrite()
    {
        int w       = 40;
        int h       = 15;
        var console = new NativeConsole(w, h);

        string str = "Hello";

        var job = console.SchedulePrint(0, 0, str);

        job.Complete();

        var tiles = console.ReadTiles(0, 0, 5, Allocator.Temp);

        for (int i = 0; i < 5; ++i)
        {
            Assert.AreEqual(str[i], ToChar(tiles[i].glyph));
        }

        console.Dispose();
    }
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += On_ProcessExit;

            Console.OutputEncoding = Encoding.UTF8; //unicode not supported by mono correctly
            Console.InputEncoding  = Encoding.UTF8;

            //new Thread(Listener).Start();

            var platform = Environment.OSVersion.Platform;
            var winNt    = platform == PlatformID.Win32NT;

            con = new NativeConsole(winNt && !Console.IsOutputRedirected
                ? (IAnsiConsole) new ConhostAnsiConsole()
                : new GenericAnsiConsole());

            con.Init();

            Console.WriteLine(Console.OutputEncoding);

            TestRendering();
            return;

            var ansi = new AnsiInputConverter();

            while (true)
            {
//                if (!Console.KeyAvailable) {
//                    Thread.Sleep(new TimeSpan(20000));
//                    continue;
//                }
                char c = ansi.Read(false);
                Console.Write(c);
                var ev = ansi.DequeueEvent();
                Console.Write(ev?.ToString());
            }



////            bool last = false;
////            var sw = new Stopwatch();
//            while (true) {
////                if (!Console.KeyAvailable) {
////                    if (!last) {
////                        sw.Start();
////                        last = true;
////                    }
////                    Thread.Sleep(new TimeSpan(10000));
////                    Console.Write('.');
////                    continue;
////                }
////                if (last) {
////                    Console.WriteLine($"{sw.ElapsedMilliseconds}");
////                    sw.Reset();
////                    last = false;
////                }
//                var c = Console.ReadKey(true);
//                var shift = (c.Modifiers & ConsoleModifiers.Shift) != 0 ? "Shift" : "NoShift";
//                var control = (c.Modifiers & ConsoleModifiers.Control) != 0 ? "Control" : "NoControl";
//                var alt = (c.Modifiers & ConsoleModifiers.Alt) != 0 ? "Alt" : "NoAlt";
//                Console.Write($"'{c.KeyChar}' {(int)c.KeyChar}, {c.Key}, {shift}, {control}, {alt} \n");
//            }
        }
Example #12
0
        public static void Write(string value)
        {
            uint written;

            NativeConsole.WriteConsoleW(currentHandle, value, value.Length, out written, IntPtr.Zero);
        }
Example #13
0
 public void KillConsole()
 {
     _nativeConsole?.Dispose();
     _nativeConsole = null;
 }