yab | yet another Basic for HAIKU

Full Version: New on the FatElk repo
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Yab over the Shell Interface

Yoshi is used to allow a script to query the user for information. Yoshi displays information to the user and receives the input, then passes the information back to the script. Yoshi doesn't change your script into an interactive gui application. Each query window is closed when the information is returned and the script must open a new window to continue to interact with the user.

This is an example of the power iof yab.


I'm experimenting with Yoshi ATM and I don't seem able to cut-n-paste a URL into a textfield. It probably has to do with the slashes. Regular text cuts and pastes fine - even if there are slashes in it.

What I'm trying to do here is replicate my app TinyTim (a front-end to tinyurl.com, described elsewhere on this forum) using Yoshi and having to type in a long URL sort of defeats the purpose!

I ran yoshitest.sh and got the same result there. Thou shalt not paste URLs!

Also, a request: could we have [enter] as a synonym for [return]?
One needs to make the textfield long enough to accomodate the url. In order not to have the Window grow too wide, use this:

tx.type = textfield
tx.label = Enter the URL:
tx.width = 200

Unless the url is longer than 200 characters, this should work.

If one adds

tx.single = true

The whole textfield is displayed, making an extreemly wide window.

[enter] or [return] is doable.
Thanks, I'll experiment with that

I should have mentioned: [return] is more computer-science canonical, but [enter] is what is actually printed on my keyboard. It will just make things a little easier.

see https://github.com/bbjimmy/Yoshi/commit/...d5a5f16b93

Thanks for the feedback!

Remember this is alpha software, If you find my textfield handeling is not usable, let me know how you think it should work.
OK, report back. I did this as an exercise to rewrite my 150-line yab program Tiny Tim. It's a quick and dirty attempt, just to gain some experience with Yoshi.

#set up the window
*.title = TinierTim
*.x = 200
*.y = 200

txt.type = text
txt.default = Please enter a long URL to send to TinyURL.com[return](You can paste it in with a right-click).
txt.lines = 3

tx.type = textfield
tx.label = URL:
tx.mandatory = true
tx.align = left
tx.width = 500
#if your url is more than 500 characters I can't help you ...

#add cancel button
cb.type = cancelbutton
cb.label = Cancel

#change defaultbutton
db.type = defaultbutton
db.label = Submit

#!/bin/env sh

## who am i? ##
_script="$(readlink -f ${BASH_SOURCE[0]})"
_base="$(dirname $_script)"
cd $_base

tmpfile=`finddir B_COMMON_TEMP_DIRECTORY`/tiniertim.out
yoshi ./tiniertim.yoshi>$tmpfile
#we only need the first line for this one so no need for   while IFS ...
read response < $tmpfile

if test $response = "cancel=1"; then echo "Exiting";exit 1; fi

url=`echo $response|cut -d = -f 2`
shorturl=`curl http://tinyurl.com/api-create.php?url=$url`

#requires the clipboard utility, available on my repo
#put this in the requires section of the .PackageInfo
clipboard --copy=$shorturl
alert --info "The shortened URL $shorturl has been put in your clipboard"
rm -f $tmpfile

[Image: tiniertim.png]

48 lines vs 150. This does not do everything TinyTim does. For example, monitoring the clipboard and error-checking that input really is a URL. Can be done, but string splitting in bash is just too painful for a Wednesday night ;-) In any case, that would make the difference smaller.

But what interest me more than just the line count is that the UI has been split off from the code. I could decide tomorrow that my app would be better if written in python, perl or even yab (!) and do that. The user would never even know. I can see myself developing a whole collection of standard yoshi scripts for things like installation wizards. No one is ever going to write an office suite in Yoshi, but for developing quick front-ends to CLI commands, this is fantastic.

Respect, Jim. I think this is a VIP (Very Important Program). I hope you'll accept input on this thread mainly as showing what problems a Yoshi newbie encounters and consider how that could affect the documentation.

No, scratch that. I think Yoshi deserves its own Forum section.
I just added a .textfile option to the text type.

txt.type = text
txt.default =
txt.txtfile = /boot/home/config/settings/fatelk/yoshi/commands/text
txt.lines = 5
txt.scrollbar = 4
txt.align = center
txt.tooltip = Ckick and press the down arrow key to see the full text.

this can input text like this from /boot/home/config/settings/fatelk/yoshi/commands/text:

Paragraph one, demo text

Paragraph two  If you like, you can use a really long label  as the window will scale accordingly.

This will not display until the text is scrolled.

No need for [return] or [enter], but it does require another file.
OK, I think I can claim to have the first app on an actual repository that uses Yoshi (apart from Yoshi itself, of course)

I ported this little Java IDE called Judo that comes in 6 interface languages, depending on the contents of a configuration file in the same directory. This meant that I had to make six different packages. Now, it has become a single package (judo_j) with a selection menu, courtesy of yoshi.

First, I relocated the configuration file to /boot/home/config/settings with a post-install script and a symlink.

Next I created six configuration files named, I kid you not, "radio=option1" to "radio=option6".

Now here comes the hard part. I don't know for a fact that the user subscribes to the FatElk repo, so if I make it a requirement I will end up with users unable to install the app. I could parse the output of pkgman list-repos, but really ... the app is not that important to me.

So the script searches for yoshi. If yoshi is not found, it defaults to an English interface. If it is found, the user is confronted with:

[Image: judo-yoshi.png]

Here's the code:

#set up the window
*.title JUDO
*.look = bordered

txt.type = text
txt.default = LANGUAGE SELECTION[return]==============
txt.lines = 3
txt.align = center

radio.type = radiobutton
radio.label = Please select the interface language for JUDO.
radio.option1 = Bahasa Indonesia
radio.option2 = English
radio.option3 = Español
radio.option4 = Français
radio.option5 = Italiano
radio.option6 = Slovenščina
radio.default = option2
radio.tooltip = Please make your selection.


## who am i? ##
_script="$(readlink -f ${BASH_SOURCE[0]})"
## Delete last component from $_script ##
_base="$(dirname $_script)"
cd $_base

tmpfile=`finddir B_COMMON_TEMP_DIRECTORY`/JUDO.out
runyoshi=`which yoshi`

if test -z $runyoshi; then
    cat 'radio=option2'>$settingsfile
    java -cp . org.judo.JUDOIDE &
    exit 0

$runyoshi ./judo.yoshi>$tmpfile

#we only need the first line for this one so no need for   while IFS ...
read response < $tmpfile

if test $response = "cancel=1"; then echo "Exiting";exit 1; fi

cat $response>$settingsfile

java -cp . org.judo.JUDOIDE &
exit 0

Naturally, I inform the user in the .PackageInfo that to get the additional languages, install yoshi from the FatElk repo. I considered asking Jim if I could host a copy of Joshi, but then we end up with different versions on different repos and I think that is a bad idea.

The next version of Judo may have an alert in the post-install script telling the user to install Yoshi.
Latest update 0.2.0 gives error "Signature in rsrc doesn't match constructor arg. (application/x-vnd.yab-app, application/x-vnd.yoshi-app)" which is interfering with yoshi output.
(04-23-2016, 06:48 PM)clasqm Wrote: [ -> ]Latest update 0.2.0 gives error "Signature in rsrc doesn't match constructor arg. (application/x-vnd.yab-app, application/x-vnd.yoshi-app)" which is interfering with yoshi output.

Fixed in... http://fatelk.com/repo/packages/yoshi-0...._gcc2.hpkg

Late night packaging. Sad
Free Web Hosting