four_two_seven 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/427.gemspec +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/427 +85 -0
- data/lib/427/command.rb +41 -0
- data/lib/427/version.rb +3 -0
- data/lib/427.rb +6 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f21ef41892a861082cc589cf27e9c2a1cc991a24
|
4
|
+
data.tar.gz: f58b9e8f37947934836f04e079acb2c0d568774a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b05e7372f78652e80aca3ce2d2cadca5c13c620777e2d7f4b716744f41fd414386884bbb3edebc396f782e36c8d4fce774a9a0fcdb2fe57e2ff77e8271dd4d3
|
7
|
+
data.tar.gz: e3638d887f0c7a459dc03d734262c2bf8788f53d9176edddf21586a06393d6d3e83de5d242142c66cf7b43150d37a7df25ab1c43bcc1dbc4c87543d67d2f6eaf
|
data/.gitignore
ADDED
data/427.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require '427/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "four_two_seven"
|
8
|
+
spec.version = FourTwoSeven::VERSION
|
9
|
+
spec.authors = ["Lee Machin"]
|
10
|
+
spec.email = ["ljmachin@gmail.com"]
|
11
|
+
spec.summary = %q{Employee number 427's job was simple...}
|
12
|
+
spec.description = %q{...he sat at his desk in room 427 and he pushed buttons on a keyboard.}
|
13
|
+
spec.homepage = "https://github.com/leemachin/427"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "curses"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Lee Machin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# 427
|
2
|
+
|
3
|
+
> Stanley worked for a company in a big building where he was employee
|
4
|
+
> number 427. Employee Number 427's job was simple: he sat at his desk in
|
5
|
+
> room 427, and he pushed buttons on a keyboard. Orders came to him
|
6
|
+
> through a monitor on his desk, telling him what buttons to push, how
|
7
|
+
> long to push them, and in what order.
|
8
|
+
|
9
|
+
Now you get to be the new Employee 427 ;)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install 427
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Get to work with:
|
20
|
+
|
21
|
+
```
|
22
|
+
427
|
23
|
+
```
|
24
|
+
|
25
|
+
And follow the commands. Quickly, of course. Slacking off won't be tolerated.
|
26
|
+
|
27
|
+
## Todo
|
28
|
+
|
29
|
+
- Get the long keypresses to work. Keypresses stack up and get used for future commands, breaking the entire thing.
|
data/Rakefile
ADDED
data/bin/427
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require "curses"
|
7
|
+
require "427"
|
8
|
+
require "timeout"
|
9
|
+
require "io/console"
|
10
|
+
|
11
|
+
include Curses
|
12
|
+
include FourTwoSeven
|
13
|
+
include Timeout
|
14
|
+
|
15
|
+
DEFAULT_COLORS = 1
|
16
|
+
|
17
|
+
begin
|
18
|
+
noecho
|
19
|
+
init_screen
|
20
|
+
start_color
|
21
|
+
crmode
|
22
|
+
nonl
|
23
|
+
|
24
|
+
init_pair(DEFAULT_COLORS, COLOR_GREEN, COLOR_BLACK)
|
25
|
+
window = Window.new(0, 0, 0, 0)
|
26
|
+
|
27
|
+
window.scrollok(true)
|
28
|
+
window.idlok(true)
|
29
|
+
window.color_set(DEFAULT_COLORS)
|
30
|
+
|
31
|
+
window << "Welcome, Employee 427."
|
32
|
+
window << Command::SEPARATOR
|
33
|
+
|
34
|
+
prev_cmd = nil
|
35
|
+
|
36
|
+
loop do
|
37
|
+
cmd = Command.new(prev_cmd)
|
38
|
+
prev_cmd = cmd
|
39
|
+
timer = 0
|
40
|
+
|
41
|
+
window << cmd.prompt
|
42
|
+
|
43
|
+
if cmd.duration > 0 # todo: fix this horrible mess
|
44
|
+
begin
|
45
|
+
input = nil
|
46
|
+
loop do
|
47
|
+
timeout(1) do
|
48
|
+
input = window.getch
|
49
|
+
if input == cmd.key && timer < cmd.duration
|
50
|
+
timer += 1
|
51
|
+
else
|
52
|
+
fail
|
53
|
+
end
|
54
|
+
end
|
55
|
+
sleep (1)
|
56
|
+
end
|
57
|
+
rescue # no keypress
|
58
|
+
if timer == cmd.duration && input == cmd.key
|
59
|
+
else
|
60
|
+
beep
|
61
|
+
flash
|
62
|
+
end
|
63
|
+
end
|
64
|
+
else
|
65
|
+
if window.getch == cmd.key
|
66
|
+
# nothing happens when you get it right, does it?
|
67
|
+
else
|
68
|
+
beep
|
69
|
+
flash
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
STDIN.flush
|
74
|
+
|
75
|
+
window << Command::SEPARATOR
|
76
|
+
window.refresh
|
77
|
+
sleep(5)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
at_exit do
|
82
|
+
close_screen
|
83
|
+
puts "See you tomorrow, Employee 427"
|
84
|
+
end
|
85
|
+
|
data/lib/427/command.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module FourTwoSeven
|
2
|
+
class Command
|
3
|
+
|
4
|
+
KEYS = [
|
5
|
+
*"A".."Z",
|
6
|
+
*"a".."z",
|
7
|
+
*"0".."9",
|
8
|
+
" "
|
9
|
+
]
|
10
|
+
|
11
|
+
DURATION = 0..15
|
12
|
+
|
13
|
+
PROMPT = "Please PRESS '%s' on your KEYBOARD for %ss.\n"
|
14
|
+
|
15
|
+
SEPARATOR = "\n\n- - -\n"
|
16
|
+
|
17
|
+
attr_accessor :prev_command
|
18
|
+
|
19
|
+
def initialize(prev_command = nil)
|
20
|
+
@prev_command = prev_command
|
21
|
+
end
|
22
|
+
|
23
|
+
def key
|
24
|
+
@key ||= if prev_command
|
25
|
+
KEYS - [prev_command.key]
|
26
|
+
else
|
27
|
+
KEYS
|
28
|
+
end.sample
|
29
|
+
end
|
30
|
+
|
31
|
+
def duration
|
32
|
+
0
|
33
|
+
#@duration ||= rand(DURATION)
|
34
|
+
end
|
35
|
+
|
36
|
+
def prompt
|
37
|
+
PROMPT % [key, duration]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/427/version.rb
ADDED
data/lib/427.rb
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: four_two_seven
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lee Machin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curses
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: '...he sat at his desk in room 427 and he pushed buttons on a keyboard.'
|
56
|
+
email:
|
57
|
+
- ljmachin@gmail.com
|
58
|
+
executables:
|
59
|
+
- '427'
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- 427.gemspec
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/427
|
70
|
+
- lib/427.rb
|
71
|
+
- lib/427/command.rb
|
72
|
+
- lib/427/version.rb
|
73
|
+
homepage: https://github.com/leemachin/427
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.14
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Employee number 427's job was simple...
|
97
|
+
test_files: []
|