[TxMt] request user input example?

Ciarán Walsh ciawal at gmail.com
Wed Mar 21 09:07:25 UTC 2007


The following Perl code:

	print <STDIN>;

and the following Ruby code:

	puts gets

both show this behaviour. Just create a new document, set to the  
relevant language, paste in the code and press command-R to run it.

I'd be very surprised if there was a way to override STDIN behaviour  
in standard PHP, but if anyone finds one let me know. You could use a  
function such as this:

function read_input() {
     if (isset($_SERVER['TM_BUNDLE_SUPPORT'])) {
         list($button, $input) = explode("\n", `CocoaDialog inputbox  
--title "STDIN" \\
             --informative-text "Script is requesting input…" \\
             --button1 "Send"`);
         return $input;
     } else {
         return fgets(STDIN);
     }
}

to read input, which will use a dialog to request input when run with  
command-shift-R in TextMate, but will use standard STDIN otherwise.

Ciarán

On 21 Mar 2007, at 08:32, Timothy Bates wrote:

> hi there,
> I see in the change list that
>
> [NEW] Perl bundle: PerlMate will now request for user input when  
> reading from <STDIN> (Ciarán Walsh)
>
>
> This seems very handy: Does anyone have an example of a command  
> which does this? If it is not perl specific, are there examples of  
> syntax for other languages, like cmd line php?
>
> cheers,
> t
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate




More information about the textmate mailing list