mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.24k stars 243 forks source link

SimpleTheme.makeTheme() gives an error #453

Closed AObuchow closed 4 years ago

AObuchow commented 4 years ago

Hey, I'm trying to use SimpleTheme.makeTheme() to theme my application.

As a test, I'm trying out

gui.setTheme(SimpleTheme.makeTheme(true, TextColor.ANSI.WHITE, TextColor.ANSI.BLACK, TextColor.ANSI.MAGENTA, TextColor.ANSI.BLUE, TextColor.ANSI.YELLOW, TextColor.ANSI.RED, TextColor.ANSI.GREEN));

However this is throwing a java.lang.IllegalArgumentException: Collection is empty Here's the full stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: Collection is empty
    at java.base/java.util.EnumSet.copyOf(EnumSet.java:173)
    at com.googlecode.lanterna.graphics.DefaultMutableThemeStyle.<init>(DefaultMutableThemeStyle.java:58)
    at com.googlecode.lanterna.graphics.SimpleTheme.<init>(SimpleTheme.java:110)
    at com.googlecode.lanterna.graphics.SimpleTheme.makeTheme(SimpleTheme.java:61)
    at com.aobuchow.sample.manager.App.main(App.java:74)

It seems DefaultMutableThemeStyle(TextColor foreground, TextColor background, SGR... sgrs) doesn't work with an empty set of SGR.

If you'd like me to submit a PR for this, just let me know :)

Thanks!

avl42 commented 4 years ago

After some initial confusion, it is now clear, that the route array->Collection->enumSet indeed doesn't work for empty arrays. apparently, Java has no way of inferring the correct EnumSet-type in that case.

I'd guess that one could create an empty EnumSet ahead, and then just addAll(sgrs).

If you have arrived at the same (or a nicer) solution, then please PR it. We'll have to wait for the boss (@mabe02) to merge it, though.

AObuchow commented 4 years ago

Sounds good. I'll work on a PR soon and submit it :)

mabe02 commented 4 years ago

Ouch, good catch! Since you've already started coding on it, please give it a try and raise a PR when ready.

AObuchow commented 4 years ago

Thank you to everyone who helped with this issue (@avl42, @jrb0001 & @mabe02) ! :)

Is there a planned release date/schedule for the next version of Lanterna? I look forward to using SimpleTheme.MakeTheme() in my application :)

Additionally, I was going to suggest: maybe I can help set up some CI instances for this repository through GitHub actions? There could be a CI workflow to verify that PR's build successfully, and another workflow to deploy to Maven Central when the Master branch is modified.

If this idea is worth looking into, I can create a new bug to track it :)

mabe02 commented 4 years ago

Yeah, I'll push a new version tomorrow

AObuchow commented 4 years ago

Okay, awesome :)

mabe02 commented 4 years ago

3.0.3 was just released to Sonatype

AObuchow commented 4 years ago

Great, can’t wait to consume all the fixes & features in this new version :D