Fork me on GitHub
#portal
<
2020-12-30
>
firstclassfunc22:12:31

This is super cool, I have a complex data structure I want to visualize thats driven by bb command line. Is there a way to use portal as a super print-table from within by bb script?

djblue02:12:20

Hi @UMFRQDVU1, this should be possible, portal does work with babashka. All you need to do is p/open portal from bb and push the data to it via tap>. Then you can select the table-viewer. You can even add metadata to your data to select a default viewer. Let me know if something is unclear.

firstclassfunc14:12:40

Hi @U1G869VNV yea the problem I think is I canโ€™t block the thread so when bb completes it breaks the connection to the portal

firstclassfunc17:12:14

And is there docs on adding meta data

djblue19:12:58

It's not currently documented but an example can be found here: https://github.com/djblue/portal/blob/master/src/examples/data.cljc#L82

๐Ÿ‘ 3
djblue19:12:35

(with-meta <data> {:portal.viewer/default :portal.viewer/table}) should work

djblue19:12:49

I am not sure what you mean by can't block the thread. As long as the bb script is running, you should always be able to send data to portal.

djblue19:12:10

Data is always sent async to portal

firstclassfunc19:12:23

yea the problem is my script calls an api, transforms some data spits out an output and exits. So I launch portal but then script exits leaving it orphaned

djblue19:12:17

Is there a problem with keeping the bb script running?

firstclassfunc19:12:11

well thats the part I am confused about i.e. keeping the script blocked while user examines portal, then exit script when portal closes

djblue19:12:20

Ohh, are you are asking how to keep bb from exiting? https://github.com/djblue/portal/blob/master/src/portal/main.clj#L26 is how I do it for portal.main

djblue19:12:55

You can also add

(.addShutdownHook
     (Runtime/getRuntime)
     (Thread. #(p/close)))
To auto close portal on process exit ๐Ÿ‘Œ

firstclassfunc19:12:03

:thinking_face:

firstclassfunc19:12:23

That works Thanks!!!\

awesome 3
firstclassfunc19:12:03

I did put in a feature request for context sensitive displays, been looking at the inspector code may have some patches when I figure this out

djblue19:12:36

I responded, not sure where the better place is to have the conversation ๐Ÿ˜†

๐Ÿ‘ 3
borkdude14:01:23

Cool discussion. It might be worth documenting this somewhere?

๐Ÿ’ฏ 6