04-20-2016, 01:27 PM
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.
tiniertim.yoshi
tinertim.sh
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.
tiniertim.yoshi
Code:
#set up the window
*.title = TinierTim
*.x = 200
*.y = 200
#Text
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
#textfield
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
tinertim.sh
Code:
#!/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
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.