color-console 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +2 -0
- data/lib/console/console.rb +10 -3
- data/lib/console/platform/ansi.rb +8 -2
- data/lib/console/platform/windows.rb +7 -1
- data/lib/console/progress.rb +4 -2
- metadata +6 -8
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTI4ZDk2ZmRhYzFmZWRmODQ2ZTA2Mzg1Y2JmNTdhNWEzNzQwOTY4MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDkzNGM2NWI3NmVmZjU4YTYxZjI4MTA3MGJlOGYxNGFjY2MyNjgwYQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzBmNWIzNjFkYjA0YzcwZTU0NjFkZWU0MGIyZTY0OGYwMjQxNzMzNWIwOWQy
|
10
|
+
Y2YxODcxYzNhZWZkMDI5NDczOWZlMGZiYmM2ZjFiNWQ0OTZiOTU4ZWUyNTVl
|
11
|
+
YTlkNGQ2YzMzZmZhNTgwODMxN2UxMmM3ZDMxYTQ0YzE1MWJmMDM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2IxNTFlZDQ4YjRlNDUzZTA1NDU5NWJhODBjZjU4YTJjOWM3MjdiNWY4YTlh
|
14
|
+
ZmQ3NDQyZTdlZTU5NzVkYzJmMTljODFlYTViY2YyYjQzYjgwZTc1NTVjZDRj
|
15
|
+
Y2ZhODU3MGUwY2JmOGVjMzJkYjY5ZWNmYzA5NjVjMjRiMGNjOTg=
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
ColorConsole is a small cross-platform library for outputting text to the console.
|
4
4
|
|
5
|
+
On Windows, FFI is used to dynamically link to the Windows Console API functions, while on other platforms, ANSI escape sequences are used. As such, there are no dependencies and no libraries to install other than this gem.
|
6
|
+
|
5
7
|
|
6
8
|
## Usage
|
7
9
|
|
data/lib/console/console.rb
CHANGED
@@ -10,11 +10,18 @@ end
|
|
10
10
|
# provide color and progress-bar functionality.
|
11
11
|
module Console
|
12
12
|
|
13
|
-
attr_reader :status, :status_enabled
|
14
|
-
|
15
|
-
|
16
13
|
# Mutex used to ensure we don't intermingle output from multiple threads
|
17
14
|
@lock = Mutex.new
|
15
|
+
# Window size, if available
|
16
|
+
@window_size = nil
|
17
|
+
# Holds the current status content (if any)
|
18
|
+
@status = nil
|
19
|
+
# Foreground color for status content
|
20
|
+
@status_fg = nil
|
21
|
+
# Background color for status content
|
22
|
+
@status_bg = nil
|
23
|
+
# Whether status text is currently displayed
|
24
|
+
@status_displayed = false
|
18
25
|
|
19
26
|
|
20
27
|
# Returns the width of the console window
|
@@ -77,6 +77,10 @@ module Console
|
|
77
77
|
# @param fg [Symbol, String] An optional foreground colour name or ANSI code.
|
78
78
|
# @param bg [Symbol, String] An optional background color name or ANSI code.
|
79
79
|
def _write(text, fg = nil, bg = nil)
|
80
|
+
if @status_displayed
|
81
|
+
_clear_line((@status.length / self.width) + 1)
|
82
|
+
@status_displayed = false
|
83
|
+
end
|
80
84
|
if fg || bg
|
81
85
|
reset = true
|
82
86
|
if fg
|
@@ -105,13 +109,15 @@ module Console
|
|
105
109
|
# @param fg [Symbol, String] An optional foreground colour name or ANSI code.
|
106
110
|
# @param bg [Symbol, String] An optional background color name or ANSI code.
|
107
111
|
def _puts(text = nil, fg = nil, bg = nil)
|
108
|
-
if @
|
109
|
-
_clear_line
|
112
|
+
if @status_displayed
|
113
|
+
_clear_line((@status.length / self.width) + 1)
|
114
|
+
@status_displayed = false
|
110
115
|
end
|
111
116
|
_write("#{text}", fg, bg)
|
112
117
|
STDOUT.write "\n"
|
113
118
|
if @status
|
114
119
|
_write @status, @status_fg, @status_bg
|
120
|
+
@status_displayed = true
|
115
121
|
end
|
116
122
|
end
|
117
123
|
module_function :_puts
|
@@ -184,6 +184,10 @@ module Console
|
|
184
184
|
# @param fg [Symbol, Integer] An optional foreground colour name or value.
|
185
185
|
# @param bg [Symbol, Integer] An optional background color name or value.
|
186
186
|
def _write(text, fg = nil, bg = nil)
|
187
|
+
if @status_displayed
|
188
|
+
_clear_line (@status.length / self.width) + 1
|
189
|
+
@status_displayed = false
|
190
|
+
end
|
187
191
|
if fg || bg
|
188
192
|
reset = @reset_colors
|
189
193
|
if fg
|
@@ -221,12 +225,14 @@ module Console
|
|
221
225
|
# @param fg [Symbol, Integer] An optional foreground colour name or value.
|
222
226
|
# @param bg [Symbol, Integer] An optional background color name or value.
|
223
227
|
def _puts(text = nil, fg = nil, bg = nil)
|
224
|
-
if @
|
228
|
+
if @status_displayed
|
225
229
|
_clear_line (@status.length / self.width) + 1
|
230
|
+
@status_displayed = false
|
226
231
|
end
|
227
232
|
_write("#{text}\r\n", fg, bg)
|
228
233
|
if @status
|
229
234
|
_write(@status, @status_fg, @status_bg)
|
235
|
+
@status_displayed = true
|
230
236
|
end
|
231
237
|
end
|
232
238
|
module_function :_puts
|
data/lib/console/progress.rb
CHANGED
@@ -13,9 +13,10 @@ module Console
|
|
13
13
|
def status(msg, opts = {})
|
14
14
|
if self.width
|
15
15
|
@lock.synchronize do
|
16
|
-
if @
|
16
|
+
if @status_displayed
|
17
17
|
# Clear existing status
|
18
|
-
_clear_line
|
18
|
+
_clear_line((@status.length / self.width) + 1)
|
19
|
+
@status_displayed = false
|
19
20
|
end
|
20
21
|
@completed = nil
|
21
22
|
@status = msg
|
@@ -23,6 +24,7 @@ module Console
|
|
23
24
|
@status_fg = opts.fetch(:text_color, opts.fetch(:color, :cyan))
|
24
25
|
@status_bg = opts[:background_color]
|
25
26
|
_write @status, @status_fg, @status_bg
|
27
|
+
@status_displayed = true
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color-console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.2'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Adam Gardiner
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: ! " ColorConsole supports cross-platform (ANSI and Windows) colored
|
15
14
|
text output to the console.\n It also provides useful methods for building
|
@@ -19,8 +18,8 @@ executables: []
|
|
19
18
|
extensions: []
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
|
-
- README.md
|
23
21
|
- LICENSE
|
22
|
+
- README.md
|
24
23
|
- lib/color-console.rb
|
25
24
|
- lib/color_console.rb
|
26
25
|
- lib/console/console.rb
|
@@ -30,27 +29,26 @@ files:
|
|
30
29
|
- lib/console/table.rb
|
31
30
|
homepage: https://github.com/agardiner/color-console
|
32
31
|
licenses: []
|
32
|
+
metadata: {}
|
33
33
|
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
37
37
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
38
|
requirements:
|
40
39
|
- - ! '>='
|
41
40
|
- !ruby/object:Gem::Version
|
42
41
|
version: '0'
|
43
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
43
|
requirements:
|
46
44
|
- - ! '>='
|
47
45
|
- !ruby/object:Gem::Version
|
48
46
|
version: '0'
|
49
47
|
requirements: []
|
50
48
|
rubyforge_project:
|
51
|
-
rubygems_version:
|
49
|
+
rubygems_version: 2.4.1
|
52
50
|
signing_key:
|
53
|
-
specification_version:
|
51
|
+
specification_version: 4
|
54
52
|
summary: ColorConsole is a cross-platform library for outputting colored text to the
|
55
53
|
console
|
56
54
|
test_files: []
|