colsole 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7915e753b4e367195f53df50fc430e2d40cffba
4
- data.tar.gz: 70a32292b7d7cbc5432d5cf0882d77e76502ff4e
3
+ metadata.gz: d285ac4d67fbeaa6676fe130895efbac0160695e
4
+ data.tar.gz: 5e101f46180a42111b597aaab400b6dd96ea3b70
5
5
  SHA512:
6
- metadata.gz: 78437a93f891e3798ddd1dbaf5c29b94b6f73fe95b3560a49978b4ee5dc70e3d1e47fa5fbbc549e028469e5a34011959ea396cb6af55da4b88df623086904387
7
- data.tar.gz: 0ffb93928c7386adbdb25d1dec4a75d47a5b31e24a136ca16860840ecf45732727383a254769f433a8142646299049ae833e90612c22833d6cc08868d44cb900
6
+ metadata.gz: 3ca0c16b18a57744bbec547b015f2e8e2b32fa8f2cf8d9978d9045948b4592c5d4905e1fcbb0e0b9471a731de55b2cfada0379c7aeefdb1df0a05379950d3dc0
7
+ data.tar.gz: 1db4f19415cf09e114fd01d4193562eb0c6693373c52ecbfe1538d56e8846e58b020900463815f605d2491e7d3d5ec2b45a3c2d069a190e53fb3d988764e2b18
data/lib/colsole.rb CHANGED
@@ -30,7 +30,7 @@ module Colsole
30
30
  # Prints a color-flagged string to STDERR
31
31
  # Use color flags (like !txtred!) to change color in the string.
32
32
  def say!(text, force_color=false)
33
- $stderr.puts colorize(text, force_color)
33
+ $stderr.puts colorize(text, force_color, :stderr)
34
34
  end
35
35
 
36
36
  # Erase the current output line, and say a new string.
@@ -40,11 +40,21 @@ module Colsole
40
40
  say text, force_color
41
41
  end
42
42
 
43
- # Returns true if interactive terminal, false if piped.
44
- def terminal?
43
+ # Returns true if stdout/stderr is interactive terminal
44
+ def terminal?(stream=:stdout)
45
+ stream == :stdout ? out_terminal? : err_terminal?
46
+ end
47
+
48
+ # Returns true if stdout is interactive terminal
49
+ def out_terminal?
45
50
  STDOUT.tty?
46
51
  end
47
52
 
53
+ # Returns true if stderr is interactive terminal
54
+ def err_terminal?
55
+ STDERR.tty?
56
+ end
57
+
48
58
  # Determines if a shell command exists.
49
59
  def command_exist?(command)
50
60
  ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exist? File.join(d, command) }
@@ -76,7 +86,7 @@ module Colsole
76
86
  # Parses and returns a color-flagged string.
77
87
  # Respects pipe and auto terminates colored strings.
78
88
  # Call without text to see a list/demo of all available colors.
79
- def colorize(text=nil, force_color=false)
89
+ def colorize(text=nil, force_color=false, stream=:stdout)
80
90
  colors = prepare_colors
81
91
 
82
92
  if text.nil? # Demo
@@ -89,7 +99,7 @@ module Colsole
89
99
  end
90
100
 
91
101
  reset = colors['txtrst']
92
- if terminal? or force_color
102
+ if terminal?(stream) or force_color
93
103
  reset_called_last = true
94
104
 
95
105
  out = text.gsub(/\!([a-z]{6})\!/) do |m|
@@ -1,3 +1,3 @@
1
1
  module Colsole
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2015-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: runfile