https://kotlinlang.org logo
Title
v

ValV

07/07/2019, 1:37 AM
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

Dico

07/07/2019, 1:39 AM
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

ValV

07/07/2019, 1:48 AM
Yep, just looking through Java Curses library. But I hope it can be done in more simple way, perhaps,
java.io.Console
n

napperley

07/07/2019, 1:50 AM
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

ValV

07/07/2019, 1:54 AM
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

napperley

07/07/2019, 1:57 AM
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

ValV

07/07/2019, 2:00 AM
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

napperley

07/07/2019, 2:27 AM
Which library?
Was much easier to deploy JavaFX programs with JVM 8 (via javafxpackager) than it was with newer JVM versions.
v

ValV

07/07/2019, 2:31 AM
I'm still on JDK8
This one https://github.com/beryx/text-io looks attractive
But it requires some time to study
g

gildor

07/07/2019, 3:46 AM
Agree, especially with JavaFX
Good luck with distributing native application with UI for different platforms
What does "will have much more control" mean?
v

ValV

07/07/2019, 4:25 AM
Swing causes less troubles than JFX (don't need to install a separate library as in case of OpenJFX)
g

gildor

07/07/2019, 5:00 AM
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

ValV

07/07/2019, 5:15 AM
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

gildor

07/07/2019, 5:33 AM
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

Robert Jaros

07/07/2019, 12:59 PM
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

ValV

07/07/2019, 3:10 PM
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

napperley

07/07/2019, 9:43 PM
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

ValV

07/08/2019, 12:07 AM
@napperley, have you tried to use Kotlin native + Qt? Just interesting for comparison difficulty/portability
g

gildor

07/08/2019, 12:53 AM
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

ValV

07/08/2019, 1:54 AM
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

gildor

07/08/2019, 2:01 AM
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

ValV

07/08/2019, 2:07 AM
@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

gildor

07/08/2019, 2:09 AM
alternative when terminal emulator is not available
And when it’s not available?
v

ValV

07/08/2019, 2:10 AM
When a program is launched via link or some other GUI
g

gildor

07/08/2019, 2:10 AM
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

ValV

07/08/2019, 2:11 AM
In my view NPM is not preferable either
g

gildor

07/08/2019, 2:11 AM
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

ValV

07/08/2019, 2:13 AM
Lanterna looks awesome, thanks for the link
I wanna also try JLine3
Oh, no, no web-service, I need it to be standalone
n

napperley

07/08/2019, 10:26 PM
Kotlin Native doesn't have C++ interop so QT isn't a option.
v

ValV

07/09/2019, 8:01 AM
Bad news 😞
g

gildor

07/09/2019, 10:04 AM
not sure that if you have no way to use QT is may consider as bad news :troll:
v

ValV

07/09/2019, 12:29 PM
Problems with C++ interop are bad. Actually I was dreaming to capture the (software) world with Kotlin
g

gildor

07/09/2019, 12:35 PM
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

ValV

07/09/2019, 1:03 PM
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

gildor

07/09/2019, 1:21 PM
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 😬,