menuboy 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/menuboy.rb +76 -19
- data/lib/menuboy/version.rb +1 -1
- data/menuboy.gemspec +3 -0
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f981149a9b3c5100d98d9185cc0a63672853d2c4
|
4
|
+
data.tar.gz: 730e809487411b80f7752f5f4bb09e42a45de2f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9055ab61a5209a6459f89cca52cb38114c3b39bb6c0f42321f93b3bc98f224eb358a46ce51acf7fb62f9fb562d58ad69eb6a6862f25534bc2d28ce2ad8a8a51
|
7
|
+
data.tar.gz: 38398fc9e2767fda3bffea8d1c20be5e52f22a0a99d06cc7a228cf5b98d0828276503aedd1f481dd94c725356afce82e76cb54f05a23152cc210cbbaf410aa51
|
data/README.md
CHANGED
@@ -8,6 +8,16 @@ managing our node.js/mongodb/redis stack in a super simple way. You can
|
|
8
8
|
see the basic idea of that in test/example.rb, which was used to develop
|
9
9
|
menuboy.
|
10
10
|
|
11
|
+
---
|
12
|
+
|
13
|
+
### v0.1.0
|
14
|
+
* Remove `STDIN.getch` loop approach which was causing formatting
|
15
|
+
issues with other programs trying to write to STDOUT
|
16
|
+
* Use EventMachine to capture keyboard input
|
17
|
+
* Use ruby-termios to enable raw keyboard capture
|
18
|
+
* Provide `Menuboy#fix_stdin` public helper method to temporary re-enable
|
19
|
+
normal stdin behavior
|
20
|
+
|
11
21
|
## Installation
|
12
22
|
|
13
23
|
Add this line to your application's Gemfile:
|
data/lib/menuboy.rb
CHANGED
@@ -1,7 +1,56 @@
|
|
1
1
|
require "menuboy/version"
|
2
2
|
require 'io/console'
|
3
|
+
require 'termios'
|
4
|
+
require 'eventmachine'
|
5
|
+
|
3
6
|
|
4
7
|
module Menuboy
|
8
|
+
@termios_normal_attributes = Termios.tcgetattr($stdin).dup
|
9
|
+
|
10
|
+
def self.raw_terminal
|
11
|
+
attributes = @termios_normal_attributes.dup
|
12
|
+
attributes.lflag &= ~Termios::ECHO
|
13
|
+
attributes.lflag &= ~Termios::ICANON
|
14
|
+
Termios::tcsetattr($stdin, Termios::TCSANOW, attributes)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.normal_terminal
|
18
|
+
Termios::tcsetattr($stdin, Termios::TCSANOW, @termios_normal_attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
module UnbufferedKeyboardHandler
|
22
|
+
def receive_data(k)
|
23
|
+
puts k
|
24
|
+
menu = Menuboy.menus.last
|
25
|
+
if k == "q"
|
26
|
+
Menuboy.menus.pop
|
27
|
+
if next_menu = Menuboy.menus.last
|
28
|
+
next_menu.print_help
|
29
|
+
else
|
30
|
+
exit # no more menus
|
31
|
+
end
|
32
|
+
else
|
33
|
+
menu.handle_input(k)
|
34
|
+
end
|
35
|
+
Menuboy.menus.last.prompt
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Use this if you need to re-enable buffering
|
41
|
+
# as menuboy disables this by default on STDIN
|
42
|
+
# You don't need this when using #system but
|
43
|
+
# you'll want it if you get user input directly
|
44
|
+
def self.fix_stdin
|
45
|
+
self.normal_terminal
|
46
|
+
yield
|
47
|
+
self.raw_terminal
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.menus
|
51
|
+
@menus ||= []
|
52
|
+
end
|
53
|
+
|
5
54
|
module DSL
|
6
55
|
def option name, &block
|
7
56
|
opt_count = @target.options.count
|
@@ -17,7 +66,8 @@ module Menuboy
|
|
17
66
|
option(name) do
|
18
67
|
@target = Menu.new(name)
|
19
68
|
yield
|
20
|
-
@target
|
69
|
+
Menuboy.menus.push @target
|
70
|
+
@target.print_help
|
21
71
|
end
|
22
72
|
end
|
23
73
|
|
@@ -25,10 +75,18 @@ module Menuboy
|
|
25
75
|
if @mainmenu
|
26
76
|
raise StandardError, "You can only define one main menu"
|
27
77
|
else
|
28
|
-
@mainmenu = Menu.new(name)
|
29
|
-
@target = @mainmenu
|
78
|
+
@target = @mainmenu = Menu.new(name)
|
30
79
|
yield
|
31
|
-
@
|
80
|
+
Menuboy.menus.push @target
|
81
|
+
@target.print_help
|
82
|
+
@target.prompt
|
83
|
+
|
84
|
+
Signal.trap("INT") { exit }
|
85
|
+
|
86
|
+
EM.run do
|
87
|
+
Menuboy.raw_terminal
|
88
|
+
EM.open_keyboard(UnbufferedKeyboardHandler)
|
89
|
+
end
|
32
90
|
end
|
33
91
|
end
|
34
92
|
end
|
@@ -61,24 +119,23 @@ module Menuboy
|
|
61
119
|
matches.length == 1 ? matches.last : false
|
62
120
|
end
|
63
121
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
puts input
|
70
|
-
if input == CTRL_C || input == "q"
|
71
|
-
break
|
72
|
-
elsif input == "h"
|
73
|
-
print_help
|
74
|
-
elsif input == "p" && defined? Pry
|
122
|
+
def handle_input k
|
123
|
+
if k == "h"
|
124
|
+
print_help
|
125
|
+
elsif k == "p" && defined? Pry
|
126
|
+
Menuboy.fix_stdin do
|
75
127
|
binding.pry
|
76
|
-
elsif option = option_match?(input)
|
77
|
-
option.proc.call
|
78
|
-
else
|
79
|
-
puts "Unassigned input"
|
80
128
|
end
|
129
|
+
elsif option = option_match?(k)
|
130
|
+
option.proc.call
|
131
|
+
else
|
132
|
+
puts "Unassigned input"
|
81
133
|
end
|
82
134
|
end
|
135
|
+
|
136
|
+
def prompt
|
137
|
+
print "(#{@name})> "
|
138
|
+
end
|
83
139
|
end
|
84
140
|
end
|
141
|
+
|
data/lib/menuboy/version.rb
CHANGED
data/menuboy.gemspec
CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_runtime_dependency 'ruby-termios'
|
22
|
+
spec.add_runtime_dependency 'eventmachine'
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "pry"
|
23
26
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menuboy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keyvan Fatehi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-termios
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +66,20 @@ dependencies:
|
|
38
66
|
- - '>='
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
description: Simple CLI-based menu building DSL
|
42
84
|
email:
|
43
85
|
- keyvanfatehi@gmail.com
|