Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getWindowsTerminalWidth Issue #175

Closed
frossm opened this issue Nov 11, 2020 · 2 comments · Fixed by grails/grails-data-mapping#1444 · May be fixed by gnodet/jansi#1
Closed

getWindowsTerminalWidth Issue #175

frossm opened this issue Nov 11, 2020 · 2 comments · Fixed by grails/grails-data-mapping#1444 · May be fixed by gnodet/jansi#1

Comments

@frossm
Copy link

frossm commented Nov 11, 2020

Hello,

With the update to jansi 2.0.1, I can't seem to find getWindowsTerminalWidth() anymore. Is there another function I should be using to get the the columns in the terminal window instead?

Here is the call I was using
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
terminalWidth = org.fusesource.jansi.internal.WindowsSupport.getWindowsTerminalWidth() - 1;
}

BTW, I love the library and use it on all of my projects. Thanks for all of the work on this.

Michael

@gnodet
Copy link
Member

gnodet commented Dec 1, 2020

Yes, right now, you can define the method using

public static int getWindowsTerminalWidth() {
        long outputHandle = GetStdHandle (STD_OUTPUT_HANDLE);
         CONSOLE_SCREEN_BUFFER_INFO info = new CONSOLE_SCREEN_BUFFER_INFO();
         GetConsoleScreenBufferInfo (outputHandle, info);
         return info.windowWidth();
}

Is that specific to windows ? I could re-introduce a helper function, but I don't really why it would be specific on windows.
Maybe something like:

    public static int getTerminalWidth() {
        if ("Windows".equals(OSInfo.getOSName())) {
            long outputHandle = Kernel32.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
            Kernel32.CONSOLE_SCREEN_BUFFER_INFO info = new Kernel32.CONSOLE_SCREEN_BUFFER_INFO();
            Kernel32.GetConsoleScreenBufferInfo(outputHandle, info);
            return info.windowWidth();
        } else {
            CLibrary.WinSize sz = new CLibrary.WinSize();
            CLibrary.ioctl(CLibrary.STDOUT_FILENO, CLibrary.TIOCGWINSZ, sz);
            return sz.ws_col;
        }
    }

I'd have to check that it works on Cygwin and other enhanced Windows environments...

@metacodez
Copy link

Hello,

Is that specific to windows ? I could re-introduce a helper function, but I don't really why it would be specific on windows.
Maybe something like:

Such a function would be great for me too! Some of my code plays orund with the terminal in terms of ASCII-Art, and I just uncommented the detection of the console width for Windows using JANSI as I upgraded to the latest JANSI version. As soon as the helper methods will be avaialable, I will re-introduce JANSI's width detection as it was the most reliable one I encountered till now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment