Class: Autotest::Tmux
- Inherits:
-
Object
- Object
- Autotest::Tmux
- Defined in:
- lib/autotest/tmux.rb
Overview
Autotest::Tmux displays autotest/autospec progress on tmux status-right.
Features
-
Screenshots aren’t available yet. (but, almost same as autotest_screen.)
Synopsis
$HOME/.autotest
require 'autotest/tmux'
# Autotest::Tmux.statusright = '"#22T" %H:%M %d-%b-%y (your statusright)'
-
To prevent server information (like “set option: status-right -> …”), you should start tmux server with -q option first.
Constant Summary collapse
- DEFAULT_STATUSRIGHT =
'"#22T" %H:%M %d-%b-%y'
- DEFAULT_TMUX_CMD =
'tmux'
- DEFAULT_UTEST_CLASSES =
['Autotest', 'Autotest::Rails']
- DEFAULT_RSPEC_CLASSES =
['Autotest::Rspec', 'Autotest::Rspec2', 'Autotest::RailsRspec', 'Autotest::RailsRspec2', 'Autotest::MerbRspec', 'Autotest::CucumberRspec2']
- SCREEN_COLOR =
{ :black => ['white', 'black'], :green => ['white', 'green'], :yellow => ['black', 'yellow'], :red => ['white', 'red'] }
Class Method Summary collapse
- .clear ⇒ Object
- .execute? ⇒ Boolean
- .message(msg = statusright, sc = :black) ⇒ Object
- .parse_output(output, class_name) ⇒ Object
- .rspec_classes ⇒ Object
- .rspec_classes=(rc) ⇒ Object
- .run_tmux_session? ⇒ Boolean
- .send_cmd(msg) ⇒ Object
- .statusright ⇒ Object
- .statusright=(s) ⇒ Object
- .tmux_cmd ⇒ Object
- .tmux_cmd=(tc) ⇒ Object
- .utest_classes ⇒ Object
- .utest_classes=(uc) ⇒ Object
Class Method Details
.clear ⇒ Object
59 60 61 |
# File 'lib/autotest/tmux.rb', line 59 def self.clear send_cmd('') end |
.execute? ⇒ Boolean
67 68 69 |
# File 'lib/autotest/tmux.rb', line 67 def self.execute? !($TESTING || !run_tmux_session?) end |
.message(msg = statusright, sc = :black) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/autotest/tmux.rb', line 50 def self.(msg=statusright, sc=:black) msg ||= statusright # when nil given sc ||= :black # when nil given col = SCREEN_COLOR[sc] msg = "#[fg=#{col[0]},bg=#{col[1]}] #{msg} #[default]" unless msg == statusright send_cmd(msg) end |
.parse_output(output, class_name) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/autotest/tmux.rb', line 71 def self.parse_output(output, class_name) case class_name when *utest_classes results = output.scan(/(\d+)\s*failures?,\s*(\d+)\s*errors?/).first num_failures, num_errors = results.map{|r| r.to_i} if num_failures > 0 || num_errors > 0 result = {:message => "Red F:#{num_failures} E:#{num_errors}", :color => :red} else result = {:message => 'All Green', :color => :green} end when *rspec_classes results = output.scan(/(\d+)\s*examples?,\s*(\d+)\s*failures?(?:,\s*(\d+)\s*pendings?)?/).first if results num_examples, num_failures, num_pendings = results.map{|r| r.to_i} if num_failures > 0 result = {:message => "Fail F:#{num_failures} P:#{num_pendings}", :color => :red} elsif num_pendings > 0 result = {:message => "Pend F:#{num_failures} P:#{num_pendings}", :color => :yellow} else result = {:message => 'All Green', :color => :green} end else result = {:message => 'Unable to run tests', :color => :red} end end result || {:message => "Unknown class. (#{class_name})"} end |
.rspec_classes ⇒ Object
43 |
# File 'lib/autotest/tmux.rb', line 43 def self.rspec_classes; @rspec_classes || DEFAULT_RSPEC_CLASSES.dup; end |
.rspec_classes=(rc) ⇒ Object
44 |
# File 'lib/autotest/tmux.rb', line 44 def self.rspec_classes=(rc); @rspec_classes = rc; end |
.run_tmux_session? ⇒ Boolean
63 64 65 |
# File 'lib/autotest/tmux.rb', line 63 def self.run_tmux_session? system "#{tmux_cmd} has-session" end |
.send_cmd(msg) ⇒ Object
46 47 48 |
# File 'lib/autotest/tmux.rb', line 46 def self.send_cmd(msg) system "#{tmux_cmd} set status-right '#{msg.gsub("'", "\'")}'" end |
.statusright ⇒ Object
37 |
# File 'lib/autotest/tmux.rb', line 37 def self.statusright; @statusright || DEFAULT_STATUSRIGHT.dup; end |
.statusright=(s) ⇒ Object
38 |
# File 'lib/autotest/tmux.rb', line 38 def self.statusright=(s); @statusright = s; end |
.tmux_cmd ⇒ Object
39 |
# File 'lib/autotest/tmux.rb', line 39 def self.tmux_cmd; @tmux_cmd || DEFAULT_TMUX_CMD.dup; end |
.tmux_cmd=(tc) ⇒ Object
40 |
# File 'lib/autotest/tmux.rb', line 40 def self.tmux_cmd=(tc); @tmux_cmd = tc; end |
.utest_classes ⇒ Object
41 |
# File 'lib/autotest/tmux.rb', line 41 def self.utest_classes; @utest_classes || DEFAULT_UTEST_CLASSES.dup; end |
.utest_classes=(uc) ⇒ Object
42 |
# File 'lib/autotest/tmux.rb', line 42 def self.utest_classes=(uc); @utest_classes = uc; end |