README.md in backticks-1.0.0rc1 vs README.md in backticks-1.0.0rc2
- old
+ new
@@ -1,17 +1,16 @@
-# Introduction
+![Build Status](https://travis-ci.org/xeger/backticks.svg) [![Coverage Status](https://coveralls.io/repos/xeger/backticks/badge.svg?branch=master&service=github)](https://coveralls.io/github/xeger/backticks?branch=master) [![Docs](https://img.shields.io/badge/docs-rubydoc-blue.svg)](http://www.rubydoc.info/gems/backticks)
Backticks is a powerful, intuitive OOP wrapper for invoking command-line processes and
interacting with them.
-![Build Status](https://travis-ci.org/xeger/backticks.svg) [![Coverage Status](https://coveralls.io/repos/xeger/backticks/badge.svg?branch=master&service=github)](https://coveralls.io/github/xeger/backticks?branch=master)
-
"Powerful" comes from features that make Backticks especially well suited for time-sensitive
or record/playback applications:
- Uses [pseudoterminals](https://en.wikipedia.org/wiki/Pseudoterminal) for realtime stdout/stdin
- Captures input as well as output
- Separates stdout from stderr
+ - Allows realtime monitoring and transformation of input/output
"Intuitive" comes from a DSL that lets you provide command-line arguments as if they were
Ruby method arguments:
```
@@ -103,24 +102,27 @@
require 'io/console'
# In IRB, call raw! on same line as command; IRB prompt uses raw I/O
STDOUT.raw! ; Backticks::Runner.new(interactive:true).run('vi').join
```
+### Intercepting and Modifying I/O
+
You can use the `Command#tap` method to intercept I/O streams in real time,
with or without interactivity. To start the tap, pass a block to the method.
Your block should accept two parameters: a Symbol stream name (:stdin,
:stdout, :stderr) and a String with binary encoding that contains fresh
input or output.
The result of your block is used to decide what to do with the input/output:
-nil means "discard" and a modified string is captured in place of the original.
+nil means "discard," any String means "use this in place of the original input
+or output.""
-Try loading the README in an editor with all of the vowels scrambled. Scroll
+Try loading `README.md` in an editor with all of the vowels scrambled. Scroll
around and notice how words change when they leave and enter the screen!
```ruby
+vowels = 'aeiou'
STDOUT.raw! ; cmd = Backticks::Runner.new(interactive:true).run('vi', 'README.md') ; cmd.tap do |io, bytes|
- vowels = 'aeiou'
bytes.gsub!(/[#{vowels}]/) { vowels[rand(vowels.size)] } if io == :stdout
bytes
end ; cmd.join ; nil
```