artsy 0.1.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a175378932a34cc922a87e42896ebe230c9d536d4201245097a681c617930927
4
- data.tar.gz: 2594faadfd97a6fda4e158ae811f9667888270b6597ffc08e742ba87be9ce3c1
3
+ metadata.gz: efb06e8dcaa16d78fd779f2c875721b2e14dd8cb1df13386173c1d0a754147e7
4
+ data.tar.gz: 2cb275e3f3040e436e1d4c002e3a275c3aef8266c81bf5d5c37dab477624e435
5
5
  SHA512:
6
- metadata.gz: '089e0fc334a0ed0c959845f461e0d2e0e1776d8d2db8ab78230f155319310b4ae5b29dd5a9a859ffbd3b51a94ce21dd1862d5963a2ce86fd281e46c30375fd38'
7
- data.tar.gz: f0f777e5d23aa55fd39343e7833bba4a41c23233e36d2af6fed17214762696a2a5dd24cf294c10cd4acaec6dd9aefde663fe6c42e289437f0da1d6871b0559eb
6
+ metadata.gz: a5de59059c5daaf5648e240dfda3e58eda0bff02363333f77f49b840bfe2f0af278f0cf305f5e0aebc3d9472b773c7f79f2c3460714c96e538101b00611516a1
7
+ data.tar.gz: 4acb92f51402f01e23160303ce5646ecde15f8b8f66d0c7e1a3bc6689b2b1609890aaa4db62541f0d30058ea23ee6cf4772d80535826d5f2c1b500136bf6cae9
data/lib/artsy.rb CHANGED
@@ -4,9 +4,13 @@
4
4
  ### Make your Ruby terminal programs look nice! ###
5
5
  ### Developed by Brett (https://github.com/notronaldmcdonald) ###
6
6
  #################################################################
7
+ ### Licensed under the GNU LGPLv3 license. See the LICENSE in ###
8
+ ### the project root for more information. ###
9
+ #################################################################
7
10
 
8
11
  class Artsy
9
12
  # main class
13
+ require 'artsy/devel/handler'
10
14
  def self.out(text, colortype, r = 0, g = 0, b = 0, color: "none", formatting: "none")
11
15
  definedColours = ["\033[0m", "\033[31m", "\033[32m", "\033[93m", "\033[91m", "\033[92m", "\033[96m"]
12
16
  # print colored/formatted text (either from the preset list or with truecolors)
@@ -15,7 +19,7 @@ class Artsy
15
19
  # print with regular colors
16
20
  if color == "none"
17
21
  # fail if color undefined
18
- raise StandardError.new "Invalid color defined (#{color})."
22
+ raise ArgumentError.new "Invalid color defined (#{color})."
19
23
  elsif color == "red"
20
24
  # printcolor = red
21
25
  printcolor = "#{definedColours[1]}"
@@ -31,27 +35,35 @@ class Artsy
31
35
  printcolor = "#{definedColours[6]}"
32
36
  else
33
37
  # fail
34
- raise StandardError.new "Invalid color defined (#{color})."
38
+ raise ArgumentError.new "Invalid color defined (#{color})."
35
39
  end
36
40
  elsif colortype == "true"
41
+ # before doing anything, ensure all rgb values are within range
42
+ ArtsyDev::Handler.rgbOutOfRange("strict", r, g, b) # calls the handler check and passes rgb
37
43
  # print with rgb
38
44
  printcolor = "\033[38;2;#{r};#{g};#{b}m"
39
45
  else
40
46
  # fail
41
- raise StandardError.new "Invalid colortype defined (#{colortype})."
47
+ raise ArgumentError.new "Invalid colortype defined (#{colortype})."
42
48
  end
43
- if formatting == "none"
44
- puts "#{printcolor}#{text}#{definedColours[0]}" # done!
45
- elsif formatting == "bold"
46
- puts "#{printcolor}\033[1m#{text}#{definedColours[0]}"
47
- elsif formatting == "underline"
48
- puts "#{printcolor}\033[4m#{text}#{definedColours[0]}"
49
- elsif formatting == "italics"
50
- # WARNING: Not widely supported by terminal emulators.
51
- puts "#{printcolor}\033[3m#{text}#{definedColours[0]}"
49
+ case formatting
50
+ when "none"
51
+ puts "#{printcolor}#{text}#{definedColours[0]}" # done!
52
+ when "bold"
53
+ puts "#{printcolor}\033[1m#{text}#{definedColours[0]}"
54
+ when "underline", "ul"
55
+ puts "#{printcolor}\033[4m#{text}#{definedColours[0]}"
56
+ when "italics"
57
+ # WARNING: Not widely supported by terminal emulators.
58
+ puts "#{printcolor}\033[3m#{text}#{definedColours[0]}"
59
+ else
60
+ raise ArgumentError.new "Invalid formatting option set (#{formatting})."
52
61
  end
53
62
  end
54
63
  def self.gradientOut(text, r1, g1, b1, r2, g2, b2, stepping, debug = 0)
64
+ # before doing anything, check both rgb sets
65
+ ArtsyDev::Handler.rgbOutOfRange("strict", r1, g1, b1)
66
+ ArtsyDev::Handler.rgbOutOfRange("strict", r2, g2, b2)
55
67
  # prints text with a gradient
56
68
  # increases every value by stepping per character
57
69
  arr_Text = text.split("") # split text into array of characters
@@ -112,3 +124,7 @@ class Artsy
112
124
  print "\n" # print a newline
113
125
  end
114
126
  end
127
+
128
+ # load any other gem components
129
+ require 'artsy/menu'
130
+ require 'artsy/colour'
@@ -0,0 +1,29 @@
1
+ #########################################################################
2
+ ### colour.rb ###
3
+ #########################################################################
4
+ ### Provides a way for users to define their own custom colour values ###
5
+ ### Developed by Brett (https://github.com/notronaldmcdonald) ###
6
+ #########################################################################
7
+ require 'json' # needs json rubygem for loading schemes
8
+
9
+ class Color
10
+ # class containing all colour manipulation functions, and variables
11
+ class Schemes
12
+ # colour schemes. namespaced under Color.
13
+ # these are essentially the same functions as above, but storing multiple colours in the hash
14
+ def initialize(filepath = "None")
15
+ # create a new colour scheme
16
+ @scheme = Hash.new
17
+ end
18
+
19
+ def setSColor(name, r, g, b)
20
+ # set scheme colour
21
+ @scheme["#{name}"] = "\033[38;2;#{r};#{g};#{b}m"
22
+ end
23
+
24
+ def out(text, colour)
25
+ # print using a scheme colour
26
+ puts "#{@scheme[colour]}#{text}\033[0m"
27
+ end
28
+ end
29
+ end
@@ -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.1.1
4
+ version: 0.4.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-12 00:00:00.000000000 Z
11
+ date: 2021-05-18 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,9 +18,12 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/artsy.rb
21
+ - lib/artsy/colour.rb
22
+ - lib/artsy/devel/handler.rb
23
+ - lib/artsy/menu.rb
21
24
  homepage: https://github.com/notronaldmcdonald/artsy
22
25
  licenses:
23
- - MIT
26
+ - LGPL-3.0
24
27
  metadata: {}
25
28
  post_install_message:
26
29
  rdoc_options: []