artsy 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/artsy.rb +45 -3
- 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: 8bc9fc5bfedd084463fc3ceab484c7685c9bb66ed85fe037ff49730d84031214
|
4
|
+
data.tar.gz: f7ae5dac299be4f2c020b7e058addfa956c9698ae16f124254ff49f8c7b32207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c45ab57d772878248d393b370ae6261c093ec83e5d78295d14305e4f7d9aa786b2ad71fe63a820995c86cdfaef1bebf8c40af5e2c1af5cb27dbe3708e50f627e
|
7
|
+
data.tar.gz: 24cbed953689cc2e826a813407fbaaec5239ca3caa6fdc328509a25986d2645f52942c495ff6d01bee59a057171efc9851fe7324a70bba34fbde7df1f879d6b6
|
data/lib/artsy.rb
CHANGED
@@ -7,6 +7,43 @@
|
|
7
7
|
|
8
8
|
class Artsy
|
9
9
|
# main class
|
10
|
+
class Handler
|
11
|
+
# subclass: contains some preset argumenterror cases
|
12
|
+
def self.rgbOutOfRange(mode, r, g, b)
|
13
|
+
# HACK: Change mode in the script to change how your artsy install deals with errors.
|
14
|
+
if mode == "strict"
|
15
|
+
# strict: raise an argument error exception without catching
|
16
|
+
limit = 255 # set limit
|
17
|
+
unless r <= limit and r >= 0
|
18
|
+
# fail if r exceeds limit or if lower than 0.
|
19
|
+
raise ArgumentError.new "'r' value out of range. Must be between 0-255 (you entered #{r})."
|
20
|
+
end
|
21
|
+
unless g <= limit and g >= 0
|
22
|
+
# fail for green
|
23
|
+
raise ArgumentError.new "'g' value out of range. Must be between 0-255 (you entered #{g})."
|
24
|
+
end
|
25
|
+
unless b <= limit and b >= 0
|
26
|
+
# fail for blue
|
27
|
+
raise ArgumentError.new "'b' value out of range. Must be between 0-255 (you entered #{b})."
|
28
|
+
end
|
29
|
+
elsif mode == "chill"
|
30
|
+
# chill: Print a warning message to stderr, but don't raise exception.
|
31
|
+
limit = 255
|
32
|
+
unless r <= limit and r >= 0
|
33
|
+
# warn for red
|
34
|
+
STDERR.puts "WARNING: red value out of range... (#{r})"
|
35
|
+
end
|
36
|
+
unless g <= limit and g >= 0
|
37
|
+
# warn for green
|
38
|
+
STDERR.puts "WARNING: green value out of range... (#{g})"
|
39
|
+
end
|
40
|
+
unless b <= limit and b >= 0
|
41
|
+
# warn for blue
|
42
|
+
STDERR.puts "WARNING: blue value out of range... (#{b})"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
10
47
|
def self.out(text, colortype, r = 0, g = 0, b = 0, color: "none", formatting: "none")
|
11
48
|
definedColours = ["\033[0m", "\033[31m", "\033[32m", "\033[93m", "\033[91m", "\033[92m", "\033[96m"]
|
12
49
|
# print colored/formatted text (either from the preset list or with truecolors)
|
@@ -15,7 +52,7 @@ class Artsy
|
|
15
52
|
# print with regular colors
|
16
53
|
if color == "none"
|
17
54
|
# fail if color undefined
|
18
|
-
raise
|
55
|
+
raise ArgumentError.new "Invalid color defined (#{color})."
|
19
56
|
elsif color == "red"
|
20
57
|
# printcolor = red
|
21
58
|
printcolor = "#{definedColours[1]}"
|
@@ -31,14 +68,16 @@ class Artsy
|
|
31
68
|
printcolor = "#{definedColours[6]}"
|
32
69
|
else
|
33
70
|
# fail
|
34
|
-
raise
|
71
|
+
raise ArgumentError.new "Invalid color defined (#{color})."
|
35
72
|
end
|
36
73
|
elsif colortype == "true"
|
74
|
+
# before doing anything, ensure all rgb values are within range
|
75
|
+
Handler.rgbOutOfRange("strict", r, g, b) # calls the handler check and passes rgb
|
37
76
|
# print with rgb
|
38
77
|
printcolor = "\033[38;2;#{r};#{g};#{b}m"
|
39
78
|
else
|
40
79
|
# fail
|
41
|
-
raise
|
80
|
+
raise ArgumentError.new "Invalid colortype defined (#{colortype})."
|
42
81
|
end
|
43
82
|
if formatting == "none"
|
44
83
|
puts "#{printcolor}#{text}#{definedColours[0]}" # done!
|
@@ -52,6 +91,9 @@ class Artsy
|
|
52
91
|
end
|
53
92
|
end
|
54
93
|
def self.gradientOut(text, r1, g1, b1, r2, g2, b2, stepping, debug = 0)
|
94
|
+
# before doing anything, check both rgb sets
|
95
|
+
Handler.rgbOutOfRange("strict", r1, g1, b1)
|
96
|
+
Handler.rgbOutOfRange("strict", r2, g2, b2)
|
55
97
|
# prints text with a gradient
|
56
98
|
# increases every value by stepping per character
|
57
99
|
arr_Text = text.split("") # split text into array of characters
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artsy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Enables you to make good looking terminal programs with colors and text
|
14
14
|
formatting.
|