retroforth/example/Paste_to_Sprunge.forth
crc 7195099cfe Add Paste to Sprunge example
FossilOrigin-Name: e8a6fc3064ad8519b731cca3cbae649117441f54e985423af58e66347f094c69
2019-01-19 16:42:24 +00:00

42 lines
866 B
Forth

# Paste to Sprunge
sprunge.us is a command line pastebin services. It's
normally used like:
<command> | curl -F 'sprunge=<-' http://sprunge.us
This is a wrapper for sharing snippits from within
RETRO.
## The Code
~~~
{{
:write '/tmp/rx.paste file:spew ;
:curl 'curl_-s_-F_'sprunge=</tmp/rx.paste'_http://sprunge.us ;
:pipe{ curl file:R unix:popen ;
:get here [ #100 [ dup file:read , ] times ] dip ;
:result s:chop s:temp ;
:} swap unix:pclose '/tmp/rx.paste file:delete ;
---reveal---
:,paste (s-s)
&Heap [ write pipe{ get result } ] v:preserve ;
}}
~~~
## Test Case
```
{{
:capture{ &buffer:add &c:put set-hook ;
:} &c:put unhook ;
---reveal---
:capture-output (qa-)
[ buffer:set capture{ call } ] buffer:preserve ;
}}
'Out d:create #128000 allot
[ d:words ] Out capture-output
Out ,paste s:put nl
```