downup 0.3.3 → 0.4.3

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
  SHA1:
3
- metadata.gz: e35290acc75be20825a11b389b1a17fcf7b15e06
4
- data.tar.gz: cfe3648f3ce916d3304be3340733bae086651e9c
3
+ metadata.gz: ae6bea2f18582ceaace3c1f7eb8f99508739823e
4
+ data.tar.gz: 3caf86aa27195deab1ee03491a0e2c94dd239df5
5
5
  SHA512:
6
- metadata.gz: 0c707f040b07feb1e6e5bd0a257c3da8518884edb782c0000eeef734d3561ab1c326fd843617da1176168b392ba96a992b8553a4c7b61aed2dc3cff58d2060c4
7
- data.tar.gz: d275a2dbe47176a8b6c59f3dddb9f7f1a27874f2c2a4abb44fb16458223cc2be6be2ff84b8791469ab5d649bae8c17928d2dbd9277a033fe1fe3e28f3208f432
6
+ metadata.gz: 64ae718eda8e249c784a4991d9636f1752468330b9fe5220f0f4a78ad6754f6eaa898007f92e0cc8424d44b91f786fe36d9b8b0d218e687286956af06d773fb8
7
+ data.tar.gz: b9d21db6b1899486fc41cf0d2b9d7121da8d7fddbc7a82e8bbb2d2c92202d7736a250989289133b2aff343f786c948897884109da32610c23fdb96de4efed610
data/README.md CHANGED
@@ -21,6 +21,8 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
+ [Runnable Examples](examples/basic.rb)
25
+
24
26
  ```ruby
25
27
  options = [
26
28
  "Dog",
@@ -32,6 +34,47 @@ Downup::Base.new(options: options).prompt
32
34
 
33
35
  # You can also pass a title when initializing
34
36
  Downup::Base.new(options: options, title: "Animals: \n").prompt
37
+
38
+ # you can pass a callable header
39
+ # to print out before the menu
40
+
41
+ def header
42
+ puts "\n=========="
43
+ puts "= HEADER ="
44
+ puts "==========\n"
45
+ end
46
+
47
+ Downup::Base.new(options: options, header_proc: method(header)).prompt
48
+
49
+ # You can also change the default and selected color,
50
+ # your options are as follows
51
+
52
+ COLOR_OPTIONS = [
53
+ :black
54
+ :red
55
+ :green
56
+ :brown
57
+ :blue
58
+ :magenta
59
+ :cyan
60
+ :gray
61
+ :bg_black
62
+ :bg_red
63
+ :bg_green
64
+ :bg_brown
65
+ :bg_blue
66
+ :bg_magenta
67
+ :bg_cyan
68
+ :bg_gray
69
+ :bold
70
+ :reverse_color
71
+ ]
72
+
73
+ Downup::Base.new(
74
+ options: options,
75
+ default_color: :bg_gray,
76
+ selected_color: :cyan
77
+ ).prompt
35
78
  ```
36
79
 
37
80
  ## Inspired By
data/downup-0.3.3.gem ADDED
Binary file
data/examples/basic.rb ADDED
@@ -0,0 +1,33 @@
1
+ require_relative "../lib/downup"
2
+
3
+ options = [
4
+ "Cat",
5
+ "Dog",
6
+ "Kangaroo"
7
+ ]
8
+
9
+ puts "The most basic example"
10
+ puts Downup::Base.new(options: options).prompt
11
+
12
+ puts Downup::Base.new(
13
+ options: options,
14
+ title: "Choose an Animal: \n"
15
+ ).prompt
16
+
17
+ def header
18
+ puts "\n\t$$$$$$$$$$$$$$$$$$$$"
19
+ puts "\t$$ AWESOME HEADER $$"
20
+ puts "\t$$$$$$$$$$$$$$$$$$$$\n\n"
21
+ end
22
+
23
+ puts Downup::Base.new(
24
+ options: options,
25
+ title: "Choose an Animal: \n",
26
+ header_proc: method(:header)
27
+ ).prompt
28
+
29
+ puts Downup::Base.new(
30
+ options: options,
31
+ default_color: :cyan,
32
+ selected_color: :bg_magenta
33
+ ).prompt
@@ -1,3 +1,3 @@
1
1
  module Downup
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.3"
3
3
  end
data/lib/downup.rb CHANGED
@@ -6,14 +6,23 @@ module Downup
6
6
  using Colors
7
7
 
8
8
  class Base
9
- def initialize(options:, title: nil)
10
- @options = options
11
- @title = title
9
+ def initialize(options:,
10
+ title: nil,
11
+ default_color: :gray,
12
+ selected_color: :green,
13
+ header_proc: Proc.new {})
14
+
15
+ @options = options
16
+ @title = title
17
+ @default_color = default_color
18
+ @selected_color = selected_color
19
+ @header_proc = header_proc
12
20
  end
13
21
 
14
22
  def prompt(position = 0)
15
23
  @selected_position = position_selector(position)
16
24
  system("clear")
25
+ header_proc.call
17
26
  print_title
18
27
  print_options
19
28
  print "\n> "
@@ -22,7 +31,12 @@ module Downup
22
31
 
23
32
  private
24
33
 
25
- attr_reader :options, :title, :selected_position
34
+ attr_reader :options,
35
+ :title,
36
+ :selected_position,
37
+ :header_proc,
38
+ :selected_color,
39
+ :default_color
26
40
 
27
41
  def process_input(input)
28
42
  case input
@@ -47,13 +61,20 @@ module Downup
47
61
 
48
62
  def print_options
49
63
  options.each_with_index do |option, index|
50
- puts index == selected_position ? option.bg_magenta : option
64
+ puts colorize_option(option, index)
65
+ end
66
+ end
67
+
68
+ def colorize_option(option, index)
69
+ if index == selected_position
70
+ eval("option.#{selected_color}")
71
+ else
72
+ eval("option.#{default_color}")
51
73
  end
52
74
  end
53
75
 
54
76
  def print_title
55
77
  return if title.nil?
56
-
57
78
  puts "#{title}".red
58
79
  end
59
80
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: downup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Begin
@@ -55,8 +55,9 @@ files:
55
55
  - Rakefile
56
56
  - bin/console
57
57
  - bin/setup
58
- - downup-0.3.2.gem
58
+ - downup-0.3.3.gem
59
59
  - downup.gemspec
60
+ - examples/basic.rb
60
61
  - lib/downup.rb
61
62
  - lib/downup/colors.rb
62
63
  - lib/downup/version.rb
data/downup-0.3.2.gem DELETED
Binary file