cigarette 1.2 → 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.
@@ -1,26 +1,26 @@
1
1
  require 'curses'
2
2
  require 'yaml'
3
- require 'cigarette/numeric.rb'
3
+ require 'cigarette/colors'
4
+ require 'cigarette/numeric'
5
+ require 'cigarette/rvm'
4
6
 
5
7
  class Cigarette
8
+ include Colors
6
9
 
7
- DEFAULT = Curses::A_NORMAL
8
- BLACK = 0
9
- RED = 1
10
- GREEN = 2
11
- YELLOW = 3
12
- BLUE = 4
13
- MAGENTA = 5
14
- CYAN = 6
15
- WHITE = 7
16
-
17
- VERSION = "1.1"
10
+ VERSION = "2.0"
18
11
  # Hope.
19
12
  CANCER_DO_NOT_APPEAR = 42
20
13
 
21
14
  def initialize
22
15
  begin
23
16
  cnf = YAML::load(File.open("#{Dir.pwd}/.cigarette"))
17
+ unless cnf["rvm"].nil?
18
+ @rubies = cnf["rvm"]
19
+ raise "rvm error in yaml. You have to put a list. (-)" unless @rubies.is_a? Array
20
+ else
21
+ RVM.use_system!
22
+ @rubies = [RUBY_VERSION]
23
+ end
24
24
  @time = (cnf[:each] || cnf['each']).to_i
25
25
  @next_check = Time.now.to_i + @time
26
26
  @command = cnf[:command] || cnf['command']
@@ -31,37 +31,64 @@ class Cigarette
31
31
  rescue Exception => e
32
32
  abort "Problem during .cigarette loading: #{e.message}"
33
33
  end
34
- init_curses
35
34
  deploy_trap
35
+ init_curses
36
+ roll_baby_roll!
36
37
  lighter_please!
37
38
  end
38
39
 
39
40
  private
40
41
 
41
- def display_main_screen
42
+ def display_main_screen(status, output, time, color = DEFAULT)
42
43
  Curses.clear
44
+ display_menu
43
45
  display(0,0, "cigarette - Version #{VERSION}")
44
- display(2, 10, "#{@banner} - #{@current_time.strftime("at: %T")}")
45
- display(2, 2, "STATUS:")
46
- display(4, 0, @output)
46
+ display(4, 8, "#{status}", color)
47
+ padding_for_time = 8 + status.length
48
+ display(4, padding_for_time," - #{time.strftime("%T")}")
49
+ display(4, 0, "STATUS:")
50
+ display(6, 0, output)
47
51
  Curses.refresh
48
52
  end
49
53
 
50
54
  def lighter_please!
55
+ #initial position
56
+ @pos = 0
51
57
  while CANCER_DO_NOT_APPEAR
52
58
  sleep 0.1
53
- if @current_time.nil? || time_to_light_up?
54
- @current_time = Time.now if @current_time.nil?
55
- @output = `#{@command} 2>&1`
56
- status = $?.success? unless defined? status
57
- current_status = $?.success?
58
- @banner = ($?.success? ? "SUCCESS" : "ERROR(S)")
59
- display_main_screen
60
- status = current_status
59
+ case Curses.getch
60
+ when Curses::Key::RIGHT then move_right
61
+ when Curses::Key::LEFT then move_left
62
+ when ?q then onsig
61
63
  end
62
64
  end
63
65
  end
64
66
 
67
+ def roll_baby_roll!
68
+ @current_rb = @rubies.first
69
+ @t_array = []
70
+ @outputs = {}
71
+ @rubies.each { |ruby|
72
+ @t_array << Thread.new {
73
+ # Run test(s) at cigarette start
74
+ next_check = 0
75
+ while CANCER_DO_NOT_APPEAR
76
+ time = Time.now.to_i
77
+ if time >= next_check
78
+ @outputs[ruby.to_s] = RVM.run(ruby) { @command }
79
+ next_check = time + @time
80
+ if @current_rb.eql?(ruby)
81
+ out = @outputs[ruby.to_s]
82
+ display_main_screen(out[:status], out[:output],
83
+ out[:time], out[:color])
84
+ end
85
+ end
86
+ sleep 0.1
87
+ end
88
+ }
89
+ }
90
+ end
91
+
65
92
  def time_to_light_up?
66
93
  @current_time = Time.now
67
94
  if @current_time.to_i >= @next_check
@@ -77,19 +104,18 @@ class Cigarette
77
104
  Curses.init_screen
78
105
  Curses.stdscr.keypad(true) # enable arrow keys
79
106
  Curses.start_color
80
- Curses.init_pair(RED, RED, BLACK)
107
+ Curses.init_pair(Colors::RED, RED, BLACK)
81
108
  Curses.init_pair(GREEN, GREEN, BLACK)
82
109
  Curses.init_pair(MAGENTA, MAGENTA, WHITE)
83
110
  Curses.init_pair(CYAN, CYAN, BLACK)
84
- display(2, 2, "STATUS:")
85
- display(2, 10, "WAITING")
111
+ display(0,0, "WAIT, INITIALIZATION...")
86
112
  Curses.refresh
87
113
  end
88
114
 
89
115
  def deploy_trap
90
- for i in 1 .. 15 # SIGHUP .. SIGTERM
116
+ for i in 1..15 # SIGHUP .. SIGTERM
91
117
  if trap(i, "SIG_IGN") != 0 then # 0 for SIG_IGN
92
- trap(i) {|sig| onsig(sig) }
118
+ trap(i) { |sig| onsig(sig) }
93
119
  end
94
120
  end
95
121
  end
@@ -99,9 +125,54 @@ class Cigarette
99
125
  Curses.attron(Curses.color_pair(color | DEFAULT)) { Curses.addstr(text) }
100
126
  end
101
127
 
102
- def onsig(sig)
128
+ def display_menu
129
+ padding = 0
130
+ @rubies.each { |ruby|
131
+ if !@outputs[ruby.to_s].nil?
132
+ color = @outputs[ruby.to_s][:color]
133
+ else
134
+ color = RED
135
+ end
136
+ color = MAGENTA if ruby.eql?(@current_rb) && @rubies.length > 1
137
+ display(2, padding, ruby, color)
138
+ padding += 8
139
+ }
140
+ end
141
+
142
+ def inc_pos
143
+ if @pos == @rubies.length - 1
144
+ @pos = 0
145
+ else
146
+ @pos += 1
147
+ end
148
+ end
149
+
150
+ def move_right
151
+ inc_pos
152
+ @current_rb = @rubies[@pos]
153
+ out = @outputs[@rubies[@pos]]
154
+ display_main_screen(out[:status], out[:output], out[:time], out[:color])
155
+ end
156
+
157
+ def dec_pos
158
+ if @pos == 0
159
+ @pos = @rubies.length - 1
160
+ else
161
+ @pos -= 1
162
+ end
163
+ end
164
+
165
+ def move_left
166
+ dec_pos
167
+ @current_rb = @rubies[@pos]
168
+ out = @outputs[@rubies[@pos]]
169
+ display_main_screen(out[:status], out[:output], out[:time], out[:color])
170
+ end
171
+
172
+ def onsig(sig = nil)
103
173
  Curses.close_screen
104
- exit sig
174
+ @t_array.each { |t| Thread.kill(t) } unless @t_array.nil?
175
+ !sig.nil? ? exit(sig) : exit(0)
105
176
  end
106
177
 
107
178
  end
@@ -0,0 +1,13 @@
1
+ module Colors
2
+
3
+ DEFAULT = Curses::A_NORMAL
4
+ BLACK = 0
5
+ RED = 1
6
+ GREEN = 2
7
+ YELLOW = 3
8
+ BLUE = 4
9
+ MAGENTA = 5
10
+ CYAN = 6
11
+ WHITE = 7
12
+
13
+ end
@@ -0,0 +1,32 @@
1
+ module RVM
2
+ include Colors
3
+
4
+ @@rvm = true
5
+
6
+ def self.use_it!
7
+ @@rvm = true
8
+ end
9
+
10
+ def self.use_system!
11
+ @@rvm = false
12
+ end
13
+
14
+ def self.run(ruby)
15
+ if block_given?
16
+ h = {}
17
+ h[:time] = Time.now
18
+ h[:ruby] = ruby
19
+ if @@rvm
20
+ h[:output] = `rvm #{ruby} do #{yield} 2>&1`
21
+ else
22
+ h[:output] = `#{yield} 2>&1`
23
+ end
24
+ h[:status] = $?.success? ? "SUCCESS" : "ERROR(S)"
25
+ h[:color] = $?.success? ? GREEN : RED
26
+ h
27
+ else
28
+ raise "You need to pass a block for RVM.run method."
29
+ end
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,67 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cigarette
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: '2.0'
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- version: "1.2"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Thibaut Deloffre
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-12-26 00:00:00 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
18
13
  dependencies: []
19
-
20
14
  description: Tiny test tool
21
15
  email: tib@rocknroot.org
22
- executables:
16
+ executables:
23
17
  - cigarette
24
18
  extensions: []
25
-
26
- extra_rdoc_files:
19
+ extra_rdoc_files:
27
20
  - LICENSE.txt
28
- files:
21
+ files:
29
22
  - lib/cigarette.rb
30
23
  - lib/cigarette/numeric.rb
24
+ - lib/cigarette/rvm.rb
25
+ - lib/cigarette/colors.rb
31
26
  - LICENSE.txt
32
27
  - bin/cigarette
33
28
  homepage: https://github.com/TibshoOT/cigarette
34
- licenses:
29
+ licenses:
35
30
  - BSD
36
31
  post_install_message:
37
32
  rdoc_options: []
38
-
39
- require_paths:
33
+ require_paths:
40
34
  - lib
41
- required_ruby_version: !ruby/object:Gem::Requirement
35
+ required_ruby_version: !ruby/object:Gem::Requirement
42
36
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
50
- required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
42
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
59
47
  requirements: []
60
-
61
48
  rubyforge_project:
62
- rubygems_version: 1.8.24
49
+ rubygems_version: 1.8.23
63
50
  signing_key:
64
51
  specification_version: 3
65
52
  summary: Tiny test tool
66
53
  test_files: []
67
-