Fork me on GitHub
#babashka
<
2023-01-16
>
jaihindhreddy11:01:49

Do people write TUI apps with Babashka? If so, what are the relevant libs to do so?

borkdude11:01:11

I've done some experiments with lanterna: https://twitter.com/borkdude/status/1569351199404576770 It worked pretty well, but I don't consider the pod stable. You can play around with it locally though and see how far you get. But if you want some simple dialogs, then this may be a nice approach: https://www.pixelated-noise.com/blog/2022/12/09/dialog-and-babashka/index.html Node.js / #nbb might give you better options using something like reagent and Ink: https://github.com/babashka/nbb#reagent

borkdude11:01:30

you can obtain (exerimental) binaries for pod-babashka-lanterna here from the builds: https://app.circleci.com/pipelines/github/babashka/pod-babashka-lanterna and then play around with it - docs are here: https://github.com/babashka/pod-babashka-lanterna

thanks3 2
orestis11:01:38

Is the *warn-on-reflection* var meaningful in babashka scripts? I am asking because clj-kondo will lint a babashka file (ending in .clj though) and complain about using (System/exit 1) without a warn-on-reflection set...

orestis11:01:37

This can take so many directions: • Should accessing static functions on a namespace such System/exit trigger the reflection warning? • Does kondo have different linters for babashka files? • Should babashka files have a .clj extension? (Our babashka file uses clj-kondo as a pod so it's definitely bb only)

borkdude11:01:24

This is an optional linter. You can set warn-on-reflection in babashka, but it has no effect. You can use the .bb extension as well if you want

borkdude11:01:44

or you can disable the linter for babashka scripts using an additional config

orestis11:01:54

We have it on inside our .clj-kondo/config.edn , since we do care about it in production.

orestis11:01:17

Hm, how would we define an additional config only for babashka scripts? So e.g. src and test get linted with one config, then bin gets linted with something else?

borkdude11:01:24

In babashka you can also use (throw (ex-info "msg" {:babashka/exit 1})

borkdude11:01:53

I'd say, just go with the *warn-on-reflection* in your bb script, even though it has no effect, it's at least consistent with the rest of your code

orestis11:01:22

that does make sense

orestis11:01:27

Thanks for the input!

👍 2
nixin7217:01:58

Is it possible to spawn child processes and disown them in babashka? I'm trying to write some convenience wrappers around a bunch of bash scripts, but a number of them spawn background child tasks. Trying to run those scripts through babashka will result in those child processes being killed when the task is done. Ex.

# test.sh
sleep 5
echo "HERE"
# test2.sh
./test.sh &
If I run test2.sh in a terminal, then the script will finish, drop me back into my prompt, and then I'll get interupted with that "HERE" in 5 seconds. If I do
;; bb.edn
{:tasks 
 {:requires ([babashka.process :as ps])
  test (ps/process "./test2.sh")}} 
And then run bb test , I'll just never see that HERE printed cause the child background process is killed

borkdude17:01:44

Use babashka.process/process , not shell

nixin7217:01:03

Sorry, I sent that before I meant to, I've edited to include more information. I'm using the process library

borkdude17:01:13

e.g. this works for me:

bb -e '(babashka.process/process {:inherit true} "/tmp/sleep.sh")'

nixin7217:01:42

Hmm. I have this task with exactly those bash scripts above, and it's not doing anything

bg        (ps/process "./scripts/test2.sh &" {:inherit true})
Running bb bg does nothing, I never get the echos from the bash script

nixin7217:01:17

Oh, removing the & from the string there does nothing either, I just added that to try it

borkdude17:01:19

you should put {:inherit true} before the string

nixin7217:01:43

Oh, whoops 😅 Still nothing though...

borkdude17:01:46

$ cat /tmp/sleep.sh
# test.sh
sleep 5
echo "HERE"
$ bb -e '(babashka.process/process {:inherit true} "/tmp/sleep.sh") nil'
$ HERE
Try this first. Don't forgot to chmod +x the /tmp/sleep.sh script

borkdude17:01:11

Then tell me if that works or not for you

nixin7217:01:24

Hmm, that still doesn't work.

$ ./scripts/test2.sh

$ HERE

$ bb -e '(babashka.process/process {:inherit true} "./scripts/test2.sh") nil'

$
$

borkdude17:01:39

what OS are you on?

borkdude17:01:01

"bash -c './scripts/test2.sh'"
might work

nixin7218:01:27

Wrapping it in bash -c doesn't work either 😅 Oh well, it's not a big deal.

borkdude18:01:29

Weird, I'm also on mac

borkdude18:01:38

@U01BH40EA0Z Perhaps you can make a github repo so we are executing 100% the same code - I find it weird that we're both on a mac and we get different behavior. What's your bb version?

pesterhazy19:01:44

Are you on the latest babashka?

pesterhazy19:01:12

The opts-first syntax will silently fail on older versions

borkdude19:01:29

yeah, so let's make a repro so we're 100% sure about the code and also specify the bb version

nixin7220:01:19

@U04V15CAJ Here's a repo. I'm using babashka version v1.0.168 and MacOS 13.0.1

borkdude20:01:49

Where's the repo? 1.0.168 should be good

nixin7220:01:11

Oh lol, sorry, forgot to paste the link https://github.com/nixin72/testing

borkdude20:01:23

@U01BH40EA0Z This works perfectly over here:

$ bb tasks
The following tasks are available:

test
borkdude@m1 /tmp/testing (main) $ bb test
borkdude@m1 /tmp/testing (main) $ HERE
bb terminates and then HERE is printed. Also tested with 1.0.168. My shell is zsh

nixin7220:01:03

Huh... I'm even also using zsh

borkdude20:01:07

Can you do file $(which bb) and paste the output?

borkdude20:01:34

Can you test from a vanilla bash shell?

$ bash

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit .
bash-3.2$ bb test
bash-3.2$ HERE

nixin7220:01:42

Ooh I have bb aliased to rlwrap bb, that might have something to do with it

nixin7220:01:05

Yup, running in bash where the alias doesn't exist works

borkdude20:01:09

yep, I can repro that ;)

nixin7220:01:13

:face_palm:

borkdude20:01:42

mystery solved then

nixin7220:01:19

Thank you so much as always @U04V15CAJ! I really appreciate it

borkdude20:01:34

Glad we solved it