genesis_promptcli 0.2.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +0 -0
  3. data/lib/promptcli.rb +41 -0
  4. metadata +62 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 756e7376157c6caf25c43c1685a4a80cfb340263
4
+ data.tar.gz: 4bd23883739189bbeffe692e4dd3dc3cbb499741
5
+ SHA512:
6
+ metadata.gz: f62409333ce6d97ae4744d0595d8f157a7e1dff13aa117c6de19c9883a32ca1e51e8e4cc903ede57a270a62e67cbe07343d254a105c44126e74cd206fe04fb84
7
+ data.tar.gz: 0990c6d9d604f18ff39343e21e6d2f7e77b9900e339cfc642ac3b3f172480a4795f6d59218479d8513de29197b03583c26e263abbc05b89ec21256d5c00f0d96
File without changes
@@ -0,0 +1,41 @@
1
+ require "termios"
2
+
3
+ module Genesis
4
+ module PromptCLI
5
+ def self.ask question, seconds = 30, default = false
6
+ old_attributes = Termios.tcgetattr($stdin)
7
+ new_attributes = old_attributes.dup
8
+ new_attributes.lflag &= ~Termios::ICANON
9
+ Termios::tcsetattr($stdin, Termios::TCSANOW, new_attributes)
10
+
11
+ start_time = Time.now
12
+ end_time = start_time + seconds
13
+ begin
14
+ prompt_format = "%s [%d] (%s/%s) "
15
+ prompt = prompt_format % [question, seconds.to_i, default ? "Y" : "y", default ? "n" : "N"]
16
+ prompt_length = seconds < 10 ? prompt.length+1 : prompt.length
17
+ $stdout.write(prompt)
18
+ $stdout.flush
19
+
20
+ # Wait until input is available
21
+ if select([$stdin], [], [], seconds % 1)
22
+ case char = $stdin.getc
23
+ when ?y, ?Y then return true
24
+ when ?n, ?N then return false
25
+ else # NOOP
26
+ end
27
+ end
28
+
29
+ $stdout.write("\b" * prompt_length)
30
+ $stdout.flush
31
+
32
+ seconds = end_time - Time.now
33
+ end while seconds > 0.0
34
+
35
+ return default
36
+ ensure
37
+ Termios::tcsetattr($stdin, Termios::TCSANOW, old_attributes)
38
+ $stdout.puts
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genesis_promptcli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Johnstone
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-10 00:00:00.000000000 Z
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.9.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.6
27
+ description: Genesis is a replacement project for InvisibleTouch that is used to manage
28
+ provisioning of hardware. The promptcli is what asks if you want to perform something
29
+ and has a timeout going with a default value if nothing selected in specified time
30
+ period.
31
+ email: jeremy@tumblr.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/promptcli.rb
37
+ - README.md
38
+ homepage: https://github.ewr01.tumblr.net/Tumblr/genesis
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.0.14
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Genesis CLI prompt
62
+ test_files: []