bcat 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALLING +6 -1
- data/README +28 -19
- data/Rakefile +24 -1
- data/bcat.gemspec +10 -6
- data/bin/bcat +5 -2
- data/lib/bcat.rb +15 -9
- data/lib/bcat/ansi.rb +2 -1
- data/lib/bcat/server.rb +113 -0
- data/man/a2h.1 +55 -0
- data/man/bcat.1 +225 -0
- data/man/bcat.1.ronn +67 -1
- data/man/btee.1 +225 -0
- data/man/btee.1.ronn +67 -1
- data/man/index.html +195 -0
- data/test/test_bcat_ansi.rb +6 -0
- metadata +12 -8
- data/lib/bcat/kidgloves.rb +0 -149
data/test/test_bcat_ansi.rb
CHANGED
@@ -93,6 +93,12 @@ class ANSITest < Test::Unit::TestCase
|
|
93
93
|
assert_equal expect, Bcat::ANSI.new(text).to_html
|
94
94
|
end
|
95
95
|
|
96
|
+
test "resetting without an implicit 0 argument" do
|
97
|
+
text = "\x1b[1mthis is bold\x1b[m, but this isn't"
|
98
|
+
expect = "<b>this is bold</b>, but this isn't"
|
99
|
+
assert_equal expect, Bcat::ANSI.new(text).to_html
|
100
|
+
end
|
101
|
+
|
96
102
|
test "multi-attribute sequences" do
|
97
103
|
text = "normal, \x1b[1;3;31mbold, underline, and red\x1b[0m, normal"
|
98
104
|
expect = "normal, <b><u><span style='color:#A00'>" +
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Tomayko
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-28 00:00:00 -07:00
|
19
19
|
default_executable: bcat
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: "0"
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
-
description:
|
35
|
+
description: pipe to browser utility
|
36
36
|
email: rtomayko@gmail.com
|
37
37
|
executables:
|
38
38
|
- bcat
|
@@ -54,17 +54,21 @@ files:
|
|
54
54
|
- lib/bcat/ansi.rb
|
55
55
|
- lib/bcat/browser.rb
|
56
56
|
- lib/bcat/html.rb
|
57
|
-
- lib/bcat/kidgloves.rb
|
58
57
|
- lib/bcat/reader.rb
|
58
|
+
- lib/bcat/server.rb
|
59
|
+
- man/a2h.1
|
59
60
|
- man/a2h.1.ronn
|
61
|
+
- man/bcat.1
|
60
62
|
- man/bcat.1.ronn
|
63
|
+
- man/btee.1
|
61
64
|
- man/btee.1.ronn
|
65
|
+
- man/index.html
|
62
66
|
- test/test_bcat_a2h.rb
|
63
67
|
- test/test_bcat_ansi.rb
|
64
68
|
- test/test_bcat_browser.rb
|
65
69
|
- test/test_bcat_head_parser.rb
|
66
70
|
has_rdoc: true
|
67
|
-
homepage: http://github.com/
|
71
|
+
homepage: http://rtomayko.github.com/bcat/
|
68
72
|
licenses: []
|
69
73
|
|
70
74
|
post_install_message:
|
@@ -97,6 +101,6 @@ rubyforge_project:
|
|
97
101
|
rubygems_version: 1.3.7
|
98
102
|
signing_key:
|
99
103
|
specification_version: 3
|
100
|
-
summary: browser
|
104
|
+
summary: Concatenate input from standard input, or one or more files, and write progressive output to a browser.
|
101
105
|
test_files: []
|
102
106
|
|
data/lib/bcat/kidgloves.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
require 'stringio'
|
3
|
-
|
4
|
-
module Rack
|
5
|
-
module Handler
|
6
|
-
class KidGloves
|
7
|
-
attr_accessor :app
|
8
|
-
|
9
|
-
StatusMessage = {
|
10
|
-
100 => 'Continue',
|
11
|
-
101 => 'Switching Protocols',
|
12
|
-
200 => 'OK',
|
13
|
-
201 => 'Created',
|
14
|
-
202 => 'Accepted',
|
15
|
-
203 => 'Non-Authoritative Information',
|
16
|
-
204 => 'No Content',
|
17
|
-
205 => 'Reset Content',
|
18
|
-
206 => 'Partial Content',
|
19
|
-
300 => 'Multiple Choices',
|
20
|
-
301 => 'Moved Permanently',
|
21
|
-
302 => 'Found',
|
22
|
-
303 => 'See Other',
|
23
|
-
304 => 'Not Modified',
|
24
|
-
305 => 'Use Proxy',
|
25
|
-
307 => 'Temporary Redirect',
|
26
|
-
400 => 'Bad Request',
|
27
|
-
401 => 'Unauthorized',
|
28
|
-
402 => 'Payment Required',
|
29
|
-
403 => 'Forbidden',
|
30
|
-
404 => 'Not Found',
|
31
|
-
405 => 'Method Not Allowed',
|
32
|
-
406 => 'Not Acceptable',
|
33
|
-
407 => 'Proxy Authentication Required',
|
34
|
-
408 => 'Request Timeout',
|
35
|
-
409 => 'Conflict',
|
36
|
-
410 => 'Gone',
|
37
|
-
411 => 'Length Required',
|
38
|
-
412 => 'Precondition Failed',
|
39
|
-
413 => 'Request Entity Too Large',
|
40
|
-
414 => 'Request-URI Too Large',
|
41
|
-
415 => 'Unsupported Media Type',
|
42
|
-
416 => 'Request Range Not Satisfiable',
|
43
|
-
417 => 'Expectation Failed',
|
44
|
-
500 => 'Internal Server Error',
|
45
|
-
501 => 'Not Implemented',
|
46
|
-
502 => 'Bad Gateway',
|
47
|
-
503 => 'Service Unavailable',
|
48
|
-
504 => 'Gateway Timeout',
|
49
|
-
505 => 'HTTP Version Not Supported'
|
50
|
-
}
|
51
|
-
|
52
|
-
def self.run(app, options={}, &block)
|
53
|
-
new(app, options).listen(&block)
|
54
|
-
end
|
55
|
-
|
56
|
-
def initialize(app, options={})
|
57
|
-
@app = app
|
58
|
-
@host = options[:Host] || '0.0.0.0'
|
59
|
-
@port = options[:Port] || 8089
|
60
|
-
end
|
61
|
-
|
62
|
-
def listen
|
63
|
-
log "Starting server on #{@host}:#{@port}"
|
64
|
-
server = TCPServer.new(@host, @port)
|
65
|
-
|
66
|
-
yield server if block_given?
|
67
|
-
|
68
|
-
loop do
|
69
|
-
socket = server.accept
|
70
|
-
socket.sync = true
|
71
|
-
log "#{socket.peeraddr[2]} (#{socket.peeraddr[3]})"
|
72
|
-
begin
|
73
|
-
|
74
|
-
req = {}
|
75
|
-
|
76
|
-
# parse the request line
|
77
|
-
request = socket.gets
|
78
|
-
method, path, version = request.split(" ")
|
79
|
-
req["REQUEST_METHOD"] = method
|
80
|
-
info, query = path.split("?")
|
81
|
-
req["PATH_INFO"] = info
|
82
|
-
req["QUERY_STRING"] = query
|
83
|
-
|
84
|
-
# parse the headers
|
85
|
-
while (line = socket.gets)
|
86
|
-
line.strip!
|
87
|
-
break if line.size == 0
|
88
|
-
key, val = line.split(": ")
|
89
|
-
key = key.upcase.gsub('-', '_')
|
90
|
-
key = "HTTP_#{key}" if !%w[CONTENT_TYPE CONTENT_LENGTH].include?(key)
|
91
|
-
req[key] = val
|
92
|
-
end
|
93
|
-
|
94
|
-
# parse the body
|
95
|
-
body = ''
|
96
|
-
if (len = req['CONTENT_LENGTH']) && ["POST", "PUT"].member?(method)
|
97
|
-
body = socket.read(len.to_i)
|
98
|
-
end
|
99
|
-
|
100
|
-
# process the request
|
101
|
-
process_request(req, body, socket)
|
102
|
-
|
103
|
-
ensure
|
104
|
-
socket.close if not socket.closed?
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def log(message)
|
110
|
-
# $stderr.puts message
|
111
|
-
end
|
112
|
-
|
113
|
-
def status_message(code)
|
114
|
-
StatusMessage[code]
|
115
|
-
end
|
116
|
-
|
117
|
-
def process_request(request, input_body, socket)
|
118
|
-
env = {}.replace(request)
|
119
|
-
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
|
120
|
-
env["QUERY_STRING"] ||= ""
|
121
|
-
env["SCRIPT_NAME"] = ""
|
122
|
-
|
123
|
-
rack_input = StringIO.new(input_body)
|
124
|
-
rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
|
125
|
-
|
126
|
-
env.update({"rack.version" => [1,0],
|
127
|
-
"rack.input" => rack_input,
|
128
|
-
"rack.errors" => $stderr,
|
129
|
-
"rack.multithread" => true,
|
130
|
-
"rack.multiprocess" => true,
|
131
|
-
"rack.run_once" => false,
|
132
|
-
|
133
|
-
"rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
|
134
|
-
})
|
135
|
-
status, headers, body = app.call(env)
|
136
|
-
begin
|
137
|
-
socket.write("HTTP/1.1 #{status} #{status_message(status)}\r\n")
|
138
|
-
headers.each do |k, vs|
|
139
|
-
vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")}
|
140
|
-
end
|
141
|
-
socket.write("\r\n")
|
142
|
-
body.each { |s| socket.write(s) }
|
143
|
-
ensure
|
144
|
-
body.close if body.respond_to? :close
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|