rubiks-cli 1.1.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72146381cce3abc1d2944045ca47fe73d75065fc31a51e2ce1cc1d219a7e1c6f
4
- data.tar.gz: afd5ba94c045ab5c6acb9a1845f8b0c7695f85028beddd945bd21cf9e53d5359
3
+ metadata.gz: b31d0f5c4d03e00788128265b7dbb190583673563adce67252c202f9e114f0a5
4
+ data.tar.gz: 046d15a7724fa53739edf3c5dde5b226c925ab8ef419f50238b4b85515d732ff
5
5
  SHA512:
6
- metadata.gz: 8d924fd2eafcc87b24ebe44b84045fedfefa1abea045cc1bebd45e83e9dfcc311d32fafaedd00bf608349c1566e3a141ad70f3c26f2df1f0057cbad4030c98cc
7
- data.tar.gz: 66e7ac7bb6e1f382c641a1e201e5d27ca58d66b89a8429c8fb4e1d6ea8ab178edfe2ba36d996cc0def8934a24b8a541e518529a2ee0c7fcca354b3bda047c83e
6
+ metadata.gz: 47d2f102cd05f55b0fc4cd36f47c1e3830c9541ec79e57b10121690a96f969b2a3fd1a50cd3975d2e2e5fe20b75dbce05989bb78097ff26b071f2f66a37a8f07
7
+ data.tar.gz: dc0b0fb6338108e15a47cb28752db0783ddd873ab71186c2ab8fdb33d41961780bc730217a28013207f68dc9232d8d1777a2393651a001402c8cf1aeb0e3d4b9
data/README.md CHANGED
@@ -18,3 +18,4 @@ rubiks
18
18
  - Press any key to stop timing
19
19
  - Type 'n' for a new scramble
20
20
  - Type 'q' to quit
21
+ - Type 'h' or '?' for help (this message)
data/bin/rubiks CHANGED
@@ -1,25 +1,49 @@
1
1
  #!/usr/bin/env ruby
2
-
2
+ require 'optparse'
3
3
  require 'rubiks_cli'
4
4
 
5
- HELP = "Press Enter to start timing\nPress any key to stop timing\nType 'q' to quit\nType 'n' for a new scramble\nType 'h' or '?' for this message"
5
+ options = {
6
+ scramble: false,
7
+ time: false,
8
+ loop: true,
9
+ clear: false,
10
+ wipe: false,
11
+ }
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: rubiks [options]"
6
14
 
7
- cmd = 'n'
15
+ opts.on("-s", "--scramble", "Generate scramble") do
16
+ options[:scramble] = true
17
+ end
8
18
 
9
- while true
10
- RubiksCli::Timer.clear_screen
19
+ opts.on("-t", "--time", "Start timer") do
20
+ options[:time] = true
21
+ end
22
+
23
+ opts.on("-l", "--loop", "Loop forever (default)") do
24
+ options[:loop] = true
25
+ end
11
26
 
12
- case cmd.downcase
13
- when 'n'
14
- puts RubiksCli::Scrambler.get_scramble
15
- when 'q'
16
- break
17
- when 'h', '?'
18
- puts HELP
19
- else
20
- RubiksCli::Timer.start
21
- puts RubiksCli::Scrambler.get_scramble
27
+ opts.on("-w", "--wipe", "Wipe output each loop iteration") do
28
+ options[:wipe] = true
22
29
  end
23
30
 
24
- cmd = gets.chomp
31
+ opts.on("-c", "--clear", "Clear the screen before starting (default for --loop)") do
32
+ options[:clear] = true
33
+ end
34
+ end.parse!
35
+
36
+ if options[:clear]
37
+ RubiksCli::Clear.screen
38
+ end
39
+
40
+ if options[:scramble] && options[:time]
41
+ RubiksCli::Solve.solve
42
+ elsif options[:scramble]
43
+ puts RubiksCli::Scrambler.get_scramble
44
+ elsif options[:time]
45
+ RubiksCli::Timer.time
46
+ else
47
+ RubiksCli::Clear.screen
48
+ RubiksCli::Solve.loop(options[:wipe])
25
49
  end
@@ -0,0 +1,11 @@
1
+ module RubiksCli
2
+ class Clear
3
+ def self.screen
4
+ system("clear") || system("cls")
5
+ end
6
+
7
+ def self.line_above
8
+ print "\e[1A\e[K\n"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module RubiksCli
2
+ class Help
3
+ LOOP = "Press Enter to start timing\nPress any key to stop timing\nType 'n' for a new scramble\nType 'c' to clear the screen\nType 'h' or '?' for this message\nType 'q' to quit"
4
+
5
+ def self.loop
6
+ puts LOOP
7
+ end
8
+ end
9
+ end
@@ -24,8 +24,9 @@ module RubiksCli
24
24
  moves.join(", ")
25
25
  end
26
26
 
27
+ private
27
28
  def self.get_move
28
29
  FACES.sample + SUFFIXES.sample
29
30
  end
30
31
  end
31
- end
32
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'clear'
2
+ require_relative 'help'
3
+ require_relative 'timer'
4
+ require_relative 'scrambler'
5
+
6
+ module RubiksCli
7
+ class Solve
8
+ def self.solve
9
+ puts Scrambler.get_scramble
10
+ gets
11
+ Clear.line_above
12
+ Timer.show
13
+ end
14
+
15
+ def self.loop(clear_screen)
16
+ Help.loop
17
+ Kernel.loop do
18
+ begin
19
+ input = gets.chomp
20
+ clear_screen ? Clear.screen : Clear.line_above
21
+ process_input(input)
22
+ rescue SystemExit
23
+ exit
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+ def self.process_input(cmd)
30
+ case cmd.downcase
31
+ when 'n'
32
+ puts Scrambler.get_scramble
33
+ when 'c'
34
+ Clear.screen
35
+ when 'h', '?'
36
+ Help.loop
37
+ when 'q'
38
+ raise SystemExit
39
+ else
40
+ Timer.show
41
+ puts "\n#{Scrambler.get_scramble}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ if __FILE__ == $0
48
+ RubiksCli::Solve.solve
49
+ end
@@ -1,10 +1,10 @@
1
1
  require 'io/console'
2
+ require_relative 'clear'
2
3
 
3
4
  module RubiksCli
4
5
  class Timer
5
-
6
- def self.clear_screen
7
- system("clear") || system("cls")
6
+ def self.show
7
+ puts "\r#{self.time.round(3)}"
8
8
  end
9
9
 
10
10
  def self.time
@@ -20,12 +20,5 @@ module RubiksCli
20
20
 
21
21
  return Time.now - start
22
22
  end
23
-
24
- def self.start
25
- clear_screen
26
- time = Timer.time
27
- clear_screen
28
- puts time.round(3)
29
- end
30
23
  end
31
- end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module RubiksCli
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/rubiks_cli.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require_relative "rubiks_cli/version"
2
2
  require_relative "rubiks_cli/scrambler"
3
3
  require_relative "rubiks_cli/timer"
4
+ require_relative "rubiks_cli/clear"
5
+ require_relative "rubiks_cli/help"
6
+ require_relative "rubiks_cli/solve"
4
7
 
5
8
  module RubiksCli
6
- end
9
+ end
data/rubiks-cli.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ["noah.scott.24@ucl.ac.uk"]
8
8
 
9
9
  spec.summary = "A command-line Rubik's Cube timer"
10
- spec.description = "A simple CLI tool for timing Rubik's Cube solves"
10
+ spec.description = "A CLI tool for generating scrambles and timing Rubik's Cube solves"
11
11
  spec.homepage = "https://github.com/noahsc0tt/rubiks-cli"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = ">= 2.7.0"
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Scott
@@ -9,7 +9,7 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: A simple CLI tool for timing Rubik's Cube solves
12
+ description: A CLI tool for generating scrambles and timing Rubik's Cube solves
13
13
  email:
14
14
  - noah.scott.24@ucl.ac.uk
15
15
  executables:
@@ -22,7 +22,10 @@ files:
22
22
  - Rakefile
23
23
  - bin/rubiks
24
24
  - lib/rubiks_cli.rb
25
+ - lib/rubiks_cli/clear.rb
26
+ - lib/rubiks_cli/help.rb
25
27
  - lib/rubiks_cli/scrambler.rb
28
+ - lib/rubiks_cli/solve.rb
26
29
  - lib/rubiks_cli/timer.rb
27
30
  - lib/rubiks_cli/version.rb
28
31
  - rubiks-cli.gemspec