mabe02 / lanterna

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

Can Lanterna be used to give autocomplete suggestions on a bash shell prompt? #458

Open part95 opened 4 years ago

part95 commented 4 years ago

I was wondering if I could use Lanterna to build a simple autocomplete like functionality on my bash shell prompt. I see this python library: https://github.com/prompt-toolkit/python-prompt-toolkit which people are using to build autocompletion tools but I was more interested in something JVM based.

Just wondering if Lanterna can be used for my intended use?

avl42 commented 4 years ago

Java is probably not the first language that springs to my mind for such tools, as my experience with java is that each startup of the jvm takes a couple of seconds...

part95 notifications@github.com schrieb am So., 26. Apr. 2020, 20:50:

I was wondering if I could use Lanterna to build a simple autocomplete like functionality on my bash shell prompt. I see this python library: https://github.com/prompt-toolkit/python-prompt-toolkit which people are using to build autocompletion tools but I was more interested in something JVM based.

Just wondering if Lanterna can be used for my intended use?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mabe02/lanterna/issues/458, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIDBMV2UOVE3VW52RQG52DROR7APANCNFSM4MRLJWQA .

part95 commented 4 years ago

I agree that JVM takes a long time to start off, but I think surely it's not slower than Python runtime.

Also, in these cases, I'm thinking something like a running daemon that provides autocomplete options, so I won't be starting JVM each time repeatedly. That's the thinking.

part95 commented 4 years ago

So suppose I stop caring about any latency issues for a while, what I was wondering was if Lanterna has any such functionality that I can use to build autocompletion with it? I'm not very familiar with Lanterna, so not sure if such a feature already exists or how much work it would be to build something like that with Lanterna.

avl42 commented 4 years ago

yes, this kind of architecture certainly works, because my project with lanterna does it: a server process with lanterna, and special clients (written in Tcl in my case) that connect to the server, and let the server do the heavy lifting. I'm not saying it was easy, though... e.g. the client will need to read stdin and output to stdout on behalf of the server/daemon.

What surprises me more is, how lanterna fits in. I haven't seen interactive expansion tools so far

part95 notifications@github.com schrieb am So., 26. Apr. 2020, 23:27:

I agree that JVM takes a long time to start off, but I think surely it's not slower than Python runtime.

Also, in these cases, I'm thinking something like a running daemon that provides autocomplete options, so I won't be starting JVM each time repeatedly. That's the thinking.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mabe02/lanterna/issues/458#issuecomment-619627595, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIDBMUZIMEOMTCD5XXDD53ROSRL3ANCNFSM4MRLJWQA .

avl42 commented 4 years ago

I doubt that lanterna will do anything specific for shell expansion. that will be your own code. But if you want your tab tab to result in an interactive textgui popup, then it might help you for that.

If you found lanterna in a search for "tab expansion", then you're likely misguided here. tab expansion for lanterna means to convert a tab character into a position dependent number of blanks.

part95 notifications@github.com schrieb am So., 26. Apr. 2020, 23:32:

So suppose I stop caring about any latency issues for a while, what I was wondering was if Lanterna has any such functionality that I can use to build autocompletion with it? I'm not very familiar with Lanterna, so not sure if such a feature already exists or how much work it would be to build something like that with Lanterna.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mabe02/lanterna/issues/458#issuecomment-619628252, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIDBMU32FP7DPWKA2WGJGDROSR57ANCNFSM4MRLJWQA .

part95 commented 4 years ago

I doubt that lanterna will do anything specific for shell expansion. that will be your own code. But if you want your tab tab to result in an interactive textgui popup, then it might help you for that.

This should be enough. I'll write the business logic to populate the autocompletion entries. All I'm looking is to offload the graphics and popup generation functionality to some already implemented graphics library.

avl42 commented 4 years ago

The only thing left to find out is, whether the expansion programs are allowed to access the terminal. I assume that the resulting list of expansions is typically sent to stdout, so you will likely have to find some tricks to let lanterna talk to the tty directly, rather than via stdin/stdout.

part95 commented 4 years ago

so you will likely have to find some tricks to let lanterna talk to the tty directly

If I'm understanding correctly, is this because Lanterna would write these autocomplete suggestions overlaid on top of the terminal? In other words, the suggestions would appear slightly raised and not just on the terminal via the standard stdout or sterr?

apatrida commented 4 years ago

@part95 look to https://github.com/remkop/picocli/tree/master/picocli-shell-jline3

mabe02 commented 4 years ago

The key point here is that Lanterna is currently not equipped to run a shell in a lanterna wrapped terminal. You can start the shell process, but we would need significant native hooks to connect all the signals and device settings.