Skip to content

Commit

Permalink
Merge b176926 into 7858775
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 26, 2020
2 parents 7858775 + b176926 commit 2f62f2b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -302,6 +302,14 @@ Optionally you can provide timeout:
spinner.join(0.5)
```

### 2.9 tty?

The spinner will not write any output if the output stream is not a TTY. You can check this with:

```ruby
spinner.tty?
```

## 3. Configuration

There are number of configuration options that can be provided to customise the behaviour of a spinner.
Expand Down
18 changes: 9 additions & 9 deletions lib/tty/spinner.rb
Expand Up @@ -474,6 +474,15 @@ def update(tokens)
end
end

# Check if IO is attached to a terminal
#
# return [Boolean]
#
# @api public
def tty?
output.respond_to?(:tty?) && output.tty?
end

private

# Execute a block on the proper terminal line if the spinner is running
Expand Down Expand Up @@ -518,15 +527,6 @@ def write(data, clear_first = false)
end
end

# Check if IO is attached to a terminal
#
# return [Boolean]
#
# @api public
def tty?
output.respond_to?(:tty?) && output.tty?
end

# Emit callback
#
# @api private
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/tty_spec.rb
@@ -0,0 +1,8 @@
# frozen_string_literal: true

RSpec.describe TTY::Spinner, "#tty?" do
it "responds to tty?" do
spinner = TTY::Spinner.new
expect(spinner).to respond_to(:tty?)
end
end

0 comments on commit 2f62f2b

Please sign in to comment.