README.md in tty-command-0.8.2 vs README.md in tty-command-0.9.0
- old
+ new
@@ -1,5 +1,9 @@
+<div align="center">
+ <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://cdn.rawgit.com/piotrmurach/tty/master/images/tty.png" alt="tty logo" /></a>
+</div>
+
# TTY::Command [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
[![Gem Version](https://badge.fury.io/rb/tty-command.svg)][gem]
[![Build Status](https://secure.travis-ci.org/piotrmurach/tty-command.svg?branch=master)][travis]
[![Build status](https://ci.appveyor.com/api/projects/status/0150ync7bdkfhmsv?svg=true)][appveyor]
@@ -188,10 +192,12 @@
```ruby
cmd = TTY::Command.new(color: true)
```
+If the default printers don't meet your needs you can always create [a custom printer](#34-custom-printer)
+
#### 2.3.1 Color
When using printers you can switch off coloring by using `:color` option set to `false`.
#### 2.3.2 UUID
@@ -326,11 +332,11 @@
cmd.run(:echo, 'hello', env: {foo: 'bar', baz: nil})
```
### 3.2 Options
-When a hash is given in the last argument (options), it allows to specify a current directory, umask, user, group and and zero or more fd redirects for the child process.
+When a hash is given in the last argument (options), it allows to specify a current directory, umask, user, group and zero or more fd redirects for the child process.
#### 3.2.1 Redirection
There are few ways you can redirect commands output.
@@ -413,11 +419,11 @@
cmd.run("my_cli_program", "login", in: in_stream).out
```
#### 3.2.3 Timeout
-You can timeout command execuation by providing the `:timeout` option in seconds:
+You can timeout command execution by providing the `:timeout` option in seconds:
```ruby
cmd.run("while test 1; sleep 1; done", timeout: 5)
```
@@ -443,11 +449,11 @@
cmd = TTY::Command.new(binmode: true)
```
#### 3.2.5 Signal
-You can specify process termination signal other than the defaut `SIGTERM`:
+You can specify process termination signal other than the default `SIGTERM`:
```ruby
cmd.run("whilte test1; sleep1; done", timeout: 5, signal: :KILL)
```
@@ -481,11 +487,11 @@
```ruby
cmd.run("git log", pty: true) # => uses pager and waits for user input (never returns)
```
-In addition, when pty device is used, any input to command may be echoed to the standard output, as well as some redirets may not work.
+In addition, when pty device is used, any input to command may be echoed to the standard output, as well as some redirects may not work.
#### 3.2.7 Current directory
To change directory in which the command is run pass the `:chdir` option:
@@ -593,26 +599,28 @@
cmd.run(:ls, '-1').each("\t") { ... }
```
### 3.4 Custom printer
-If the built-in printers do not meet your requirements you can create your own. At the very minimum you need to specify the `write` method that will be called during the lifecycle of command execution. The `write` accepts two arguments, first the currently run command instance and second the message to be printed:
+If the built-in printers do not meet your requirements you can create your own. A printer is a regular Ruby class that can be registered through `:printer` option to receive notifications about received command data.
+As the command runs the custom printer will be notified when the command starts, when data is printed to stdout, when data is printed to stderr and when the command exits.
+
+Please see [lib/tty/command/printers/abstract.rb](https://github.com/piotrmurach/tty-command/blob/master/lib/tty/command/printers/abstract.rb) for a full set of methods that you can override.
+
+At the very minimum you need to specify the `write` method that will be called during the lifecycle of command execution. The `write` accepts two arguments, first the currently run command instance and second the message to be printed:
+
```ruby
CustomPrinter < TTY::Command::Printers::Abstract
def write(cmd, message)
- puts message
+ puts cmd.to_command + message
end
end
-printer = CustomPrinter
-
-cmd = TTY::Command.new(printer: printer)
+cmd = TTY::Command.new(printer: CustomPrinter)
```
-Please see [lib/tty/command/printers/abstract.rb](https://github.com/piotrmurach/tty-command/blob/master/lib/tty/command/printers/abstract.rb) for a full set of methods that you can override.
-
## 4. Example
Here's a slightly more elaborate example to illustrate how tty-command can improve on plain old shell scripts. This example installs a new version of Ruby on an Ubuntu machine.
```ruby
@@ -648,6 +656,6 @@
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
## Copyright
-Copyright (c) 2016-2018 Piotr Murach. See LICENSE for further details.
+Copyright (c) 2016 Piotr Murach. See LICENSE for further details.