downup 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c6e65b3f3072415591a30ea663da443baecfb82
4
+ data.tar.gz: 1e523fd756f0a970b7787b1527241708cc458f89
5
+ SHA512:
6
+ metadata.gz: 11eeadb275adca911e8a52057022770071f21e3612bf1be12f649c5c6d2628b9237e7f2727b8843252abd471c917eca75bfafa7c823cb9d5d477443dba942d50
7
+ data.tar.gz: 0deff0c531f8369ebbc652a1b030a413aca1aeb378abcff871dc3fe7fe6f6c383fc622f6871e166a85979b904b3f3fdf81edddaf0aa8a6bf406959bf0ebcc93f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in downup.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 David Begin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Downup
2
+
3
+ A simple gem for creating command line menus you can use the arrows
4
+ to move through.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'downup'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install downup
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ options = [
26
+ "Dog",
27
+ "Cat",
28
+ "Kangaroo"
29
+ ]
30
+
31
+ Downup::Base.new(options).prompt
32
+ ```
33
+
34
+ ## Inspired By
35
+
36
+ This gist
37
+ https://gist.github.com/acook/4190379
38
+
39
+ and this SO article
40
+ http://stackoverflow.com/questions/1489183/colorized-ruby-output
41
+
42
+
43
+ ## Development
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/[my-github-username]/downup/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "downup"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/downup.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'downup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "downup"
8
+ spec.version = Downup::VERSION
9
+ spec.authors = ["David Begin"]
10
+ spec.email = ["davidmichaelbe@gmail.com"]
11
+ spec.summary = "a Gem for creating menus that you can easily navigate through"
12
+ spec.description = "allow up and down arrows, as well as vim like commands"
13
+ spec.homepage = "https://github.com/presidentJFK/downup"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,24 @@
1
+ module Downup
2
+ module Colors
3
+ refine String do
4
+ def black; "\033[30m#{self}\033[0m" end
5
+ def red; "\033[31m#{self}\033[0m" end
6
+ def green; "\033[32m#{self}\033[0m" end
7
+ def brown; "\033[33m#{self}\033[0m" end
8
+ def blue; "\033[34m#{self}\033[0m" end
9
+ def magenta; "\033[35m#{self}\033[0m" end
10
+ def cyan; "\033[36m#{self}\033[0m" end
11
+ def gray; "\033[37m#{self}\033[0m" end
12
+ def bg_black; "\033[40m#{self}\033[0m" end
13
+ def bg_red; "\033[41m#{self}\033[0m" end
14
+ def bg_green; "\033[42m#{self}\033[0m" end
15
+ def bg_brown; "\033[43m#{self}\033[0m" end
16
+ def bg_blue; "\033[44m#{self}\033[0m" end
17
+ def bg_magenta; "\033[45m#{self}\033[0m" end
18
+ def bg_cyan; "\033[46m#{self}\033[0m" end
19
+ def bg_gray; "\033[47m#{self}\033[0m" end
20
+ def bold; "\033[1m#{self}\033[22m" end
21
+ def reverse_color; "\033[7m#{self}\033[27m" end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Downup
2
+ VERSION = "0.2.1"
3
+ end
data/lib/downup.rb ADDED
@@ -0,0 +1,66 @@
1
+ require "downup/version"
2
+ require "downup/colors"
3
+ require "io/console"
4
+
5
+ module Downup
6
+ using Colors
7
+
8
+ class Base
9
+ def initialize(options)
10
+ @options = options
11
+ end
12
+
13
+ def prompt(position = 0)
14
+ @selected_position = position_selector(position)
15
+ print_options
16
+ print "\n> "
17
+ process_input read_char
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :options, :selected_position
23
+
24
+ def process_input(input)
25
+ case input
26
+ when "\e[A", "k"
27
+ prompt(selected_position - 1)
28
+ when "\e[B", "j"
29
+ prompt(selected_position + 1)
30
+ when "\u0003" then exit
31
+ when "\r"
32
+ options[selected_position]
33
+ else
34
+ prompt(selected_position)
35
+ end
36
+ end
37
+
38
+ def position_selector(position)
39
+ case position
40
+ when -1 then options.count - 1
41
+ when options.count then 0
42
+ else position; end
43
+ end
44
+
45
+ def print_options
46
+ system("clear")
47
+ options.each_with_index do |option, index|
48
+ puts index == selected_position ? option.bg_magenta : option
49
+ end
50
+ end
51
+
52
+ def read_char
53
+ STDIN.echo = false
54
+ STDIN.raw!
55
+ input = STDIN.getc.chr
56
+ if input == "\e" then
57
+ input << STDIN.read_nonblock(3) rescue nil
58
+ input << STDIN.read_nonblock(2) rescue nil
59
+ end
60
+ ensure
61
+ STDIN.echo = true
62
+ STDIN.cooked!
63
+ return input
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: downup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - David Begin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: allow up and down arrows, as well as vim like commands
42
+ email:
43
+ - davidmichaelbe@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".ruby-version"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - downup.gemspec
59
+ - lib/downup.rb
60
+ - lib/downup/colors.rb
61
+ - lib/downup/version.rb
62
+ homepage: https://github.com/presidentJFK/downup
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: a Gem for creating menus that you can easily navigate through
86
+ test_files: []
87
+ has_rdoc: