colsole 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/colsole.rb +15 -5
- data/lib/colsole/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d285ac4d67fbeaa6676fe130895efbac0160695e
|
4
|
+
data.tar.gz: 5e101f46180a42111b597aaab400b6dd96ea3b70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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|
|
data/lib/colsole/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: runfile
|