Arc Forumnew | comments | leaders | submitlogin
JQuery + wterm + arc = Ajaxified Arc Web Terminal
10 points by thaddeus 5527 days ago | 11 comments
I wanted a quick and easy means to talk to the arc server on my SheevaPlug (from the web).

Thought I'd share the fun. Not as fancy as conanites' Rainbow or palsecams' Evserv project, but it works :)

Steps:

  1. Download -> http://wterminal.appspot.com/downloads/wterm-0.0.3.tar.gz   (jQuery + plugin named wterm)
  2. Get these 3 files out (jquery.min.js, wterm.jquery.js, wterm.css); 
     Put them somewhere and make sure your arc server can serve them out.
  3. Make your service or HTML file and serve it from Arc.
     Result should look like so... (make sure file paths are correct):

 
  <html><head>
   <link rel="stylesheet" type="text/css" href="css/wterm.css">
   <title>Ajaxified Arc Terminal</title>
   <script type="text/javascript" src="js/jquery.min.js"></script>
   <script type="text/javascript" src="js/wterm.jquery.js"></script>
   <script type="text/javascript">
      $(document).ready(function (){
      $('#terminal').wterm({WIDTH: '100%', HEIGHT: '100%', WELCOME_MESSAGE: 'AJAX Terminal. To Begin Using type <strong>help</strong>'});
      $.register_command('arc',{PS1:'arc $',START_HOOK: function(){set_prompt;},DISPATCH:'arc-handler'});});
   </script>
   </head>
   <body style="margin:0; background-color: #000000;">
   <div id="terminal" style="font-size: 1.3em; margin:10px; overflow:hidden;"></div>
   </body></html>


  4. Create and load an arc handler service:

    (defop arc-handler req
       (withs (exps (arg req "tokens") 	
               return (on-err [prn "Error: " (details _)]
	                     (fn () (eval (list 'eval (list 'quote (read exps)))))))
       (write return)))


  5. In your browser, go to your service or html file from step 3 and you 
     should see a prompt. Type "arc" to start arc mode. 
     Type "exit" to get back to the mainline. 
     "clear" works on the mainline. 
Notes:

  If you want to send commands to the underlying server 
  just use (system "whatever") or (read (pipe-from "whatever")).

  You could easily add python or ruby or other services 
  then use wterm as the gateway to each.
T.


2 points by palsecam 5526 days ago | link

Very cool, thanks for sharing.

I didn't know about wterm. I suppose I wrote "an informally-specified, bug-ridden, slow implementation of half of it" for the evsrv front-end :-) I'll go check it out.

I suppose you know about it, but prompt.arc, shipped with Arc, is also something similar to your Arc Web terminal or my evsrv. But it's not Ajaxified.

Do you have any screenshot of your terminal to share? I'd be glad to see what it looks like.

(eval (list 'eval (list 'quote (read exps))) The double-eval is because of macros, right? I remember I did something similar in the first version of the evsrv. Also, does your solution handle multiple expressions? I mean, what happens if "tokens" is, for instance "(+ 2 3) (+ 4 4) (prn "something")"? And, does it handle 'prn well, i.e: writing to stdout, or does it only give the result of evaluation?

Don't hesitate to ask for any help concerning your terminal. I have a bit of experience on the question with evsrv, I'd be glad to help you.

-----

2 points by thaddeus 5526 days ago | link

You can see the wterm demo here:

http://wterminal.appspot.com/demo

  type 'help' to see what examples exist.
  'strrev' emulates switching modes.
As a note: I wasn't trying to build an IDE using wterm, rather I just wanted to be able to push out changes, have a means to look at data. etc etc.

> "The double-eval is because of macros, right?"

um - eh-hem - yep - I think I got that idea from you :)

> "Also, does your solution handle multiple expressions?"

hmmm... I hadn't actually tried that until you mentioned it here - no it doesn't, but I think that's a matter of defining the arc-handler to do so. wterm just takes what ever I type and submits all of it as a string then returns the response. I should look into that :)

> "And, does it handle 'prn well"

not really... in wterm everthing has to be typed on 1 line and everything returns on 1 line; example:

  AJAX Terminal. To Begin Using type help
  Terminal $ arc
  arc $ (= db (obj how "wterm" what "arc"))
  #hash((what . "arc") (how . "wterm"))
  arc $ (pr db)
  #hash((what . arc) (how . wterm))#hash((what . "arc") (how . "wterm"))
  arc $ (repeat 3 (prn " all on one line "))
  all on one line all on one line all on one line nil
  arc $ 
> "Don't hesitate to ask for any help concerning your terminal."

ok thanks! :). I am going to take another look at your Evserv code to see if I can figure out handling of mutliple expressions. I will let you know if I need help.

Right now I am just so happy being able to tinker with arc via my sheevaplug; which is totally awesome! (+ nothing to do with arc, but I just got twonkeymedia server up and distributing movies and music to my TV - haha I don't need to keep my computer on anymore!!! cheapest, 2 watt, mediaserver I have ever seen).

T.

-----

2 points by palsecam 5526 days ago | link

> You can see the wterm demo here:

Thanks for the link.

> ok thanks! :). I am going to take another look at your Evserv code to see if I can figure out handling of mutliple expressions. I will let you know if I need help.

Right now I am just so happy

Yes, I pointed this eventual issue just that you have some ideas for what to work on next / what problems may appear. But yeah, if it fits your needs in this current state, which is already very good, just enjoy!

Oh and all your sheevaplug / twonkeymedia server stuff seems rather cool!

-----

2 points by thaddeus 5526 days ago | link

> Oh and all your sheevaplug / twonkeymedia server stuff seems rather cool!

'kens' got me hooked on playing with the sheevaplug. I hope this guy keeps sharing the wealth. Now I just got to come up with a practical use for arc on it.

If anyone else is interested:

http://plugcomputer.org/plugwiki/index.php/Run_TwonkyMedia_o...

T.

-----

3 points by thaddeus 5527 days ago | link

Wterm was written by venkatakirshnan Ganesh.

The plugin link is:

http://plugins.jquery.com/project/wterm

-----

1 point by thaddeus 5517 days ago | link

Update:

I made 2 small changes to "wterm.jquery.js" that help:

1. Comment out line 151 (get's rid of the welcome message):

    // element.html( '' ).append( '<div>' + settings.WELCOME_MESSAGE + '</div>' );
2. Changed line 205 (use 'pre' tags instead of 'div' tags to handle "prn"):

   content.append( '<div><span>' + p + ' ' + cmd + '</span><pre>' + ( ( data ) ? data : '' ) + '</pre></div>' );

You can see a snapshot of results here:

http://www.blackstag.com/docs/example.jpg

This shows Nathan Smiths jquery web-browser desktop (http://sonspring.com/journal/jquery-desktop ) with an arc window I use to access my sheeva plug (notice 'prn' now works).

T.

-----

1 point by thaddeus 5516 days ago | link

at line 301 (allows 'clear' to work in REPL):

   } else if(cdispatch && key == 'clear' ) {
     content.html( '' );
     set_prompt(cprompt);
ok... and I'll stop now :)

-----

1 point by revorad 5524 days ago | link

Ok, now that I've gotten around to give this a serious try, I'm having trouble displaying anything. It seems arc has a problem using .js files because I tried doing something very basic with jquery and it didn't work. Even generating the following html as an arc op doesn't work, even though saving it as a plain html page works perfectly fine. Can anyone enlighten me please?

  <html>
  <head>
  <script type="text/JavaScript" src="jquery-1.3.2.min.js"></script>
  <script type="text/JavaScript">
  $(document).ready(function(){
   $("#generate").click(function(){
  alert('hello');
  });
  });
  </script>
  </head>
  <body>
  <div id="wrapper">
  <div id="quote">
  </p></div>
  <input type="submit" id="generate" value="Generate!">
  </div>
  </body>
  </html>

-----

4 points by fallintothis 5523 days ago | link

srv.arc isn't configured to serve static Javascript. You'll need to patch it:

  $ diff -u old-srv.arc new-srv.arc                           
  --- old-srv.arc      2009-08-04 11:51:09.000000000 -0700
  +++ new-srv.arc     2009-10-10 16:11:21.000000000 -0700        
  @@ -152,10 +152,11 @@                                      
   Connection: close"))                                      
                                                             
   (map (fn ((k v)) (= (type-header* k) (gen-type-header v)))
  -     '((gif       "image/gif")                            
  -       (jpg       "image/jpeg")                           
  -       (png       "image/png")                            
  -       (text/html "text/html; charset=utf-8")))           
  +     '((gif             "image/gif")                      
  +       (jpg             "image/jpeg")                     
  +       (png             "image/png")                      
  +       (text/html       "text/html; charset=utf-8")       
  +       (text/javascript "text/javascript")))              

   (= rdheader* "HTTP/1.0 302 Moved")

  @@ -242,6 +243,7 @@
              "htm"  'text/html
              "html" 'text/html
              "arc"  'text/html
  +           "js"   'text/javascript
              ))))

   (def respond-err (str msg . args)
Then it should work.

-----

3 points by revorad 5523 days ago | link

Ah thanks! I did try the second change but missed the first one. Finally, I can use js properly with arc. Joy to the world.

-----

3 points by revorad 5526 days ago | link

This is awesome. Thanks thaddeus.

-----