Sophrinix / TryRuby

Try Ruby is a interactive shell that quickly and whimsically teaches the Ruby programming language. Originally _why's idea, it has been recreated from the ground up by Rubyists who have a passion for Ruby and for teaching their fellow (wo)man how to program.
tryruby.org
345 stars 80 forks source link

Make it work on my iPhone ;-) #27

Open chrisjacob opened 14 years ago

chrisjacob commented 14 years ago

Not sure if it's possible, but I would love to be able to use this on my iphone - in safari. Naturally the terminal is a DIV (#terminal). Which of course does not bring up the keypad on the iphone when I click on it.

There must be something nifty you can do to force the keypad to open up and allow input... ;-)

Keep me posted!

ghost commented 14 years ago

There is. But until then, you use your iphone to go to http://tryruby.sophrinix.com/irb.cgi?cmd=dsfsdgdfsg where "dsfsdgdfsg" is what you what you would type in. It will remember your command history if you have cookies enabled.

Sophrinix commented 14 years ago

I have been working on this issue for some time.

The problem is I need a mobile safari analog to this.observeKeyboard.

I need some javascript that allows me to trigger activate keyboard and respond to observe Keyboard.

If you can figure out how to make that happen, I'll put it in there

Sophrinix commented 14 years ago

a good litmus test for iphone support is the keypress_test.html file.

If you can figure out how to make iphone respond to that file, then let me know.

This is an issue I will keep working on, but I am more focused on implementing fakefs and new lessons.

chrisjacob commented 14 years ago

It's nice to know that this is on your mind. If I get some spare time I will certainly take a look at figuring out a solution. Thanks for the pointers to files / functions I can start on. Wish me luck! ;-)

Sophrinix commented 14 years ago

If you can figure this out, it would be huge. I would immediately make sure that you get the credit for figuring this out and roll it into its own .js library.

This is an issue to date that no one has been able to figure out.

mobileInput.js (has a nice ring to it)

Sophrinix commented 14 years ago

a radically simpler approach may be to pull the textbox out to somewhere that it is visible.

This at least lets you enter stuff into try ruby. The problem now becomes how to deliver a carriage return (aka return or enter)

This proof of concept shows that this is possible to do.

I might end up going with the idea of just writing a try ruby client for iPhone and call it a day.

chrisjacob commented 14 years ago

I'm thinking that the iphone keyboard is not the best option for "code" input. Need a "coding keypad". I'm thinking of building a Javascript solution. jQTouch for it's Fast Tap feature (http://blog.jqtouch.com/post/205113875/milliseconds-responsiveness-and-the-fast-tap). Landscape mode for Keyboard Input. Portrait mode for code "viewing". Various Keyboards optimised for code input. (Even pre-defined templates like "" for HTML.

Basically need to figure out how I can fake the key input - only done some quick google but this might start the ball rolling - http://stackoverflow.com/questions/832059/definitive-way-to-trigger-keypress-events-with-jquery

I'll let you know once I've had a play around... want to do some sketches of various keyboard layouts too.

;-)

chrisjacob commented 14 years ago

The following simulates a keypress, which is picked up by the div#terminal. Tested in firebug, FF3.5.

var event = jQuery.Event("keypress"); event.keyCode = 65; $(document).trigger(event);

// 65 outputs "A" // 13 outputs "Enter"

Now to build the keyboard ;-)

Sophrinix commented 14 years ago

The real trick is going to be getting the iphone keyboard to activate. Also, those keycodes differ by browser.

chrisjacob commented 14 years ago

I'm thinking of by-passing the iPhone keyboard all together... It's not really optimised for coding. Basically create a web based iPhone Keyboard, which triggers these keypress events.

Sophrinix commented 14 years ago

that's not a bad idea. If your going to do that then is this going to be web based, or is this going to be a iphone application. If so, then I'll consider uploading my attempt at making a try ruby iphone app. Long term I plan on adding new functionality to try ruby.

chrisjacob commented 14 years ago

Web based. Using jQTouch as the foundation. Do you have an iPhone / iPodTouch? I recently worked on http://i.woolworths.com.au/ which used jQTouch + custom 'hack's to get the job done.

Sophrinix commented 14 years ago

Yes. I am also an app developer.

I have been learning rhomobile though as of late. It allows me to write mobile apps in ruby.

chrisjacob commented 14 years ago

Ah cool. rhomobile looks interesting too!

I'm thinking of cheating if I want to go native... http://phonegap.com/ screenscast http://www.youtube.com/watch?v=LcES5nIbMkk

chrisjacob commented 14 years ago

Very early mashup/prototype/proof-of-concept... what ever you want to call it, it's hacky, it's buggy, but it's some what functional ;-)

http://multimedia123.com/iide/public/

To-Do:

  1. Use jQtouch 'fast tap' to speed up touch response times on "keypress"
  2. Build keyboard that mimics native iPhone keyboard look and feel
  3. Build customised keyboard(s) tailored to Code input (i.e. user needs access to "+" key and "[" "]" keys etc more regularly... native keypad is not friendly for this).
  4. Tidy up the styling
  5. Do heaps heaps more...
  6. Crack open a beer and celebrate ;-)

Let me know what you think!

Sophrinix commented 14 years ago

this is very promising! I'll dig into the details tomorrow. I have been busy porting the sandbox to ruby 1.9 so the file stuff will finally work.

Sophrinix commented 14 years ago

This actually opens up a whole additional world of possibilities. keep up the good work.

Is it correct to assume that all your changes have been javascript only?

That is to say you have only modified the index.html file and maybe some javascript associated with index, and not touched any ruby or cgi files.

chrisjacob commented 14 years ago

Correct, just html, css, js. I'm going to try and build a plugin for jQtouch, that lets you build your own web-based iPhone Keyboard(s). Obviously first step is to emulate the native iPhone Keyboard, then start working on ways of letting people customise this. Might seperate it from jQTouch if it gets popular - but for now I think that's a good 'community' in which to develop this project.

To access the CGI I'm using a proxy to get the results. The rest of your files pretty much stand up on their own with a few adjustments (files paths etc). The keyboard I've taken from http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/ which is good enough for the proof-of-concept. I make some tweeks to the keyboard to send out Keypress events, which in turn your irb js picks up... all came together pretty smoothly after some trial and error ;-)

Project I'm now thinking of:

pocket irb - iphone webapp that emulates irb using your existing work with Try Ruby and my keyboard... potential to convert this into native app using "phone gap" and sell it on iTunes - I know I would pay $2 for it ;-)

try ruby - on your iphone!

iIDE - a simple IDE on your iphone...

Other services... thinking about how pastie.org could use the keyboard, thier code highlighting is brilliant, thinking how that could be integrated back into iIDE...

Anyway all pipe dreams right now, first step is to get the keyboard working ;-)

I'll keep you posted!

chrisjacob commented 14 years ago

Set myself up a nice little area to start building the HTML/CSS for the keyboard.

http://multimedia123.com/iide/webik/

Development name for this project is WebIK (Web Based iPhone Keyboard)... simple enough ;-)

Better get back to doing some PAID work :-P

chrisjacob commented 14 years ago

More progress... got base QWERTY keys layed out - looks good in all modern browsers + Mobile Safari. :-) http://multimedia123.com/iide/webik/

chrisjacob commented 14 years ago

More progress... http://multimedia123.com/iide/webik/

Need to add in profile orientation, key backgrounds. But for now you get the idea ;-)

Going to give keys an a:active state (well actually faking this coz iphone does not trigger a:active). This state will have the keys change to the reverse colour i.e. light goes dark, dark goes light... as on iphone when you click on the Backspace Key.

Also going to work on adding a 'sticky key' style and functionality. This will have the keys turn blue (like when you enable 'Capslock' on the Shift key on iphone). This will cause the key to trigger the keypress event every 200 milliseconds (or something like that). So instead of needing to click Backspace 20 times you enable sticky key and it will continue to trigger the event.

Thinking of having two sticky key 'enablers'. 1 - a key you manually click first, then the next key you press becomes sticky. 2 - if you click the same key 3 times, then sticky key gets automatically enabled.

Can't wait to integrating into jQTouch and get TryRuby working on my iPhone (or at least irb.cgi for some IRB fun) ... I'll keep ya posted ;-)

Sophrinix commented 14 years ago

thanks.

is there a current git repo for this?

If not then do you mind if I launch one?

chrisjacob commented 14 years ago

I haven't ever put a project up on git. I think I will set one up myself, just so I can learn how it's all done ;-) ... Then I can keep this conversation going over there, and stop spamming your project :-P. I will post the link when available.

chrisjacob commented 14 years ago

Ok WebIK now has it's own official GitHub repo :-) http://github.com/chrisjacob/webik

p.s. Git and GitHub are AWESOME. I've been living in SVN land for TOO long.

Sophrinix commented 14 years ago

yep..

hey fyi, I am moving sophrinix.com and thus tryruby.sophrinix.com over to amazon ec2 . dns might take a while to resolve, so if try ruby is in accessible thats why. I've put an announcement on the site and on my twitter.

ghost commented 14 years ago

I can't javascript very well, and I don't have an iphone, but could putting this right before </body> trigger the Iphone keyboard and let you type stuff?

Sophrinix commented 14 years ago

i have an iphone. I'll look at this in the morning.

I have been busy with migrating off my dedicated box and moving entirely into the cloud.

there have been some difficulties with my domain name and the registrar it is with, but these appear to be solved problems that take time.

Sophrinix commented 14 years ago

That is on to the right track. I wonder what ever happened to the guy working on the iphone javascript keyboard.

The real solution is to just build an iphone version that uses tryruby. I'll commit to doing this after another 10 major things are accomplished first.

chrisjacob commented 14 years ago

Hi ya, yeah I pretty much feel off the face of the earth... I'm still interested in developing the project further - particularly with more and more touch screen devices coming out (e.g. ipad). I just got swamped with work. Also trying to dig into learning Rails and move my career down that path. Probably just like you - time is the biggest issue here.

Actually I've got a lot of enthusiasm right now to start my own business that operates on a 40% Client Work, 20% Learning, 40% Personal Projects basis... 37 Signals new book REWORK fuels my fire ;-)

Sophrinix commented 14 years ago

good to see your still around. Yeah I can relate to no time.

I am making time right now to catch up all on all the ideas I have had about try ruby for some time. i am working on launching a startup and a non profit.

chrisjacob commented 14 years ago

Busy bee indeed ;-) I work as a Freelance Web Developer in Australia.... what's your day job? p.s. chrisjacob.work[at]hotmail.com if you're ever on MSN ;-)

cparen commented 14 years ago

... not sure if this helps, but i noticed yesterday that TryHaskell.org works great on the iPad, but TryRuby.org fails to bring up the keyboard. Perhaps you could use their code if the license is compatible.

chrisjacob commented 14 years ago

Great suggestion aaronia

Sophrinix commented 14 years ago

ive looked into this, this biggest thing that i dont like about tryhaskell is that the previous command/up arrow fails to work. Also, the way lessons work is different between try haskell and try ruby.

Sophrinix commented 13 years ago

this will work when I switch to jquery console

pnhearer commented 13 years ago

ANy update on this? yes please maybe?

Sophrinix commented 13 years ago

its in the updates...friday...more later

Sophrinix commented 13 years ago

iOS (iPad, and iphone support coming very soon) see: http://twitter.com/#!/sophrinix/status/52811824835473408

danopia commented 13 years ago

This is not exactly related, but on Android platforms it would be nice for tryruby to show a message on load saying to hold down menu to activate the soft keyboard, and then it could fade out when the first keypress is detected.

Sophrinix commented 13 years ago

I am actually planning a mobile android app after I pushed the code I have already promised to push onto this repo.

JRuby works on android, so it will be fairly straight forward to do a JRuby + TryRuby = android native app in the marketplace. I'll note your comment. I only have the android sdk (no actual android devices except my humble nook)

danopia commented 13 years ago

Android devices work nicely, except arrow keys. I also have full out irb on my phone (and a code editor), powered by jruby. I was just saying to pop up a notice in case someone without a hard keyboard doesn't know how to show the soft one.

I was considering writing a simple mobile android app for you, but it would use the web api, not jruby. It would then show all the same help and stuff as the web site version.