9e03717deb
FossilOrigin-Name: 088675e452ed86a712563c8b2597fe4d47da59bdea0e40becdd1e028a84c47b0
23 lines
450 B
Forth
23 lines
450 B
Forth
# Capturing Output
|
|
|
|
By taking advantage of the hook in `c:put`, it's possible to
|
|
write a combinator to capture output to a user specified
|
|
buffer.
|
|
|
|
~~~
|
|
{{
|
|
:capture{ &buffer:add &c:put set-hook ;
|
|
:} &c:put unhook ;
|
|
---reveal---
|
|
:capture-output (qa-)
|
|
[ buffer:set capture{ call } ] buffer:preserve ;
|
|
}}
|
|
~~~
|
|
|
|
## A Test Case
|
|
|
|
```
|
|
'Output d:create #256 #1024 * n:inc allot
|
|
[ d:words ] &Output capture-output
|
|
Output s:length n:put nl
|
|
```
|