colsole 0.8.2 → 1.0.0
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 +4 -4
- data/README.md +2 -2
- data/lib/colsole/version.rb +1 -1
- data/lib/colsole.rb +2 -9
- metadata +3 -4
- data/lib/colsole/compat.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 832d466f34ab604a7a9cc7b4e92b94aea79fc4fd52e6383c767bf17483be5d7b
|
4
|
+
data.tar.gz: ceb677bb2f0b6125e2f80717709bbb65d4c9b43bc9bf00d994f4c337a0317536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aa0974a9282c9c3140ae0e16e2b8dfaec4b846cea832a2c46f5d35cd5200ce76d93ebb3bad5f24e785489af1143b3da20acb4f9e8f09e2442b01c90a52fbe54
|
7
|
+
data.tar.gz: 957dc4bf62fd4fcecc0d11e7a2bee220b03e75d0283bdc6d123026fc117b305c2d36b66a9a83b81fbe5f44547aade7cd0ac6dd5cb45ea4bd221cb02c10a0c446
|
data/README.md
CHANGED
@@ -10,8 +10,8 @@ Utility functions for colorful console applications.
|
|
10
10
|
|
11
11
|
> **Upgrade Note**
|
12
12
|
>
|
13
|
-
>
|
14
|
-
>
|
13
|
+
> - Version 1.0.x is not compatible with older versions
|
14
|
+
> - Version 0.8.x is compatible with both the old syntax and new syntax
|
15
15
|
>
|
16
16
|
> See [Uprading](#upgrading) below.
|
17
17
|
|
data/lib/colsole/version.rb
CHANGED
data/lib/colsole.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'io/console'
|
2
|
-
require 'colsole/compat'
|
3
2
|
|
4
3
|
# Utility functions for colorful console applications.
|
5
4
|
module Colsole
|
@@ -105,20 +104,14 @@ module_function
|
|
105
104
|
|
106
105
|
# Convert color markers to ansi colors.
|
107
106
|
def colorize(string)
|
108
|
-
|
109
|
-
compat_string = old_colorize string
|
110
|
-
|
111
|
-
process_color_markers compat_string do |color, styles, text|
|
107
|
+
process_color_markers string do |color, styles, text|
|
112
108
|
"#{styles}#{color}#{text}#{ANSI_STYLES['z']}"
|
113
109
|
end
|
114
110
|
end
|
115
111
|
|
116
112
|
# Remove color markers.
|
117
113
|
def strip_colors(string)
|
118
|
-
|
119
|
-
compat_string = old_strip_colors string
|
120
|
-
|
121
|
-
process_color_markers(compat_string) { |_color, _styles, text| text }
|
114
|
+
process_color_markers(string) { |_color, _styles, text| text }
|
122
115
|
end
|
123
116
|
|
124
117
|
def process_color_markers(string)
|
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.
|
4
|
+
version: 1.0.0
|
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: 2023-01-
|
11
|
+
date: 2023-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Utility functions for making colorful console applications
|
14
14
|
email: db@dannyben.com
|
@@ -18,7 +18,6 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- README.md
|
20
20
|
- lib/colsole.rb
|
21
|
-
- lib/colsole/compat.rb
|
22
21
|
- lib/colsole/version.rb
|
23
22
|
homepage: https://github.com/DannyBen/colsole
|
24
23
|
licenses:
|
@@ -33,7 +32,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
32
|
requirements:
|
34
33
|
- - ">="
|
35
34
|
- !ruby/object:Gem::Version
|
36
|
-
version: 2.
|
35
|
+
version: '2.7'
|
37
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
38
|
- - ">="
|
data/lib/colsole/compat.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# This file contains methods that are called by the main Colsole module
|
2
|
-
# for compatibility with older versions of colsole.
|
3
|
-
# Do not use these methods directly.
|
4
|
-
module Colsole
|
5
|
-
module_function
|
6
|
-
|
7
|
-
def detect_terminal_size(*args)
|
8
|
-
terminal_size(*args)
|
9
|
-
end
|
10
|
-
|
11
|
-
def old_colorize(text)
|
12
|
-
reset = colors['txtrst']
|
13
|
-
reset_called_last = true
|
14
|
-
|
15
|
-
out = text.gsub(/!([a-z]{6})!/) do
|
16
|
-
reset_called_last = $1 == 'txtrst'
|
17
|
-
colors[$1]
|
18
|
-
end
|
19
|
-
|
20
|
-
reset_called_last or out = "#{out}#{reset}"
|
21
|
-
out
|
22
|
-
end
|
23
|
-
|
24
|
-
def old_strip_colors(text)
|
25
|
-
text.gsub(/!([a-z]{6})!/, '')
|
26
|
-
end
|
27
|
-
|
28
|
-
def resay(text)
|
29
|
-
say text, replace: true
|
30
|
-
end
|
31
|
-
|
32
|
-
def say_status(status, message = nil, color = nil)
|
33
|
-
color ||= (message ? :txtgrn : :txtblu)
|
34
|
-
say "!#{color}!#{status.to_s.rjust 12} !txtrst! #{message}".strip
|
35
|
-
end
|
36
|
-
|
37
|
-
def colors
|
38
|
-
@colors ||= begin
|
39
|
-
esc = 27.chr
|
40
|
-
pattern = "#{esc}[%{decor};%{fg}m"
|
41
|
-
|
42
|
-
decors = { txt: 0, bld: 1, und: 4, rev: 7 }
|
43
|
-
color_codes = { blk: 0, red: 1, grn: 2, ylw: 3, blu: 4, pur: 5, cyn: 6, wht: 7 }
|
44
|
-
colors = {}
|
45
|
-
|
46
|
-
decors.each do |dk, dv|
|
47
|
-
color_codes.each do |ck, cv|
|
48
|
-
key = "#{dk}#{ck}"
|
49
|
-
val = pattern % { decor: dv, fg: "3#{cv}" }
|
50
|
-
colors[key] = val
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
colors['txtbld'] = "#{esc}[1m"
|
55
|
-
colors['txtund'] = "#{esc}[4m"
|
56
|
-
colors['txtrev'] = "#{esc}[7m"
|
57
|
-
colors['txtrst'] = "#{esc}[0m"
|
58
|
-
colors
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|