pry/pry — pull request #717 by lloeki (2012-09-25 12:21:58+00:00)
Title: Pry <#.*> coloring falls apart when it has multiple lines

Take e.g this return value, made of an Array containing Rule instances:

```
=> [#,
#,
#]
```

Pry will fail at coloring it consistently: the second and third objects will be colored in green, with `<#` and `>` delimiters in yellow, while the first object will have only its first line colored green, and the remainder with the default color. A single (and hence first) object outside an Array will show this behavior too, but this is less noticeable since it does not look so inconsistent.

The cause lies in this code in `lib/pry.rb`:

```ruby
# avoid colour-leak from CodeRay and any of the users' previous output
colorized = colorized.sub(/(\n*)$/, "\e[0m\\1") if Pry.color
````

As `$` matches the first end of line, this clears the color after the first *newline*. One should instead use `\Z` to match end of string, as such:

```ruby
colorized = colorized.sub(/(\n*)\Z/, "\e[0m\\1") if Pry.color
```

The colored output is then correct.