termvana 0.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -0
- data/LICENSE.txt +22 -0
- data/READING.txt +7 -0
- data/README.rdoc +46 -0
- data/Rakefile +36 -0
- data/bin/termvana +4 -0
- data/lib/termvana.rb +15 -0
- data/lib/termvana/app/actions/home_action.rb +7 -0
- data/lib/termvana/app/actions/websocket_action.rb +34 -0
- data/lib/termvana/app/command_processor.rb +58 -0
- data/lib/termvana/app/commands/cd.rb +15 -0
- data/lib/termvana/app/commands/set.rb +17 -0
- data/lib/termvana/app/models/command.rb +42 -0
- data/lib/termvana/app/models/environment.rb +31 -0
- data/lib/termvana/app/models/request.rb +25 -0
- data/lib/termvana/app/models/response.rb +11 -0
- data/lib/termvana/application.rb +36 -0
- data/lib/termvana/config/routes.rb +6 -0
- data/lib/termvana/public/css/jquery.readline.css +11 -0
- data/lib/termvana/public/css/jquery.repl.css +15 -0
- data/lib/termvana/public/css/jquery.ui.autocomplete.css +347 -0
- data/lib/termvana/public/css/nirvana.css +63 -0
- data/lib/termvana/public/demo.html +9 -0
- data/lib/termvana/public/images/spinner.gif +0 -0
- data/lib/termvana/public/index.html +36 -0
- data/lib/termvana/public/js/jquery.hotkeys.js +99 -0
- data/lib/termvana/public/js/jquery.min.js +154 -0
- data/lib/termvana/public/js/jquery.readline.js +104 -0
- data/lib/termvana/public/js/jquery.repl.js +96 -0
- data/lib/termvana/public/js/jquery.ui.autocomplete.min.js +80 -0
- data/lib/termvana/public/js/nirvana.js +30 -0
- data/lib/termvana/version.rb +3 -0
- data/termvana.gemspec +28 -0
- metadata +159 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
== 0.2.0
|
2
|
+
* Tear out all ripl/fresh stuff, rebuild in Eventmachine
|
3
|
+
* Basic cucumber support
|
4
|
+
* Nifty iframe demo
|
5
|
+
* build simple site
|
6
|
+
_ fix timeout error when you run a long command and then other commands
|
7
|
+
* more specs for CD - home dir, expanded paths, CDPATH, multiple terminals
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2011 David Haslem
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/READING.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
== Description
|
2
|
+
A web-based shell that has autocompletion and readline behavior. It uses
|
3
|
+
websockets, repl.js, readline.js.
|
4
|
+
|
5
|
+
Goal is to have a fully usable shell for 80% of daily tasks, but with an awesome and hackable
|
6
|
+
UI built in HTML/CSS/jQuery - eventually this goal may require a specialized browser, Termkit style,
|
7
|
+
but initially I hope to get most functionality without taking that step.
|
8
|
+
|
9
|
+
== Install
|
10
|
+
Install the gem with:
|
11
|
+
|
12
|
+
gem install termvana
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
Your browser must have html5 websockets support.
|
17
|
+
|
18
|
+
To start the server
|
19
|
+
|
20
|
+
$ termvana
|
21
|
+
|
22
|
+
Termvana will be available on port 5432
|
23
|
+
|
24
|
+
Also notice that a subset of readline's functionality is available. Try C-l, C-r or C-p and they
|
25
|
+
should do what readline normally does. For more keybindings, see
|
26
|
+
{readline.js}[http://github.com/cldwalker/readline.js].
|
27
|
+
|
28
|
+
|
29
|
+
== Bugs/Issues
|
30
|
+
Please report them {on github}[http://github.com/cldwalker/nirvana/issues]. For javascript issues,
|
31
|
+
report them on {readline.js}[http://github.com/cldwalker/readline.js/issues] or
|
32
|
+
{repl.js}[http://github.com/cldwalker/repl.js/issues] as appropriate.
|
33
|
+
|
34
|
+
== Credits
|
35
|
+
* {rkh's brirb}[http://github.com/rkh/brirb]: Original prototype which inspired nirvana
|
36
|
+
* {cldwalker's nirvana}[http://github.com/cldwalker/nirvana]: Initial project inspiration, JS libs.
|
37
|
+
* {janlelis's fresh}[https://github.com/janlelis/fresh]
|
38
|
+
* {unconed's TermKit}[https://github.com/unconed/TermKit]
|
39
|
+
|
40
|
+
== License
|
41
|
+
termvana is MIT licensed. termvana comes bundled with other libraries which have the following
|
42
|
+
licenses: jquery (GPL2 and MIT), jquery.hotkeys plugin (no license), repl.js jquery plugin (MIT) and
|
43
|
+
readline.js jquery plugin (MIT).
|
44
|
+
|
45
|
+
== Todo
|
46
|
+
* Tests
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def gemspec
|
5
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Build the gem"
|
9
|
+
task :gem=>:gemspec do
|
10
|
+
sh "gem build .gemspec"
|
11
|
+
FileUtils.mkdir_p 'pkg'
|
12
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Install the gem locally"
|
16
|
+
task :install => :gem do
|
17
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Generate the gemspec"
|
21
|
+
task :generate do
|
22
|
+
puts gemspec.to_ruby
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Validate the gemspec"
|
26
|
+
task :gemspec do
|
27
|
+
gemspec.validate
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
desc 'Run tests'
|
32
|
+
task :test do |t|
|
33
|
+
sh 'bacon -q -Ilib -I. test/*_test.rb'
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :test
|
data/bin/termvana
ADDED
data/lib/termvana.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'termvana/version'
|
2
|
+
require 'termvana/application'
|
3
|
+
|
4
|
+
require 'thin'
|
5
|
+
|
6
|
+
|
7
|
+
module Termvana
|
8
|
+
def self.start(port = 5432, open = false)
|
9
|
+
filename = File.expand_path(File.dirname(__FILE__) + '/termvana/config.ru')
|
10
|
+
puts "Opening up tervana..."
|
11
|
+
Thread.new{ sleep 1; `open http://localhost:5432/`} if open
|
12
|
+
|
13
|
+
Thin::Runner.new("--max-persistent-conns 1024 --timeout 0 -R #{filename} -p #{port} start -e #{Termvana::Application.env}".split).run!
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Cramp::Websocket.backend = :thin
|
2
|
+
|
3
|
+
class Termvana::WebsocketAction < Cramp::Websocket
|
4
|
+
self.transport = :websocket
|
5
|
+
|
6
|
+
on_data :received_data
|
7
|
+
on_start :opened_conn
|
8
|
+
on_finish :closed_conn
|
9
|
+
|
10
|
+
attr_accessor :environment
|
11
|
+
|
12
|
+
def opened_conn
|
13
|
+
@environment = Termvana::Environment.new(:env => {"HOME" => ENV['HOME']})
|
14
|
+
@environment.messenger do |message|
|
15
|
+
render message.to_s
|
16
|
+
end
|
17
|
+
render Termvana::Response.new(:message => "Welcome to Nirvana. Websocket connected.", :type => :on_connect).to_s
|
18
|
+
# resulvt = Termvana::Runner.run ARGV
|
19
|
+
# send(result) unless result.to_s.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
def received_data(data)
|
23
|
+
command = Termvana::Request.new(data)
|
24
|
+
callable = Termvana::CommandProcessor.parse(environment, command)
|
25
|
+
callable.call
|
26
|
+
end
|
27
|
+
|
28
|
+
def closed_conn
|
29
|
+
# Ripl.shell.after_loop
|
30
|
+
STDERR.puts "Browser disconnecting."
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Termvana
|
2
|
+
class CommandProcessor < EventMachine::Connection
|
3
|
+
include EventMachine::Deferrable
|
4
|
+
attr_accessor :environment, :command
|
5
|
+
# https://gist.github.com/535644
|
6
|
+
#
|
7
|
+
def self.register(command_klass)
|
8
|
+
@command_list ||=[]
|
9
|
+
@command_list << command_klass
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse(environment, request)
|
13
|
+
@command_list ||= []
|
14
|
+
command_klass = @command_list.detect{|klass| klass.match?(request)}
|
15
|
+
if command_klass
|
16
|
+
command_klass.new(environment, request)
|
17
|
+
else
|
18
|
+
# Simple case - popen and set a timeout
|
19
|
+
lambda do
|
20
|
+
process = EM.popen(environment.runnable(request), self, environment)
|
21
|
+
process.callback do |data|
|
22
|
+
environment.send_message Termvana::Response.new(:message => data)
|
23
|
+
end
|
24
|
+
process.errback do |data|
|
25
|
+
environment.send_message Termvana::Response.new(:message => "Command timed out.", :type => :error)
|
26
|
+
end
|
27
|
+
process.timeout(10)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(environment)
|
33
|
+
@environment = environment
|
34
|
+
# @command = command
|
35
|
+
environment.setup
|
36
|
+
end
|
37
|
+
|
38
|
+
# In the command processor, we are sending/recieving data over an
|
39
|
+
# I/O pipe to a command
|
40
|
+
def prepare_and_run
|
41
|
+
# send_data "cd #{environment.cwd}\n"
|
42
|
+
# send_data command.full_command
|
43
|
+
# send_data "\n"
|
44
|
+
# send_data "exit\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def receive_data data
|
49
|
+
environment.send_message(Response.new(:message => data))
|
50
|
+
end
|
51
|
+
|
52
|
+
def unbind
|
53
|
+
cancel_timeout
|
54
|
+
# puts "exit status: #{get_status.exitstatus}"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Termvana
|
2
|
+
class CdCommand < Command
|
3
|
+
type :builtin
|
4
|
+
response :none
|
5
|
+
name "cd"
|
6
|
+
def call
|
7
|
+
dir = request[1] || "~"
|
8
|
+
Dir.chdir(environment.fullpath(dir))
|
9
|
+
environment.env["PWD"] = environment.cwd = Dir.pwd
|
10
|
+
finish
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Termvana::CommandProcessor.register(Termvana::CdCommand)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Termvana
|
2
|
+
class SetCommand < Command
|
3
|
+
type :builtin
|
4
|
+
response :none
|
5
|
+
name "set"
|
6
|
+
def call
|
7
|
+
key, val = request[1].match(/(.+)=(.+)/) do |matches|
|
8
|
+
[matches[1], matches[2]]
|
9
|
+
end
|
10
|
+
environment.env[key] = val
|
11
|
+
finish
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Termvana::CommandProcessor.register(Termvana::SetCommand)
|
17
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Termvana
|
2
|
+
class Command
|
3
|
+
attr_accessor :request, :environment
|
4
|
+
def initialize(environment, request)
|
5
|
+
@request = request
|
6
|
+
@environment = environment
|
7
|
+
end
|
8
|
+
|
9
|
+
def finish
|
10
|
+
if !self.class.response || self.class.response == :none
|
11
|
+
respond_with :null
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_with(opts = {})
|
16
|
+
if opts == :null
|
17
|
+
environment.send_message Termvana::Response.new
|
18
|
+
elsif data = opts.delete(:text)
|
19
|
+
environment.send_message Termvana::Response.new(:message => data)
|
20
|
+
elsif data = opts.delete(:error)
|
21
|
+
environment.send_message Termvana::Response.new(:message => data, :type => :error)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def self.type(arg = false)
|
27
|
+
@type = arg if arg
|
28
|
+
@type
|
29
|
+
end
|
30
|
+
def self.response(arg = false)
|
31
|
+
@response = arg if arg
|
32
|
+
@response
|
33
|
+
end
|
34
|
+
def self.name(arg = false)
|
35
|
+
@name = arg if arg
|
36
|
+
@name
|
37
|
+
end
|
38
|
+
def self.match?(request)
|
39
|
+
self.name.match(/^#{request[0]}$/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Termvana
|
2
|
+
class Environment
|
3
|
+
include Virtus
|
4
|
+
attribute :cwd, String, :default => "~"
|
5
|
+
attribute :env, Hash, :default => {}
|
6
|
+
def messenger
|
7
|
+
@messenger = Proc.new
|
8
|
+
end
|
9
|
+
def send_message(response)
|
10
|
+
@messenger[response]
|
11
|
+
end
|
12
|
+
def fullpath(path)
|
13
|
+
path.gsub("~", home)
|
14
|
+
end
|
15
|
+
def home
|
16
|
+
env['HOME']
|
17
|
+
end
|
18
|
+
def setup
|
19
|
+
Dir.chdir(fullpath(cwd))
|
20
|
+
end
|
21
|
+
def envs
|
22
|
+
my_envs = env.map do |k, v|
|
23
|
+
"#{k.upcase}=#{v}"
|
24
|
+
end.join(" ")
|
25
|
+
end
|
26
|
+
def runnable(request)
|
27
|
+
"env -i #{envs} #{request.full_command}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Termvana
|
2
|
+
class Request
|
3
|
+
include Virtus
|
4
|
+
attribute :full_command, String
|
5
|
+
attribute :type, Symbol, :default => :standard
|
6
|
+
def initialize(*args)
|
7
|
+
if args.first.is_a? String
|
8
|
+
command = JSON.parse(args.first).symbolize_keys
|
9
|
+
super(command)
|
10
|
+
else
|
11
|
+
super(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](*args)
|
16
|
+
@tokens ||= Shellwords.split(full_command)
|
17
|
+
@tokens[*args]
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
attributes.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'cramp'
|
2
|
+
require 'thin'
|
3
|
+
require 'bundler'
|
4
|
+
require 'http_router'
|
5
|
+
require 'async-rack'
|
6
|
+
require 'virtus'
|
7
|
+
require 'active_support/json'
|
8
|
+
|
9
|
+
module Termvana
|
10
|
+
class Application
|
11
|
+
|
12
|
+
def self.root(path = nil)
|
13
|
+
@_root ||= File.expand_path(File.dirname(__FILE__))
|
14
|
+
path ? File.join(@_root, path.to_s) : @_root
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.env
|
18
|
+
@_env ||= (ENV['RACK_ENV'] || 'development')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.routes
|
22
|
+
@_routes ||= eval(File.read("#{root}/config/routes.rb"))
|
23
|
+
end
|
24
|
+
|
25
|
+
# Initialize the application
|
26
|
+
def self.initialize!
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Preload application classes
|
33
|
+
Dir["#{File.expand_path(File.dirname(__FILE__))}/app/models/*.rb"].each {|f| require f}
|
34
|
+
Dir["#{File.expand_path(File.dirname(__FILE__))}/app/command_processor.rb"].each {|f| require f}
|
35
|
+
Dir["#{File.expand_path(File.dirname(__FILE__))}/app/**/*.rb"].each {|f| require f}
|
36
|
+
|