rubiks-cli 1.2.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b31d0f5c4d03e00788128265b7dbb190583673563adce67252c202f9e114f0a5
4
- data.tar.gz: 046d15a7724fa53739edf3c5dde5b226c925ab8ef419f50238b4b85515d732ff
3
+ metadata.gz: 94d7e949c32e1c1a2d7bb2b31da2e6ff4f99a54fcd61e1b2e973787501c7ccf3
4
+ data.tar.gz: b44f919f1db21605a46bf69809da069e8b322aa4ceda216dc94fe6d9a074c45f
5
5
  SHA512:
6
- metadata.gz: 47d2f102cd05f55b0fc4cd36f47c1e3830c9541ec79e57b10121690a96f969b2a3fd1a50cd3975d2e2e5fe20b75dbce05989bb78097ff26b071f2f66a37a8f07
7
- data.tar.gz: dc0b0fb6338108e15a47cb28752db0783ddd873ab71186c2ab8fdb33d41961780bc730217a28013207f68dc9232d8d1777a2393651a001402c8cf1aeb0e3d4b9
6
+ metadata.gz: cd3db42e118df490e9336e9261da8a164ab574b0683117cd49fceb75d2a20876ce0b97d0bf593ed7de7214268dbcaaa37cef27d379e25b58a213bb2065db2a07
7
+ data.tar.gz: a7675552b1ed9c8734876fd37889bce8c500b7ec9fe5a4c18e1fe122a03e0aee3231d6165ac3581ddf327553955eb09e3cc65f215a738d74154f49ccba711bde
data/bin/rubiks CHANGED
@@ -3,15 +3,28 @@ require 'optparse'
3
3
  require 'rubiks_cli'
4
4
 
5
5
  options = {
6
+ clear: false,
7
+ inspection: false,
8
+ loop: true,
6
9
  scramble: false,
7
10
  time: false,
8
- loop: true,
9
- clear: false,
10
11
  wipe: false,
11
12
  }
12
13
  OptionParser.new do |opts|
13
14
  opts.banner = "Usage: rubiks [options]"
14
15
 
16
+ opts.on("-c", "--clear", "Clear the screen before starting") do
17
+ options[:clear] = true
18
+ end
19
+
20
+ opts.on("-i", "--inspection", "Include inspection time") do
21
+ options[:inspection] = true
22
+ end
23
+
24
+ opts.on("-l", "--loop", "Loop forever") do
25
+ options[:loop] = true
26
+ end
27
+
15
28
  opts.on("-s", "--scramble", "Generate scramble") do
16
29
  options[:scramble] = true
17
30
  end
@@ -20,30 +33,21 @@ OptionParser.new do |opts|
20
33
  options[:time] = true
21
34
  end
22
35
 
23
- opts.on("-l", "--loop", "Loop forever (default)") do
24
- options[:loop] = true
25
- end
26
-
27
36
  opts.on("-w", "--wipe", "Wipe output each loop iteration") do
28
37
  options[:wipe] = true
29
38
  end
30
39
 
31
- opts.on("-c", "--clear", "Clear the screen before starting (default for --loop)") do
32
- options[:clear] = true
33
- end
34
40
  end.parse!
35
41
 
36
- if options[:clear]
37
- RubiksCli::Clear.screen
38
- end
42
+ RubiksCli::Clear.screen if options[:clear]
39
43
 
40
44
  if options[:scramble] && options[:time]
41
- RubiksCli::Solve.solve
45
+ RubiksCli::Solve.solve(options[:inspection])
42
46
  elsif options[:scramble]
43
47
  puts RubiksCli::Scrambler.get_scramble
44
48
  elsif options[:time]
45
- RubiksCli::Timer.time
49
+ RubiksCli::Timer.start(options[:inspection])
46
50
  else
47
51
  RubiksCli::Clear.screen
48
- RubiksCli::Solve.loop(options[:wipe])
52
+ RubiksCli::Solve.loop(options[:wipe], options[:inspection])
49
53
  end
@@ -4,8 +4,12 @@ module RubiksCli
4
4
  system("clear") || system("cls")
5
5
  end
6
6
 
7
+ def self.current_line
8
+ print "\r\e[K"
9
+ end
10
+
7
11
  def self.line_above
8
- print "\e[1A\e[K\n"
12
+ print "\e[1A\r\e[K\n"
9
13
  end
10
14
  end
11
15
  end
@@ -5,20 +5,20 @@ require_relative 'scrambler'
5
5
 
6
6
  module RubiksCli
7
7
  class Solve
8
- def self.solve
8
+ def self.solve(inspection)
9
9
  puts Scrambler.get_scramble
10
10
  gets
11
11
  Clear.line_above
12
- Timer.show
12
+ Timer.start(inspection)
13
13
  end
14
14
 
15
- def self.loop(clear_screen)
15
+ def self.loop(clear_screen, inspection)
16
16
  Help.loop
17
17
  Kernel.loop do
18
18
  begin
19
19
  input = gets.chomp
20
20
  clear_screen ? Clear.screen : Clear.line_above
21
- process_input(input)
21
+ process_input(input, inspection)
22
22
  rescue SystemExit
23
23
  exit
24
24
  end
@@ -26,7 +26,7 @@ module RubiksCli
26
26
  end
27
27
 
28
28
  private
29
- def self.process_input(cmd)
29
+ def self.process_input(cmd, inspection)
30
30
  case cmd.downcase
31
31
  when 'n'
32
32
  puts Scrambler.get_scramble
@@ -37,7 +37,7 @@ module RubiksCli
37
37
  when 'q'
38
38
  raise SystemExit
39
39
  else
40
- Timer.show
40
+ Timer.start(inspection)
41
41
  puts "\n#{Scrambler.get_scramble}"
42
42
  end
43
43
  end
@@ -45,5 +45,5 @@ module RubiksCli
45
45
  end
46
46
 
47
47
  if __FILE__ == $0
48
- RubiksCli::Solve.solve
48
+ RubiksCli::Solve.loop(true, false)
49
49
  end
@@ -3,7 +3,13 @@ require_relative 'clear'
3
3
 
4
4
  module RubiksCli
5
5
  class Timer
6
- def self.show
6
+ INSPECTION_TIME = 15
7
+
8
+ def self.start(inspection)
9
+ if inspection
10
+ self.inspection
11
+ end
12
+ Clear.current_line
7
13
  puts "\r#{self.time.round(3)}"
8
14
  end
9
15
 
@@ -12,13 +18,35 @@ module RubiksCli
12
18
 
13
19
  STDIN.raw do
14
20
  loop do
15
- print "\r#{(Time.now - start).round(1)}"
16
- break if STDIN.wait_readable(0.01)
21
+ elapsed = Time.now - start
22
+ print "\r#{elapsed.round(1)}"
23
+ return elapsed if STDIN.wait_readable(0.1)
17
24
  end
18
- STDIN.read_nonblock(1) rescue nil
25
+ ensure
26
+ STDIN.getch rescue nil
19
27
  end
28
+ end
29
+
30
+ def self.inspection
31
+ STDIN.raw do
32
+ (0...INSPECTION_TIME).each do |i|
33
+ print "\rInspection: #{i}"
34
+ return if STDIN.wait_readable(1)
35
+ end
20
36
 
21
- return Time.now - start
37
+ print "\r+2"
38
+ 2.times do
39
+ return if STDIN.wait_readable(1)
40
+ end
41
+
42
+ print "\rDNF"
43
+ ensure
44
+ STDIN.getch rescue nil
45
+ end
22
46
  end
23
47
  end
24
48
  end
49
+
50
+ if __FILE__ == $0
51
+ RubiksCli::Timer.start(true)
52
+ end
@@ -1,3 +1,3 @@
1
1
  module RubiksCli
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubiks-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Scott