Guys, can you point some good examples, please, on...
# announcements
v
Guys, can you point some good examples, please, on how to implement (preferably in Kotlin) interactive command-line mode for an app, just like smbclient has?
d
This would be mostly the same as how youd do it in Java, so that's a good starting point. Unless you use native which should probably be specified.
v
Yep, just looking through Java Curses library. But I hope it can be done in more simple way, perhaps,
java.io.Console
n
If you are heading down the curses library route then Kotlin Native is the way to go. Will have much more control, and the developed program will be using less resources than a Kotlin JVM one.
Also the C ecosystem provides greater support for CLI development than Java does, which is another major reason to go with Kotlin Native.
v
I would like to target JVM for more portability, so end-user can launch it on Mac/Win/Linux without compiling
1
I would think about native support later (I hope)
n
One of the major issues with JVM based programs is that they are difficult to deploy compared to native ones (eg have to include the JVM runtime, and figure out a way to create a binary).
1
v
Agree, especially with JavaFX 🙂
That's why I'd like to minimize dependencies to JVM only. The problem is that I did not find a simple way to use Google API with native
n
Which library?
Was much easier to deploy JavaFX programs with JVM 8 (via javafxpackager) than it was with newer JVM versions.
v
I'm still on JDK8
This one https://github.com/beryx/text-io looks attractive
But it requires some time to study
g
Agree, especially with JavaFX
Good luck with distributing native application with UI for different platforms
What does "will have much more control" mean?
v
Swing causes less troubles than JFX (don't need to install a separate library as in case of OpenJFX)
g
Yes, I agree that now run Fx apps is less pleasant, but you can just bundle JavaFx module
My comment was just about comparasion with native, that native distribution is definitely not easier, especially you are going to support multiple platforms.
v
Gtk and Qt are claiming to be cross-platform, but... I tried once Qt on Windows - do not want anymore. From ordinary user's view installing JVM is a pain (installing JVM + JavaFX is a nightmare). Support native graphical toolkits (VCL, Cocoa, Gtk, Qt, Tk, etc) is a nightmare for developers. Command-line interface should work in most cases 🙂
JLine3 seems to be a bit platform-dependent too
g
installing JVM + JavaFX is a nightmare
JavaFx module jus should be bundled to your app, so you can run it on JVM without Fx
🤔 1
From ordinary user’s view installing JVM is a pain
Definitely not more than installing Qt or Gtk, otherwise you have to bundle it. And if you bundle everything it’s not different from bundling whole JVM using jlink
I agree in general, there is no perfect solution, trade-offs are everywhere, especially for UI
r
You can also try targeting Kotlin/JS and use some Node.js libraries (https://github.com/chjj/blessed). It should be relatively easy to deploy using npm.
v
Interesting option (bookmarked it)
@gildor, bundling JavaFX is platform-specific, if I'm not mistaken, it requires some binary libraries (.so, .dll, etc), it looks just like supplying Gtk+ with an app (native)
n
Gtk wasn't meant to be used on platforms other than Linux even though Gtk is cross-platform. On Linux Gtk is native since most of the desktop environments (Cinnamon, Gnome, Xfce etc) are Gtk based.
v
@napperley, have you tried to use Kotlin native + Qt? Just interesting for comparison difficulty/portability
g
Qt is C++ framework (some even arguing that it’s C++ at all, but some Cpp-like language) with a lot of own complications
v
Discussion slowly slithered to cross-platform graphics... In my view the most optimal solution is CLI that depends solely on basic JVM (without JavaFX), so that it can be used even on servers without graphics available. So far I have found only 2 options: text-io libraries and jline3 libraries. Also suggestions to use native + some (what) libraries for command-line and JS/Blessed with NPM (perhaps, Electron)
g
How requirement “it can be used even on servers without graphics” and Electron are coexist?
It really depends on what kind “CLI UI” do you need of course, text-io is just a relatevely simple wrapper for readLine, isn’t it? If so I don’t see any reason to use any kind UI or native for this
If you need something like ncurses, have you checked? https://github.com/mabe02/lanterna
👍 1
I would say that you should first collect list of requirements and list of “good to have” and also generic cos/pros of every soltion and consider base on it
👍 1
v
@gildor, you're right, text-io seems to be quite primitive with some unnessesary features. As for Electron... I thought about an alternative when terminal emulator is not available. For JVM such an alternative can be Swing window, for JS, I guess, Electron 🙂
g
alternative when terminal emulator is not available
And when it’s not available?
v
When a program is launched via link or some other GUI
g
Electron is huge, don’t think that it make any sense to use it for small/medium application, it’s perfect if you already have some code on web
v
In my view NPM is not preferable either
g
When a program is launched via link
But there is no universal way to do that, you need some integration with operation system for this
some other GUI
What kind UI? I also don’t think that there is any OS-independent solution
NPM is just a package manager
and can be used for a lot of different types of application, it’s not an option itself
Maybe if you really want to run it everywhere, on every OS with every setup, you just need webservice (some website for UI and some API for server)?
v
Lanterna looks awesome, thanks for the link
I wanna also try JLine3
Oh, no, no web-service, I need it to be standalone
n
Kotlin Native doesn't have C++ interop so QT isn't a option.
v
Bad news 😞
g
not sure that if you have no way to use QT is may consider as bad news 🧌
v
Problems with C++ interop are bad. Actually I was dreaming to capture the (software) world with Kotlin
g
Direct interop with C++ is a c huuuge pain, C++ doesn't have stable ABI, very few languages actually invest into it (for example D, which was originally target C++ interop and positioned as C++ replacement), Even languages as Rust don't have it. So essentially the only way is expose C++ API using C
1
v
Hmm. That I was thinking about... E.g. we have OpenCV library that is written in C++, it also has Java interface. But in C++ it's possible to overload operators, i.e. we can
rectA + rectB
or
captureDevice >> frameToProcess
, but with Java it would be just
rectA.add(rectB)
or
captureDevice.read(frameToProcess)
. I was thinking that it would be nice to have C++ interop because of operator overloading in both C++ and Kotlin
Hmm, perhaps, it's not true for rectangles, but for matrices looks like so
g
OpenCV has official C and Java APIs so possible to use from Kotlin Native and JS. Not sure about OpenCV, but operator overload is least problem when you use API of another language (especially such complicated as C++)
We (fortunately) don't have operator overload for >> in Kotlin 😬,