shatty 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/shatty +13 -3
  2. data/shatty.gemspec +2 -5
  3. data/web.rb +45 -23
  4. metadata +4 -52
data/bin/shatty CHANGED
@@ -4,6 +4,13 @@ require "clamp"
4
4
  require "pty"
5
5
  require "ftw"
6
6
  require "uuidtools"
7
+ require "cabin"
8
+
9
+ if $DEBUG
10
+ logger = Cabin::Channel.get
11
+ logger.level = :debug if $DEBUG
12
+ logger.subscribe(STDERR)
13
+ end
7
14
 
8
15
  class Shatty < Clamp::Command
9
16
  subcommand "share", "Share a terminal session (read only for now)" do
@@ -17,8 +24,12 @@ class Shatty < Clamp::Command
17
24
  def execute
18
25
  start = Time.now
19
26
  if output.nil?
20
- self.output = "http://r.logstash.net:8200/s/#{UUIDTools::UUID.random_create}"
27
+ self.output = "http://shatty.semicomplete.com:8200/s/#{UUIDTools::UUID.random_create}"
21
28
  puts "Sending output to: #{output}"
29
+ puts "View commands"
30
+ puts " wget -qO- #{output}"
31
+ puts " curl -Lso- #{output}"
32
+ puts " shatty play #{output}"
22
33
  end
23
34
 
24
35
  if output =~ /^https?:/
@@ -59,8 +70,7 @@ class Shatty < Clamp::Command
59
70
  # for each chunk of text read from tmux, record
60
71
  # the timestamp (duration since 'start' of recording)
61
72
  out.syswrite([time_offset.to_f, buffer.length, buffer].pack("GNA#{buffer.length}"))
62
-
63
- $stdout.write(buffer) unless headless?
73
+ $stdout.syswrite(buffer) unless headless?
64
74
  end
65
75
 
66
76
  system("stty sane")
@@ -2,16 +2,13 @@ Gem::Specification.new do |spec|
2
2
  files = %x{git ls-files}.split("\n")
3
3
 
4
4
  spec.name = "shatty"
5
- spec.version = "0.0.6"
5
+ spec.version = "0.0.7"
6
6
  spec.summary = "shatty"
7
7
  spec.description = "shatty"
8
8
  spec.license = "none chosen yet"
9
9
 
10
10
  # Note: You should set the version explicitly.
11
- spec.add_dependency "cabin"
12
- spec.add_dependency "clamp"
13
- spec.add_dependency "ftw"
14
- spec.add_dependency "uuidtools"
11
+ spec.add_dependency "cabin", ">0" # for logging. apache 2 license
15
12
  spec.files = files
16
13
  spec.require_paths << "lib"
17
14
  spec.bindir = "bin"
data/web.rb CHANGED
@@ -2,43 +2,49 @@ require "ftw" # gem ftw
2
2
  require "cabin" # gem cabin
3
3
  require "thread"
4
4
 
5
+ Thread.abort_on_exception = true
5
6
  ShutdownSignal = :shutdown
6
7
 
7
8
  class Session
8
9
  def initialize
9
10
  @queue = Queue.new
10
11
  @recent = []
12
+ @subscribers = []
13
+
14
+ @publisher_thread = Thread.new { run }
11
15
  end # def initialize
12
16
 
17
+ def run
18
+ while true
19
+ chunk = @queue.pop
20
+ puts "#{@subscribers.count} subscribers"
21
+ @subscribers.each do |subscriber|
22
+ #p subscriber => chunk
23
+ subscriber << chunk
24
+ end
25
+ break if chunk == ShutdownSignal
26
+ end
27
+ end # def run
28
+
13
29
  def <<(chunk)
14
- @queue << chunk
15
30
  @recent << chunk
16
31
  @recent = @recent[0..100]
17
- end # def push
32
+ @queue << chunk
33
+ end # def <<
18
34
 
19
- def enumerator
20
- return Enumerator.new do |y|
21
- @recent.each { |chunk| y << chunk }
22
- while true
23
- chunk = @queue.pop
24
- break if chunk == ShutdownSignal
25
- y << chunk
26
- end
27
- end # Enumerator
28
- end # def enumerator
35
+ def subscribe(output)
36
+ @recent.each { |c| output << c }
37
+ @subscribers << output
38
+ end # def subscribe
29
39
 
30
- def raw
31
- return Enumerator.new do |y|
32
- enumerator.each do |chunk|
33
- y << decode(chunk)
34
- end
35
- end # Enumerator
36
- end # def enumerator
40
+ def unsubscribe(output)
41
+ @subscribers.delete(output)
42
+ end # def unsubscribe
37
43
 
38
- def decode(chunk)
44
+ def self.decode(chunk)
39
45
  headersize = [1,1].pack("GN").size
40
46
  return chunk[headersize .. -1]
41
- end # def decode
47
+ end # def self.decode
42
48
 
43
49
  def close
44
50
  @queue << ShutdownSignal
@@ -66,11 +72,27 @@ server = FTW::WebServer.new("0.0.0.0", port) do |request, response|
66
72
  elsif request.method == "GET"
67
73
  response.status = 200
68
74
  response["Content-Type"] = "text/plain"
75
+ queue = Queue.new
76
+ session.subscribe(queue)
69
77
  if request["user-agent"] =~ /^(curl|Wget)/
70
78
  # Curl or wget. Send raw text.
71
- response.body = session.raw
79
+ response.body = Enumerator.new do |y|
80
+ while true
81
+ chunk = queue.pop
82
+ break if chunk == ShutdownSignal
83
+ puts "Raw: #{chunk.inspect}"
84
+ y << Session.decode(chunk)
85
+ end
86
+ end
72
87
  else
73
- response.body = session.enumerator
88
+ response.body = Enumerator.new do |y|
89
+ while true
90
+ chunk = queue.pop
91
+ break if chunk == ShutdownSignal
92
+ puts "Plain: #{chunk.inspect}"
93
+ y << chunk
94
+ end
95
+ end
74
96
  end
75
97
  else
76
98
  response.status = 400
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shatty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cabin
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ! '>'
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :runtime
@@ -24,55 +24,7 @@ dependencies:
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: clamp
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: ftw
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: uuidtools
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
27
+ - - ! '>'
76
28
  - !ruby/object:Gem::Version
77
29
  version: '0'
78
30
  description: shatty