artsy 0.3.0 → 0.3.1
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/lib/artsy.rb +16 -49
- data/lib/artsy/devel/handler.rb +40 -0
- data/lib/artsy/menu.rb +72 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14db637c153d6dce542eacc55e154dc2dd3a6135894370a4566dd3121e659b95
|
4
|
+
data.tar.gz: 1562e5f4683a7fddc5312e36a48badf3e2e853a4b932b74e99da3dd41849455a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c38b8fbf673f19350da3b1caef2c49ad41dcc39ed67dc6d1f5a871d1dae562e224dd2e02f164c74bcdbf9e2ee86cfd8c7073b517cd5138056cd31831c2dd95a3
|
7
|
+
data.tar.gz: 3911cdd115b9f8ab118b1d312793c95f8f84c00605efc8be601ccfb865ac4910a33c874fe8210fc99c7172958e32a5dde77e1b26a9427da1061867f05ddf7fe5
|
data/lib/artsy.rb
CHANGED
@@ -7,43 +7,7 @@
|
|
7
7
|
|
8
8
|
class Artsy
|
9
9
|
# main class
|
10
|
-
|
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
|
+
require 'artsy/devel/handler'
|
47
11
|
def self.out(text, colortype, r = 0, g = 0, b = 0, color: "none", formatting: "none")
|
48
12
|
definedColours = ["\033[0m", "\033[31m", "\033[32m", "\033[93m", "\033[91m", "\033[92m", "\033[96m"]
|
49
13
|
# print colored/formatted text (either from the preset list or with truecolors)
|
@@ -72,28 +36,31 @@ class Artsy
|
|
72
36
|
end
|
73
37
|
elsif colortype == "true"
|
74
38
|
# before doing anything, ensure all rgb values are within range
|
75
|
-
Handler.rgbOutOfRange("strict", r, g, b) # calls the handler check and passes rgb
|
39
|
+
ArtsyDev::Handler.rgbOutOfRange("strict", r, g, b) # calls the handler check and passes rgb
|
76
40
|
# print with rgb
|
77
41
|
printcolor = "\033[38;2;#{r};#{g};#{b}m"
|
78
42
|
else
|
79
43
|
# fail
|
80
44
|
raise ArgumentError.new "Invalid colortype defined (#{colortype})."
|
81
45
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
46
|
+
case formatting
|
47
|
+
when "none"
|
48
|
+
puts "#{printcolor}#{text}#{definedColours[0]}" # done!
|
49
|
+
when "bold"
|
50
|
+
puts "#{printcolor}\033[1m#{text}#{definedColours[0]}"
|
51
|
+
when "underline", "ul"
|
52
|
+
puts "#{printcolor}\033[4m#{text}#{definedColours[0]}"
|
53
|
+
when "italics"
|
54
|
+
# WARNING: Not widely supported by terminal emulators.
|
55
|
+
puts "#{printcolor}\033[3m#{text}#{definedColours[0]}"
|
56
|
+
else
|
57
|
+
raise ArgumentError.new "Invalid formatting option set (#{formatting})."
|
91
58
|
end
|
92
59
|
end
|
93
60
|
def self.gradientOut(text, r1, g1, b1, r2, g2, b2, stepping, debug = 0)
|
94
61
|
# before doing anything, check both rgb sets
|
95
|
-
Handler.rgbOutOfRange("strict", r1, g1, b1)
|
96
|
-
Handler.rgbOutOfRange("strict", r2, g2, b2)
|
62
|
+
ArtsyDev::Handler.rgbOutOfRange("strict", r1, g1, b1)
|
63
|
+
ArtsyDev::Handler.rgbOutOfRange("strict", r2, g2, b2)
|
97
64
|
# prints text with a gradient
|
98
65
|
# increases every value by stepping per character
|
99
66
|
arr_Text = text.split("") # split text into array of characters
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class ArtsyDev
|
2
|
+
# parent class as a namespace
|
3
|
+
class Handler
|
4
|
+
# subclass: contains some preset argumenterror cases
|
5
|
+
def self.rgbOutOfRange(mode, r, g, b)
|
6
|
+
# HACK: Change mode in the script to change how your artsy install deals with errors.
|
7
|
+
if mode == "strict"
|
8
|
+
# strict: raise an argument error exception without catching
|
9
|
+
limit = 255 # set limit
|
10
|
+
unless r <= limit and r >= 0
|
11
|
+
# fail if r exceeds limit or if lower than 0.
|
12
|
+
raise ArgumentError.new "'r' value out of range. Must be between 0-255 (you entered #{r})."
|
13
|
+
end
|
14
|
+
unless g <= limit and g >= 0
|
15
|
+
# fail for green
|
16
|
+
raise ArgumentError.new "'g' value out of range. Must be between 0-255 (you entered #{g})."
|
17
|
+
end
|
18
|
+
unless b <= limit and b >= 0
|
19
|
+
# fail for blue
|
20
|
+
raise ArgumentError.new "'b' value out of range. Must be between 0-255 (you entered #{b})."
|
21
|
+
end
|
22
|
+
elsif mode == "chill"
|
23
|
+
# chill: Print a warning message to stderr, but don't raise exception.
|
24
|
+
limit = 255
|
25
|
+
unless r <= limit and r >= 0
|
26
|
+
# warn for red
|
27
|
+
STDERR.puts "WARNING: red value out of range... (#{r})"
|
28
|
+
end
|
29
|
+
unless g <= limit and g >= 0
|
30
|
+
# warn for green
|
31
|
+
STDERR.puts "WARNING: green value out of range... (#{g})"
|
32
|
+
end
|
33
|
+
unless b <= limit and b >= 0
|
34
|
+
# warn for blue
|
35
|
+
STDERR.puts "WARNING: blue value out of range... (#{b})"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/artsy/menu.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
########################################################################
|
2
|
+
### menu.rb ###
|
3
|
+
########################################################################
|
4
|
+
### Allows you to easily create menus in your terminal programs. ###
|
5
|
+
### Developed by Brett. (https://github.com/notronaldmcdonald) ###
|
6
|
+
########################################################################
|
7
|
+
|
8
|
+
class Menu
|
9
|
+
def initialize(title, opts = 3, selectMode = "int")
|
10
|
+
# you can set title and no. of opts for your menu object
|
11
|
+
@menutitle = title
|
12
|
+
@optstrings = Array.new(opts) # create an array for each option
|
13
|
+
@optids = Array.new(opts)
|
14
|
+
maxopts = opts - 1 # for use in the loop
|
15
|
+
for i in 0..maxopts
|
16
|
+
# cycle through the number of options, generating a default string for each
|
17
|
+
@optstrings[i] = "Option #{i}"
|
18
|
+
@optids[i] = i + 1
|
19
|
+
end # end of loop
|
20
|
+
@methodLoader = Linkage.new(@optids.count) # create an object, passing all necessary arguments to it
|
21
|
+
end # end of method
|
22
|
+
|
23
|
+
def setOpt(index, value)
|
24
|
+
# set the value of an option
|
25
|
+
index_real = index - 1
|
26
|
+
@optstrings[index_real] = "#{value}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def show()
|
30
|
+
# print menu
|
31
|
+
puts "#{@menutitle}"
|
32
|
+
puts ""
|
33
|
+
for i in 1..@optids.count
|
34
|
+
# print each option
|
35
|
+
n = i - 1 # to access strings via index
|
36
|
+
puts "#{i}) #{@optstrings[n]}" # print the option
|
37
|
+
end
|
38
|
+
puts ""
|
39
|
+
puts "Enter your selection: "
|
40
|
+
@choice = gets.chomp
|
41
|
+
puts "You entered #{@choice}."
|
42
|
+
# now, we'll run some logic to ensure the choice was in @optids, then we can run the user's code!
|
43
|
+
@choice = Integer(@choice) # make sure it is int
|
44
|
+
@choice = @choice - 1 # convert to real
|
45
|
+
@methodLoader.run(@choice)
|
46
|
+
end # end of method
|
47
|
+
|
48
|
+
def assign(option, mname)
|
49
|
+
# a wrapper function to assign a method to an option
|
50
|
+
trueOpt = option - 1 # do some math
|
51
|
+
@methodLoader.bindMethod(trueOpt, mname)
|
52
|
+
end
|
53
|
+
|
54
|
+
class Linkage
|
55
|
+
# this private class contains functions for binding functions to an optid
|
56
|
+
def initialize(optsize)
|
57
|
+
# initializing the object, setting up the callbackMethods instance array based on optsize
|
58
|
+
@callbackMethods = Array.new(optsize)
|
59
|
+
end # simple method
|
60
|
+
|
61
|
+
def bindMethod(toOpt, mname)
|
62
|
+
# binding methods to a value in an array, to be called back later
|
63
|
+
@callbackMethods[toOpt] = mname
|
64
|
+
end
|
65
|
+
|
66
|
+
def run(target, *args)
|
67
|
+
# run the method assigned to the integer value in the array
|
68
|
+
@callbackMethods[target].call(*args) # taking any arguments, as they are sent to the attached method
|
69
|
+
end
|
70
|
+
end # end of private class
|
71
|
+
private_constant :Linkage # set as private constant
|
72
|
+
end # end of class
|
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.3.
|
4
|
+
version: 0.3.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-14 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.
|
@@ -18,6 +18,8 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/artsy.rb
|
21
|
+
- lib/artsy/devel/handler.rb
|
22
|
+
- lib/artsy/menu.rb
|
21
23
|
homepage: https://github.com/notronaldmcdonald/artsy
|
22
24
|
licenses:
|
23
25
|
- MIT
|