colsole 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/colsole.rb +20 -19
- data/lib/colsole/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a430d377ca6b98614b6d3127bf1f35f2dc259b2bb4378bdc61570519d5126130
|
4
|
+
data.tar.gz: c2e890a8104283b070323f9916db75bc9ec692d81e49630159b2127b0b8d83f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bc5fc5638d1cb43b0a88d487686fd7afc918626446220b2874a419443bf2d4ac2dd24ac3711fe9f13a62fea07d80d0e1cea4a15d2da398b7f18ceba819fb401
|
7
|
+
data.tar.gz: 3232586c10d02fdc7fd4ca3adc517cae833c62440eeec552bf2e50bc23d1d5192718212cbc7bd6dcda7647c404c55b11ac7427b7972911a8062c9e722a2a21c5
|
data/README.md
CHANGED
@@ -2,9 +2,8 @@ Colsole
|
|
2
2
|
==================================================
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/colsole.svg)](https://badge.fury.io/rb/colsole)
|
5
|
-
[![Build Status](https://
|
5
|
+
[![Build Status](https://github.com/DannyBen/colsole/workflows/Test/badge.svg)](https://github.com/DannyBen/colsole/actions?query=workflow%3ATest)
|
6
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/0556015f7cd2080531a1/maintainability)](https://codeclimate.com/github/DannyBen/colsole/maintainability)
|
7
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/0556015f7cd2080531a1/test_coverage)](https://codeclimate.com/github/DannyBen/colsole/test_coverage)
|
8
7
|
|
9
8
|
---
|
10
9
|
|
data/lib/colsole.rb
CHANGED
@@ -21,7 +21,7 @@ module Colsole
|
|
21
21
|
# Prints a color-flagged string.
|
22
22
|
# Use color flags (like !txtred!) to change color in the string.
|
23
23
|
# Space terminated strings will leave the cursor at the same line.
|
24
|
-
def say(text, force_color=false)
|
24
|
+
def say(text, force_color = false)
|
25
25
|
last = text[-1, 1]
|
26
26
|
if terminal? and (last == ' ' or last == '\t')
|
27
27
|
print colorize(text, force_color)
|
@@ -32,13 +32,13 @@ module Colsole
|
|
32
32
|
|
33
33
|
# Prints a color-flagged string to STDERR
|
34
34
|
# Use color flags (like !txtred!) to change color in the string.
|
35
|
-
def say!(text, force_color=false)
|
35
|
+
def say!(text, force_color = false)
|
36
36
|
$stderr.puts colorize(text, force_color, :stderr)
|
37
37
|
end
|
38
38
|
|
39
39
|
# Erase the current output line, and say a new string.
|
40
40
|
# This should be used after a space terminated say().
|
41
|
-
def resay(text, force_color=false)
|
41
|
+
def resay(text, force_color = false)
|
42
42
|
text = "\033[2K\r#{text}" if terminal?
|
43
43
|
say text, force_color
|
44
44
|
end
|
@@ -47,13 +47,13 @@ module Colsole
|
|
47
47
|
# Status can be a symbol or a string. Color is optional, defaults to
|
48
48
|
# green (:txtgrn) when there is a message, and to blue (:txtblu) when
|
49
49
|
# there is only a status
|
50
|
-
def say_status(status, message=nil, color=nil)
|
50
|
+
def say_status(status, message = nil, color = nil)
|
51
51
|
color ||= (message ? :txtgrn : :txtblu)
|
52
52
|
say "!#{color}!#{status.to_s.rjust 12} !txtrst! #{message}".strip
|
53
53
|
end
|
54
54
|
|
55
55
|
# Returns true if stdout/stderr is interactive terminal
|
56
|
-
def terminal?(stream
|
56
|
+
def terminal?(stream = :stdout)
|
57
57
|
stream == :stdout ? out_terminal? : err_terminal?
|
58
58
|
end
|
59
59
|
|
@@ -76,7 +76,7 @@ module Colsole
|
|
76
76
|
|
77
77
|
# Returns [width, height] of terminal when detected, or a default
|
78
78
|
# value otherwise.
|
79
|
-
def detect_terminal_size(default=[80,30])
|
79
|
+
def detect_terminal_size(default = [80,30])
|
80
80
|
if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
|
81
81
|
result = [ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
|
82
82
|
elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exist?('tput')
|
@@ -98,7 +98,7 @@ module Colsole
|
|
98
98
|
# Converts a long string to be wrapped keeping words in tact.
|
99
99
|
# If the string starts with one or more spaces, they will be
|
100
100
|
# preserved in all subsequent lines (i.e., remain indented).
|
101
|
-
def word_wrap(text, length=nil)
|
101
|
+
def word_wrap(text, length = nil)
|
102
102
|
length ||= terminal_width
|
103
103
|
lead = text[/^\s*/]
|
104
104
|
text.strip!
|
@@ -116,13 +116,13 @@ module Colsole
|
|
116
116
|
# Parses and returns a color-flagged string.
|
117
117
|
# Respects pipe and auto terminates colored strings.
|
118
118
|
# Call without text to see a list/demo of all available colors.
|
119
|
-
def colorize(text=nil, force_color=false, stream
|
119
|
+
def colorize(text = nil, force_color = false, stream = :stdout)
|
120
120
|
return show_color_demo if text.nil?
|
121
121
|
return strip_color_markers(text) unless terminal?(stream) || force_color
|
122
122
|
colorize! text
|
123
123
|
end
|
124
124
|
|
125
|
-
|
125
|
+
private
|
126
126
|
|
127
127
|
def colors
|
128
128
|
@colors ||= prepare_colors
|
@@ -133,11 +133,11 @@ module Colsole
|
|
133
133
|
reset_called_last = true
|
134
134
|
|
135
135
|
out = text.gsub(/\!([a-z]{6})\!/) do |m|
|
136
|
-
reset_called_last = $1 == "txtrst"
|
137
|
-
colors[$1]
|
136
|
+
reset_called_last = $1 == "txtrst"
|
137
|
+
colors[$1]
|
138
138
|
end
|
139
139
|
|
140
|
-
reset_called_last or out = "#{out}#{reset}"
|
140
|
+
reset_called_last or out = "#{out}#{reset}"
|
141
141
|
out
|
142
142
|
end
|
143
143
|
|
@@ -145,9 +145,7 @@ module Colsole
|
|
145
145
|
# and values which are the escape codes for the colors.
|
146
146
|
def prepare_colors
|
147
147
|
esc = 27.chr
|
148
|
-
|
149
|
-
pattern_fg = "#{esc}[%{decor};%{fg}m"
|
150
|
-
pattern_reset = "#{esc}[0m"
|
148
|
+
pattern = "#{esc}[%{decor};%{fg}m"
|
151
149
|
|
152
150
|
decors = { txt: 0, bld: 1, und: 4, rev: 7 }
|
153
151
|
color_codes = { blk: 0, red: 1, grn: 2, ylw: 3, blu: 4, pur: 5, cyn: 6, wht: 7 }
|
@@ -156,17 +154,20 @@ module Colsole
|
|
156
154
|
decors.each do |dk, dv|
|
157
155
|
color_codes.each do |ck, cv|
|
158
156
|
key = "#{dk}#{ck}"
|
159
|
-
val =
|
157
|
+
val = pattern % { decor: dv, fg: "3#{cv}" }
|
160
158
|
colors[key] = val
|
161
159
|
end
|
162
160
|
end
|
163
|
-
colors['
|
161
|
+
colors['txtbld'] = "#{esc}[1m"
|
162
|
+
colors['txtund'] = "#{esc}[4m"
|
163
|
+
colors['txtrev'] = "#{esc}[7m"
|
164
|
+
colors['txtrst'] = "#{esc}[0m"
|
164
165
|
colors
|
165
166
|
end
|
166
167
|
|
167
168
|
def show_color_demo
|
168
|
-
i=
|
169
|
-
colors.each do |k
|
169
|
+
i = colors.count
|
170
|
+
colors.keys.each do |k|
|
170
171
|
puts colorize "#{k} = !#{k}! #{i} bottles of beer on the wall !txtrst!"
|
171
172
|
i -= 1
|
172
173
|
end
|
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.7.
|
4
|
+
version: 0.7.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:
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Utility functions for making colorful console applications
|
14
14
|
email: db@dannyben.com
|