This commit is contained in:
John Bintz 2010-12-09 16:20:21 -05:00
parent afbdee688a
commit 234a6734b3
15 changed files with 388 additions and 0 deletions

8
.screenie Normal file
View File

@ -0,0 +1,8 @@
session :first do
screen "bundle exec autotest", :title => 'autotest'
screen!
end
session :second do
screen %{echo "cats"}
end

54
Gemfile.lock Normal file
View File

@ -0,0 +1,54 @@
PATH
remote: .
specs:
screenie (0.0.1)
thor
GEM
remote: http://rubygems.org/
specs:
ZenTest (4.4.1)
aruba (0.2.7)
background_process
cucumber (~> 0.10.0)
autotest (4.4.6)
ZenTest (>= 4.4.1)
background_process (1.2)
builder (3.0.0)
cucumber (0.10.0)
builder (>= 2.1.2)
diff-lcs (~> 1.1.2)
gherkin (~> 2.3.2)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
diff-lcs (1.1.2)
gherkin (2.3.2)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
json (1.4.6)
mocha (0.9.10)
rake
rake (0.8.7)
rspec (2.2.0)
rspec-core (~> 2.2)
rspec-expectations (~> 2.2)
rspec-mocks (~> 2.2)
rspec-core (2.2.1)
rspec-expectations (2.2.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.2.0)
term-ansicolor (1.0.5)
thor (0.14.6)
PLATFORMS
ruby
DEPENDENCIES
aruba
autotest
bundler (>= 1.0.0)
cucumber
mocha
rspec
screenie!
thor

View File

@ -0,0 +1 @@
Autotest.add_discovery { "rspec2" }

33
bin/screenie Executable file
View File

@ -0,0 +1,33 @@
#!which ruby
require 'getoptlong'
require 'screenie/dsl/builder'
opt = GetoptLong.new(
[ '--input', '-i', GetoptLong::REQUIRED_ARGUMENT ]
)
files = %w{.screenie ~/.screenie}
opt.each do |key, value|
case key
when '--input'
files = [ value ]
end
end
session_name = ARGV.shift
files.each do |path|
if File.exist?(target = File.expand_path(path))
sessions = Screenie::DSL::Builder.new(File.read(target))
if !session_name || session_name.empty?
session = sessions.first
else
session = sessions[session_name.to_sym]
end
session.to_cmd.each { |cmd| system cmd }
end
end

0
lib/screenie/cli.rb Normal file
View File

View File

@ -0,0 +1,35 @@
require 'screenie/dsl/session'
module Screenie
module DSL
class Builder
attr_reader :sessions
def initialize(code = '', &block)
@sessions = []
if !code.empty?
instance_eval(code)
else
instance_eval(&block)
end
end
def session(name = nil, &block)
name ||= "screenie-#{Time.now.to_i}"
session = Session.new(name.to_sym, &block)
@sessions << session
end
def first
@sessions.first
end
def [](key)
@sessions.find { |session| session.name == key }
end
end
end
end

View File

@ -0,0 +1,47 @@
module Screenie
module DSL
class Screen
attr_accessor :screen_id
def initialize(*options)
@options = options
@screen_id = nil
if @options.first.kind_of?(::Fixnum)
@screen_id = @options.shift
end
end
def stuff
output = [ %{-p #{@screen_id || 0} stuff} ]
if @options.first.kind_of?(::String)
output << %{"#{@options.first}\n"}
end
output * ' '
end
def screen
title = nil
if @options.last.kind_of?(::Hash)
opts = @options.last
title = opts[:title]
end
if @screen_id == 0
output = []
output << %{-p 0 title "#{title}"} if title
else
output = %w{screen}
output << %{-t "#{title}"} if title
output << (@screen_id || 0)
end
output * ' '
end
end
end
end

View File

@ -0,0 +1,54 @@
require 'screenie/dsl/screen'
module Screenie
module DSL
class Session
attr_accessor :name
def initialize(name = '', code = '', &block)
@name = name
@screens = []
@start_screen = 0
@start_screen_to_use = nil
if !code.empty?
instance_eval(code)
else
instance_eval(&block)
end
end
def screen(*opts)
@screens << Screen.new(*opts)
end
def screen!(*opts)
@start_screen_to_use = Screen.new(*opts)
@screens << @start_screen_to_use
end
def to_cmd
output = [ %{screen -dmS "#{@name}"} ]
available_screen_ids = (0..9).to_a
output += @screens.collect { |screen|
if !screen.screen_id
screen.screen_id = available_screen_ids.shift
end
commands = []
commands << %{screen -X -S "#{@name}" #{screen.screen}} if !screen.screen.empty?
commands << %{screen -X -S "#{@name}" #{screen.stuff}}
}.flatten
@start_screen = @start_screen_to_use.screen_id if @start_screen_to_use
output << %{screen -x "#{@name}" -p #{@start_screen}}
output
end
end
end
end

View File

@ -17,6 +17,9 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec"
s.add_development_dependency "mocha"
s.add_development_dependency "autotest"
s.add_development_dependency "cucumber"
s.add_development_dependency "aruba"
s.add_dependency 'thor'
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact

View File

@ -0,0 +1,24 @@
require 'spec_helper'
require 'screenie/dsl/builder'
describe Screenie::DSL::Builder do
describe '#sessions' do
context 'from block' do
subject { Screenie::DSL::Builder.new { session("cats") { } }}
specify { subject[:cats].should_not be_nil }
end
context 'from code' do
subject { Screenie::DSL::Builder.new(%{session("cats") { } })}
specify { subject[:cats].should_not be_nil }
end
end
describe '#first' do
subject { Screenie::DSL::Builder.new { session do; end }}
its(:first) { should be_a_kind_of(Screenie::DSL::Session) }
end
end

View File

@ -0,0 +1,48 @@
require 'spec_helper'
require 'screenie/dsl/screen'
describe Screenie::DSL::Screen do
describe '#to_cmd' do
let(:screen) { Screenie::DSL::Screen.new(*params) }
subject { screen }
context 'blank' do
let(:params) { [] }
its(:screen) { should == 'screen 0' }
end
context 'with command' do
let(:params) { ["command"] }
its(:screen) { should == 'screen 0' }
its(:stuff) { should == %{-p 0 stuff "command
"} }
end
context 'with number id' do
let(:params) { [ 1 ] }
its(:screen) { should == "screen 1" }
specify { screen.screen_id.should == 1 }
end
context 'with number id and command' do
let(:params) { [ 1, "command" ] }
its(:screen) { should == "screen 1" }
its(:stuff) { should == %{-p 1 stuff "command
"} }
specify { screen.screen_id.should == 1 }
end
context 'with title' do
let(:params) { [ { :title => 'My title' } ] }
its(:screen) { should == %{screen -t "My title" 0} }
specify { screen.screen_id.should == nil }
end
end
end

View File

@ -0,0 +1,66 @@
require 'spec_helper'
require 'screenie/dsl/session'
describe Screenie::DSL::Session do
describe '#to_cmd' do
context 'one screen' do
subject {
Screenie::DSL::Session.new("my-session") { screen "test" }.to_cmd
}
it { should == [
%{screen -dmS "my-session"},
%{screen -X -S "my-session" -p 0 stuff "test
"},
%{screen -x "my-session" -p 0}
] }
end
context 'two screens' do
subject {
Screenie::DSL::Session.new("my-session") { screen "test"; screen "test2" }.to_cmd
}
it { should == [
%{screen -dmS "my-session"},
%{screen -X -S "my-session" -p 0 stuff "test
"},
%{screen -X -S "my-session" screen 1},
%{screen -X -S "my-session" -p 1 stuff "test2
"},
%{screen -x "my-session" -p 0}
] }
end
end
describe 'from string' do
subject {
Screenie::DSL::Session.new("my-session", <<-EOR).to_cmd
screen "test"
EOR
}
it { should == [
%{screen -dmS "my-session"},
%{screen -X -S "my-session" -p 0 stuff "test
"},
%{screen -x "my-session" -p 0}
] }
end
describe 'screen!' do
subject {
Screenie::DSL::Session.new("my-session") { screen "test"; screen! "test2" }.to_cmd
}
it { should == [
%{screen -dmS "my-session"},
%{screen -X -S "my-session" -p 0 stuff "test
"},
%{screen -X -S "my-session" screen 1},
%{screen -X -S "my-session" -p 1 stuff "test2
"},
%{screen -x "my-session" -p 1}
] }
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Screenie do
end

View File

@ -0,0 +1,3 @@
RSpec.configure do |config|
config.mock_with :mocha
end

7
test/screenie.config Normal file
View File

@ -0,0 +1,7 @@
session :testing do
screen %{bundle exec autotest}, :name => 'autotest'
screen %{rails s}, :name => 'rails'
screen :name => 'command prompt'
select :first
end