On 21.12.2007, at 20:18, Thomas Aylott - subtleGradient wrote:
On Dec 21, 2007, at 8:39 AM, Hans-Jörg Bibiko wrote:
after fixing to run R inside of TM as interactive shell I tried to run irb and it also works. But one 'only' has to change the communication between irb and TM slightly. Is someone interested to do that? ;)
DO WHAT?!!!!1! :O Please don't tease us here. You can run IRB interactively from within TextMate? How? What do we need to do to make that work?
Give me a moment. I will try to modify a bit in order to show something basic.
Hi, here comes at least a screencast of an IRBdaemon. To be honest, I've never used all of irb's possibilities but the basics seem to work.
http://www.bibiko.de/irbdaemon.mov (600kB)
My general approach – in very short terms:
If I have an application which runs in a normal Terminal without any graphical environment (including such as Midnight Commander, vi, etc.) **AND** I can find a definable return pattern coming from that application then I can do the following.
Example for R but it's also applicable in modified form to irb, etc.
If I run R in a Terminal I will have a prompt '> ', I can type a command '2+3', press RETURN, and R writes into that Terminal '[1] 5\n> '. Fine. Now I run R in a pseudo terminal (meaning a terminal which is hidden for the user) using Ruby's lib 'pty' (a spawned process). The output of that pseudo terminal will be written into ~/Rdaemon/ r_out (together with stderr). Then I created in beforehand a named pipe on ~/Rdaemon/r_in. Into that pipe I send all commands coming from TM or elsewhere.
Here the daemon as simplified version:
cmd = "R 2&> ~/Rdaemon/r_out" PTY.spawn(cmd) { |r,w,pid| # write r into the nirvana Thread.new {r.read} fin = File.open('~/Rdaemon/r_in', "r+") while TRUE #wait for a new task and send it to R task = fin.gets w.puts task end }
That means the named pipe r_in is my keyboard and r_out is the terminal content
Before I send a command to r_in I look for the end of r_out. Then, after sending, the Rdaemon wrote something into r_out. I wait until R wrote at the end the pattern '> ' (synchronization). Then I only take the new piece of r_out and I insert it as snippet (fine-tuned for irb because irb has a changeable prompt). That's it. The daemon runs in a while TRUE loop. Caused by the line 'task = fin.gets' this process needs no cpu while waiting. If I send 'quit' to r_in it destroys itself.
--Hans