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

Please ship WindowsTerminal along with rest of the binary classes #422

Closed
unix-junkie opened this issue Jun 10, 2019 · 22 comments
Closed

Please ship WindowsTerminal along with rest of the binary classes #422

unix-junkie opened this issue Jun 10, 2019 · 22 comments

Comments

@unix-junkie
Copy link

Currently, the version of the library available from the Maven Central lacks WindowsTerminal class.

Please ship WindowsTerminal plus native code for win32/win64 along with the rest of the library.

Additionally, lanterna can have an optional dependency on the native-platform library which already ships the native primitives for all mainstream platforms. WindowsTerminal could be re-implemented via those primitives -- see WindowsConsoleFunctions.java.

@mabe02
Copy link
Owner

mabe02 commented Aug 18, 2019

Unfortunately, the native bindings library was more of an experiment and was never 100% functional. As long as it's experimental, I don't think it would be a good idea to distribute it to Maven central.

@avl42
Copy link
Contributor

avl42 commented Aug 18, 2019 via email

@rednoah
Copy link
Contributor

rednoah commented May 10, 2020

@mabe02 I had a crack at it over the weekend and got it working, after many many hours of debugging.

Since lanterna is already doing Class.forName(...) this can be added as 3rd party library, but you're welcome to merge it into your code base here:
https://github.com/rednoah/lanterna-wincon

They key was figuring out that on Windows the InputStream.available() method of System.in is basically lying, and so our input loop breaks in strange unexpected ways when it randomly starts blocking in code paths that shouldn't be blocking, or never reading anything when there is something to read.

@mabe02
Copy link
Owner

mabe02 commented May 16, 2020

Interesting! Did you write this from scratch or did you base it off the experimental work we've done in native-integration?

@rednoah
Copy link
Contributor

rednoah commented May 16, 2020

I started out with your code base to debug the issue. WindowsTerminal itself remains relatively unchanged. The new code is rewriting things to use ReadConsoleInput and GetNumberOfConsoleInputEvents instead of System.in.read() and System.in.available() (which just doesn't work) and to get resize events. Using WriteConsole for output helped with screen flickering and allows for printing Emoji.

@rednoah
Copy link
Contributor

rednoah commented May 18, 2020

jna-platform now includes the added native bindings as well:
java-native-access/jna@b22f85a

@mabe02
Copy link
Owner

mabe02 commented May 24, 2020

What would be really nice is if we auto-detect if JNA is available at runtime and only then load the WindowsTerminal class. Not sure if we can use the "optional" dependency feature in Maven for this (on jna) to make it compile at build time. Just want to avoid Lanterna pulling in JNA as a transient dependency when it's really only used in special case.

@rednoah
Copy link
Contributor

rednoah commented May 25, 2020

I'd make jna-platform a compile time dependency, and then just do catch LinkageError in the createWindowsConsole factory method to account for jna-platform missing from the class path, as well as jnidispatch.dll not working.

I'd probably also change the factory to default to using the Swing Terminal Emulator, even if we have a console window already, instead of the most-likely non-functional Cygwin implementation, and get rid of that use javaw instead error message.

@mabe02
Copy link
Owner

mabe02 commented May 31, 2020

I've read up on the optional tag and that seems like what we want, as it won't be included as a transitive dependency. Is you code you linked to above in a state where you think we can merge it?

@rednoah
Copy link
Contributor

rednoah commented May 31, 2020

I've done some testing with FileDialog (the most complex built-in component I could find) and that works perfectly as far as I can tell. Though I'm not using this in "production" yet. Testing is also limited to the latest Windows 10, so it may or may not work well on Windows 7, if that's a concern.

So setting setPreferTerminalEmulator(true) on Windows might be a good idea regardless.

@jrb0001
Copy link
Contributor

jrb0001 commented May 31, 2020

You will also need to add a requires static com.sun.jna; to module-info.java and you will need to catch the ClassNotFoundException in case the class isn't available on the classpath or module path (or it is on the classpath while lanterna is on the module path). Also keep in mind that JNA is not compatible with jlink because it is an automatic module so it will always be missing there.

@mabe02
Copy link
Owner

mabe02 commented Jun 7, 2020

Ok, here what we'll do. I'll branch of master into release/3.1 and we'll merge this jna code for a future 3.2 release on master.

@mabe02
Copy link
Owner

mabe02 commented Jun 7, 2020

@jrb0001 will the requires static com.sun.jna; work even if jna isn't on the classpath? I have really 0 experience with the Java module system.

@jrb0001
Copy link
Contributor

jrb0001 commented Jun 7, 2020

@mabe02 Yes, I tested that with the java.desktop dependency. If the module is on the module path, then it is available. And if not, then it simply doesn't exist. If lanterna is on the module path and JNA on the classpath then the latter applies.

@mabe02
Copy link
Owner

mabe02 commented Jun 14, 2020

There, that should do it! I've tested and it seems to work fine.

@reibitto
Copy link
Contributor

reibitto commented Aug 4, 2020

Just for confirmation, this feature got merged but there is no published artifact that includes it (including the beta)?

If it's still too experimental at this moment for a release of some kind, I can try building from source and report my findings (though Scala + SBT makes source dependencies kind of tricky... so it's not terribly ideal, but I'll manage).

I'm not sure if anybody is using the Windows terminal yet, but considering it's pretty important for one of my projects I can try helping with any potential bug fixes and testing.

@mabe02
Copy link
Owner

mabe02 commented Aug 10, 2020

I thought we had released a beta with this...? Let me check...

@mabe02
Copy link
Owner

mabe02 commented Aug 10, 2020

Ah, because I put this on master. But I can make an alpha release of 3.2 for you.

@reibitto
Copy link
Contributor

Thanks. That would be great. 👍

@mabe02
Copy link
Owner

mabe02 commented Aug 13, 2020

Having some issues with my gpg key not working with Sonatype, but should be available in a day or two

@mabe02
Copy link
Owner

mabe02 commented Aug 15, 2020

Ok, finally. 3.2.0-alpha1 released to Sonatype, should be available shortly on Maven central.

@reibitto
Copy link
Contributor

Thanks! I tried this in my project and it works. All I had to really do is add the JNA dependency: reibitto/command-center#85

I haven't run into any bugs or anything like that so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants