Code Monkey home page Code Monkey logo

Comments (14)

eiredrake avatar eiredrake commented on May 24, 2024 2

I have not tested this, but if you want to stop the user from resizing a console window, this may work

class Program
    {
        private const int MF_BYCOMMAND = 0x00000000;
        public const int SC_CLOSE = 0xF060;
        public const int SC_MINIMIZE = 0xF020;
        public const int SC_MAXIMIZE = 0xF030;
        public const int SC_SIZE = 0xF000;

        [DllImport("user32.dll")]
        public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

        [DllImport("user32.dll")]
        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();

        static void Main(string[] args)
        {
            IntPtr handle = GetConsoleWindow();
            IntPtr sysMenu = GetSystemMenu(handle, false);

            if (handle != IntPtr.Zero)
            {
                DeleteMenu(sysMenu, SC_CLOSE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND);
            }
            Console.Read();
        }

    }

code is from here : https://social.msdn.microsoft.com/Forums/vstudio/en-US/1aa43c6c-71b9-42d4-aa00-60058a85f0eb/c-console-window-disable-resize?forum=csharpgeneral

Can confirm this works. I added it to my ConsoleWrapper interface and implementation.

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

sounds like it should be easy enough to reproduce. (simple to reproduce but quite a big update to fix).
I've put it in my diary to look at this tomorrow morning. I'm thinking some type of virtual void Refresh() that will be called on screen resize, so that you can redraw your UI. Not sure how that would work because Konsole is designed to live in realtime side by side with any ongoing writes to the console. Essentially tracking bespoke regions of a screen and when the console scrolls tracking the Y position so that we can continue to render in the correct location on scrolled portions of console window. When you resize a window, what's on line X that's been wrapped no longer has any meaning.
Ah, doh, ..ok, I rekon you're probably ok with that and just don't want it to crash. So I should be able to handle that. Keeping it all looking pretty, not so much.
I'll aim at getting a patch for stopping it from throwing an exception, and then think about how it possibly should work. Though I think I may need the scroll fix (as well as the speed fix) to Konsole to really do that properly.
BTW, I'm looking for volunteers to help me update Konsole.
see here:
https://www.linkedin.com/posts/goblinfactory_callforhelp-konsole-progressbar-activity-6602883874693406720-qqvb

from konsole.

eiredrake avatar eiredrake commented on May 24, 2024

was actually looking at it myself to try to see if there was a reasonable way to be alerted to the change in console size to maybe take some sort of corrective action. But didn't find any. Most of the googling had people saying you might as well implement a UI.

I don't know anything about porting to mac or linux so it might be an interesting thing to watch as it evolves. I can't say that I'd have anything useful to add in that respect but I'll poke my head in when I can.

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

looking at all these now in the following order
https://github.com/goblinfactory/konsole/blob/master/backlog.md

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

This has been fixed in package 3.4.1.
I have released a patch, please test and let me know if this solves your resizing issue.
https://www.nuget.org/packages/Goblinfactory.Konsole/3.4.1

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

I will close this issue if I don't hear back from you in a little while, or if you tell me this is working.

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

I have not tested this, but if you want to stop the user from resizing a console window, this may work

class Program
    {
        private const int MF_BYCOMMAND = 0x00000000;
        public const int SC_CLOSE = 0xF060;
        public const int SC_MINIMIZE = 0xF020;
        public const int SC_MAXIMIZE = 0xF030;
        public const int SC_SIZE = 0xF000;

        [DllImport("user32.dll")]
        public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

        [DllImport("user32.dll")]
        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();

        static void Main(string[] args)
        {
            IntPtr handle = GetConsoleWindow();
            IntPtr sysMenu = GetSystemMenu(handle, false);

            if (handle != IntPtr.Zero)
            {
                DeleteMenu(sysMenu, SC_CLOSE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND);
            }
            Console.Read();
        }

    }

code is from here : https://social.msdn.microsoft.com/Forums/vstudio/en-US/1aa43c6c-71b9-42d4-aa00-60058a85f0eb/c-console-window-disable-resize?forum=csharpgeneral

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

By the way, I ran your sample code and I noticed that the windows are rendered incorrectly when the height of a window is 3 lines high, and they render correctly if 4 or more lines.
see here : #31

I also saw the code needed to generate the layout you wanted (a common design) is not very elegant. Or more accurately, Konsole is not fluid enough to make creating the layout more elegantly, so I've got a draft of a new version committed (needs more tests), and will release that soon. You will be able to do the following;

        private static void QuickTest()
        {
            Console.CursorVisible = false;
            var c = new Window();
            var consoles = c.SplitRows(
                    new Split(4, "headline", LineThickNess.Single, ConsoleColor.Yellow),
                    new Split(0, "content", LineThickNess.Single),
                    new Split(4, "status", LineThickNess.Single, ConsoleColor.Red)
            );

            var headline = consoles[0];
            var content = consoles[1];
            var status = consoles[2];

            headline.Write("my headline");
            content.WriteLine("content goes here");
            status.Write("System offline!");
            Console.ReadLine();
        }

this produces the following output

no-bug

from konsole.

eiredrake avatar eiredrake commented on May 24, 2024

I'll give it a try shortly. Thank you for the fast response. Also I'll look at the way I'm creating the windows and rework.

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

I'm busy testing the final changes for columns, so you can now create any shape UI using rows and columns, passing a width or height of 0 to indicate it takes up the rest of the space.

Console.CursorVisible = false;
            var c = new Window();
            var consoles = c.SplitRows(
                    new Split(4, "heading", LineThickNess.Single),
                    new Split(0),
                    new Split(4, "status", LineThickNess.Single)
            ); ; ;

            var headline = consoles[0];
            var status = consoles[2];

            var contents = consoles[1].SplitColumns(
                    new Split(20),
                    new Split(0, "content") { Foreground = ConsoleColor.White, Background = ConsoleColor.Cyan },
                    new Split(20)
            );
            var menu = contents[0];
            var content = contents[1];
            var sidebar = contents[2];

            headline.Write("my headline");
            content.WriteLine("content goes here");

            menu.WriteLine("Options A");
            menu.WriteLine("Options B");

            sidebar.WriteLine("20% off all items between 11am and midnight tomorrow!");

            status.Write("System offline!");

gives you the following UI. This will be available in version 4.0.1 of Konsole. Should push that later tonight.

Capture

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

done, fix should be available shortly. Package is being verified
https://www.nuget.org/packages/Goblinfactory.Konsole/4.0.1
Package is live, please test. Going to close this issue now.

from konsole.

eiredrake avatar eiredrake commented on May 24, 2024

That worked pretty well actually.

 if (Environment.UserInteractive)
            {
                Console.CursorVisible = false;

                var mainWindow = new Window();
                var consoles = mainWindow.SplitRows(
                        new Split(4, "operation progress", LineThickNess.Single, ConsoleColor.Yellow),
                        new Split(0, "operation logging", LineThickNess.Single),
                        new Split(3, "system command", LineThickNess.Single, ConsoleColor.Red)
                );


                var progress_console = consoles.Take(1).FirstOrDefault();
                var logging_console  = consoles.Skip(1).Take(1).FirstOrDefault();
                var command_console  = consoles.LastOrDefault();

                
                var console_wrapper = new ConsoleWrapper(progress_console, logging_console, command_console, command_console.AbsoluteY);

                serviceCollection.AddSingleton<IConsoleWrapper>(console_wrapper);
            }

            return serviceCollection;

IConsoles don't seem to retain their name, is that true?

from konsole.

eiredrake avatar eiredrake commented on May 24, 2024

Bugger... nope it happened again when I resized the window to a smaller size

System.ArgumentOutOfRangeException: 'The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'sourceWidth')
Actual value was 106.'
at System.ConsolePal.MoveBufferArea(Int32 sourceLeft, Int32 sourceTop, Int32 sourceWidth, Int32 sourceHeight, Int32 targetLeft, Int32 targetTop, Char sourceChar, ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
 at Konsole.Window.ScrollUp()
 at Konsole.Window.WriteLine(String format, Object[] args)
 at Konsole.ConcurrentWriter.WriteLine(String format, Object[] args)
 at Progress_Reporter_tests_cli.Implementations.Serilog_Sink.StealthConsoleSink.Emit(LogEvent logEvent) in C:\Users\ekramer\Documents\Visual Studio 2019\Projects\Progress_Reporter_tests_cli\Progress_Reporter_tests_cli\Implementations\Serilog_Sink\StealthConsoleSink.cs:line 33
 at Serilog.Core.Sinks.SafeAggregateSink.Emit(LogEvent logEvent)

from konsole.

goblinfactory avatar goblinfactory commented on May 24, 2024

@eiredrake I think I have a really nice solution to your resizing problem
there's a checkbox, on the console default properties, "wrap text on resize", untick this and everything works like it was made in heaven.
see #33 for screenshot

from konsole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.