aslakhellesoy-bcat 0.6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CONTRIBUTING +13 -0
- data/COPYING +19 -0
- data/INSTALLING +10 -0
- data/README +48 -0
- data/RELEASING +10 -0
- data/Rakefile +83 -0
- data/bcat.gemspec +60 -0
- data/bin/a2h +15 -0
- data/bin/bcat +79 -0
- data/bin/btee +2 -0
- data/contrib/bman +26 -0
- data/lib/bcat.rb +118 -0
- data/lib/bcat/ansi.rb +170 -0
- data/lib/bcat/browser.rb +68 -0
- data/lib/bcat/html.rb +106 -0
- data/lib/bcat/reader.rb +102 -0
- data/lib/bcat/server.rb +113 -0
- data/man/a2h.1 +55 -0
- data/man/a2h.1.ronn +39 -0
- data/man/bcat.1 +226 -0
- data/man/bcat.1.ronn +159 -0
- data/man/btee.1 +226 -0
- data/man/btee.1.ronn +159 -0
- data/man/index.html +195 -0
- data/test/contest.rb +68 -0
- data/test/test_bcat_a2h.rb +19 -0
- data/test/test_bcat_ansi.rb +121 -0
- data/test/test_bcat_browser.rb +12 -0
- data/test/test_bcat_head_parser.rb +56 -0
- metadata +97 -0
data/CONTRIBUTING
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Please submit pull requests to:
|
2
|
+
|
3
|
+
<https://github.com/rtomayko/bcat/pulls>
|
4
|
+
|
5
|
+
For information on forking repositories and sending pull requests:
|
6
|
+
|
7
|
+
<http://help.github.com/pull-requests/>
|
8
|
+
|
9
|
+
If you prefer sending text patches, please use git-format-patch(1) to generate
|
10
|
+
them so I can attribute you properly. Text patches can be submitted to the issue
|
11
|
+
tracker:
|
12
|
+
|
13
|
+
<https://github.com/rtomayko/bcat/issues>
|
data/COPYING
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
bcat
|
2
|
+
Copyright (c) 2010 Ryan Tomayko <http://tomayko.com/about>
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to
|
6
|
+
deal in the Software without restriction, including without limitation the
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
8
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
17
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/INSTALLING
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
bcat is known to work under MacOS X, Linux, and FreeBSD (other UNIX-like
|
2
|
+
environments with freedesktop.org integration should work fine too). Progressive
|
3
|
+
output has been tested under Safari, Firefox, Chrome, and GNOME Epiphany.
|
4
|
+
|
5
|
+
bcat is written in Ruby and requires a basic Ruby installation. Install bcat
|
6
|
+
using the gem command:
|
7
|
+
|
8
|
+
$ gem install bcat
|
9
|
+
|
10
|
+
bcat depends on the rack package.
|
data/README
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
bcat
|
2
|
+
http://github.com/rtomayko/bcat
|
3
|
+
git clone git://github.com/rtomayko/bcat.git
|
4
|
+
gem install bcat
|
5
|
+
|
6
|
+
bcat is a pipe to browser utility for use at the shell and within editors like
|
7
|
+
Vim or Emacs. It reads from standard input, or one or more files, and streams
|
8
|
+
output to a browser window:
|
9
|
+
|
10
|
+
$ echo "hi mom" |bcat
|
11
|
+
$ echo "hi mom" |bcat -T 'Important Message'
|
12
|
+
$ echo "hi mom" |bcat -b chrome
|
13
|
+
|
14
|
+
Plain text is converted to simple preformatted HTML with rudimentary support for
|
15
|
+
ANSI/VT100 escape sequences (color, background, bold, underline, etc.)
|
16
|
+
|
17
|
+
You can also pipe HTML into bcat, in which case input is written through to the
|
18
|
+
browser unmodified:
|
19
|
+
|
20
|
+
$ echo "<h1>hi mom</h1>" |bcat
|
21
|
+
$ echo "*hi mom*" |markdown |bcat
|
22
|
+
|
23
|
+
Output is displayed progressively as it's being read, making bcat especially
|
24
|
+
useful with build tools or even commands like tail(1) that generate output over
|
25
|
+
longer periods of time:
|
26
|
+
|
27
|
+
$ make all |bcat
|
28
|
+
$ rake test |bcat
|
29
|
+
$ tail -f /var/log/syslog |bcat
|
30
|
+
$ (while printf .; do sleep 1; done) |bcat
|
31
|
+
|
32
|
+
See the bcat(1) EXAMPLES section for more on using bcat from the shell or within
|
33
|
+
editors like Vim:
|
34
|
+
<http://rtomayko.github.com/bcat/bcat.1.html#EXAMPLES>
|
35
|
+
|
36
|
+
bcat was inspired by TextMate's HTML output capabilities and a desire to have
|
37
|
+
them at the shell and also within editors like Vim or Emacs. See:
|
38
|
+
<http://manual.macromates.com/en/commands#html_output>
|
39
|
+
<http://blog.macromates.com/2005/html-output-for-commands/>
|
40
|
+
|
41
|
+
Only a small portion of TextMate's HTML output features are currently supported,
|
42
|
+
although more will be added in the future (like hyperlinking file:line
|
43
|
+
references and injecting CSS/JavaScript).
|
44
|
+
|
45
|
+
See the INSTALLING, COPYING, and CONTRIBUTING files for more information on
|
46
|
+
those things.
|
47
|
+
|
48
|
+
Copyright (c) 2010 by Ryan Tomayko <http://tomayko.com/about>
|
data/RELEASING
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'date'
|
2
|
+
task :default => :test
|
3
|
+
|
4
|
+
ROOTDIR = File.expand_path('..', __FILE__).sub(/#{Dir.pwd}(?=\/)/, '.')
|
5
|
+
LIBDIR = "#{ROOTDIR}/lib"
|
6
|
+
BINDIR = "#{ROOTDIR}/bin"
|
7
|
+
|
8
|
+
task :environment do
|
9
|
+
$:.unshift ROOTDIR if !$:.include?(ROOTDIR)
|
10
|
+
$:.unshift LIBDIR if !$:.include?(LIBDIR)
|
11
|
+
ENV['RUBYLIB'] = $LOAD_PATH.join(':')
|
12
|
+
ENV['PATH'] = "#{BINDIR}:#{ENV['PATH']}"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run tests'
|
16
|
+
task :test => :environment do
|
17
|
+
$LOAD_PATH.unshift "#{ROOTDIR}/test"
|
18
|
+
Dir['test/test_*.rb'].each { |f| require(f) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def source_version
|
22
|
+
@source_version ||= `ruby -Ilib -rbcat -e 'puts Bcat::VERSION'`.chomp
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
$spec = eval(File.read('bcat.gemspec'))
|
27
|
+
|
28
|
+
desc "Build gem package"
|
29
|
+
task :package => 'bcat.gemspec' do
|
30
|
+
sh "gem build bcat.gemspec"
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Build the manual'
|
34
|
+
task :man do
|
35
|
+
ENV['RONN_MANUAL'] = "Bcat #{source_version}"
|
36
|
+
ENV['RONN_ORGANIZATION'] = "Ryan Tomayko"
|
37
|
+
sh "ronn -stoc -w -r5 man/*.ronn"
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Publish to github pages'
|
41
|
+
task :pages => :man do
|
42
|
+
puts '----------------------------------------------'
|
43
|
+
puts 'Rebuilding pages ...'
|
44
|
+
verbose(false) {
|
45
|
+
rm_rf 'pages'
|
46
|
+
push_url = `git remote show origin`.grep(/Push.*URL/).first[/git@.*/]
|
47
|
+
sh "
|
48
|
+
set -e
|
49
|
+
git fetch -q origin
|
50
|
+
rev=$(git rev-parse origin/gh-pages)
|
51
|
+
git clone -q -b gh-pages . pages
|
52
|
+
cd pages
|
53
|
+
git reset --hard $rev
|
54
|
+
rm -f *.html
|
55
|
+
cp -rp ../man/*.html ../man/index.* ./
|
56
|
+
git add -u *.html index.*
|
57
|
+
git commit -m 'rebuild manual'
|
58
|
+
git push #{push_url} gh-pages
|
59
|
+
", :verbose => false
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
file 'bcat.gemspec' => FileList['{lib,test,bin}/**','Rakefile'] do |f|
|
64
|
+
# read spec file and split out manifest section
|
65
|
+
spec = File.read(f.name)
|
66
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
67
|
+
# replace version and date
|
68
|
+
head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
|
69
|
+
head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
|
70
|
+
# determine file list from git ls-files
|
71
|
+
files = `git ls-files`.
|
72
|
+
split("\n").
|
73
|
+
sort.
|
74
|
+
reject{ |file| file =~ /^\./ }.
|
75
|
+
reject { |file| file =~ /^doc/ }.
|
76
|
+
map{ |file| " #{file}" }.
|
77
|
+
join("\n")
|
78
|
+
# piece file back together and write...
|
79
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
80
|
+
spec = [head,manifest,tail].join(" # = MANIFEST =\n")
|
81
|
+
File.open(f.name, 'w') { |io| io.write(spec) }
|
82
|
+
puts "updated #{f.name}"
|
83
|
+
end
|
data/bcat.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'aslakhellesoy-bcat'
|
3
|
+
s.version = '0.6.0.1'
|
4
|
+
s.date = '2011-05-22'
|
5
|
+
|
6
|
+
s.description = "pipe to browser utility"
|
7
|
+
s.summary =
|
8
|
+
"Concatenate input from standard input, or one or more files, " +
|
9
|
+
"and write progressive output to a browser."
|
10
|
+
|
11
|
+
s.authors = ["Ryan Tomayko"]
|
12
|
+
s.email = "rtomayko@gmail.com"
|
13
|
+
|
14
|
+
# = MANIFEST =
|
15
|
+
s.files = %w[
|
16
|
+
CONTRIBUTING
|
17
|
+
COPYING
|
18
|
+
INSTALLING
|
19
|
+
README
|
20
|
+
RELEASING
|
21
|
+
Rakefile
|
22
|
+
bcat.gemspec
|
23
|
+
bin/a2h
|
24
|
+
bin/bcat
|
25
|
+
bin/btee
|
26
|
+
contrib/bman
|
27
|
+
lib/bcat.rb
|
28
|
+
lib/bcat/ansi.rb
|
29
|
+
lib/bcat/browser.rb
|
30
|
+
lib/bcat/html.rb
|
31
|
+
lib/bcat/reader.rb
|
32
|
+
lib/bcat/server.rb
|
33
|
+
man/a2h.1
|
34
|
+
man/a2h.1.ronn
|
35
|
+
man/bcat.1
|
36
|
+
man/bcat.1.ronn
|
37
|
+
man/btee.1
|
38
|
+
man/btee.1.ronn
|
39
|
+
man/index.html
|
40
|
+
test/contest.rb
|
41
|
+
test/test_bcat_a2h.rb
|
42
|
+
test/test_bcat_ansi.rb
|
43
|
+
test/test_bcat_browser.rb
|
44
|
+
test/test_bcat_head_parser.rb
|
45
|
+
]
|
46
|
+
# = MANIFEST =
|
47
|
+
|
48
|
+
s.default_executable = 'bcat'
|
49
|
+
s.executables = ['a2h', 'bcat', 'btee']
|
50
|
+
|
51
|
+
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
52
|
+
s.add_dependency 'rack', '>= 1.2.2'
|
53
|
+
|
54
|
+
s.extra_rdoc_files = %w[COPYING]
|
55
|
+
|
56
|
+
s.has_rdoc = true
|
57
|
+
s.homepage = "http://rtomayko.github.com/bcat/"
|
58
|
+
s.rdoc_options = ["--line-numbers", "--inline-source"]
|
59
|
+
s.require_paths = %w[lib]
|
60
|
+
end
|
data/bin/a2h
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Usage: a2h [-] [<file>...]
|
3
|
+
# Convert ANSI/VT100 escape sequences to HTML.
|
4
|
+
require 'bcat/ansi'
|
5
|
+
require 'bcat/reader'
|
6
|
+
|
7
|
+
$stdin.sync = true
|
8
|
+
$stdout.sync = true
|
9
|
+
|
10
|
+
ARGV.push '-' if ARGV.empty?
|
11
|
+
|
12
|
+
reader = Bcat::Reader.new(false, ARGV.to_a)
|
13
|
+
reader.open
|
14
|
+
filter = Bcat::ANSI.new(reader)
|
15
|
+
filter.each { |text| $stdout.write(text) }
|
data/bin/bcat
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#/ Usage: bcat [-htp] [-a] [-b <browser>] [-T <title>] [<file>]...
|
3
|
+
#/ bcat [-htp] [-a] [-b <browser>] [-T <title>] -c command...
|
4
|
+
#/ btee <options> [<file>]...
|
5
|
+
#/ Pipe to browser utility. Read standard input, possibly one or more <file>s,
|
6
|
+
#/ and write concatenated / formatted output to browser. When invoked as btee,
|
7
|
+
#/ also write all input back to standard output.
|
8
|
+
#/
|
9
|
+
#/ Display options:
|
10
|
+
#/ -b, --browser=<browser> open <browser> instead of system default browser
|
11
|
+
#/ -T, --title=<text> use <text> as the browser title
|
12
|
+
#/ -a, --ansi convert ANSI (color) escape sequences to HTML
|
13
|
+
#/
|
14
|
+
#/ Input format (auto detected by default):
|
15
|
+
#/ -h, --html input is already HTML encoded, doc or fragment
|
16
|
+
#/ -t, --text input is unencoded text
|
17
|
+
#/
|
18
|
+
#/ Misc options:
|
19
|
+
#/ -c, --command read the standard output of command
|
20
|
+
#/ -p, --persist serve until interrupted, allowing reload
|
21
|
+
#/ -d, --debug enable verbose debug logging on stderr
|
22
|
+
require 'optparse'
|
23
|
+
|
24
|
+
options = {
|
25
|
+
:Host => '127.0.0.1',
|
26
|
+
:Port => 0,
|
27
|
+
:format => nil,
|
28
|
+
:title => nil,
|
29
|
+
:browser => (ENV['BCAT_BROWSER'].to_s.size > 0 ? ENV['BCAT_BROWSER'] : 'default'),
|
30
|
+
:ansi => false,
|
31
|
+
:persist => false,
|
32
|
+
:command => false,
|
33
|
+
:debug => false,
|
34
|
+
:tee => !!($0 =~ /tee$/)
|
35
|
+
}
|
36
|
+
|
37
|
+
(class <<self;self;end).send(:define_method, :notice) { |message|
|
38
|
+
warn "#{File.basename($0)}: #{message}" if options[:debug] }
|
39
|
+
|
40
|
+
ARGV.options do |argv|
|
41
|
+
argv.on('-h', '--html') { options[:format] = 'html' }
|
42
|
+
argv.on('-t', '--text') { options[:format] = 'text' }
|
43
|
+
argv.on('-b', '--browser=v') { |app| options[:browser] = app }
|
44
|
+
argv.on('-T', '--title=v') { |text| options[:title] = text }
|
45
|
+
argv.on('-a', '--ansi') { options[:ansi] = true }
|
46
|
+
argv.on('-p', '--persist') { options[:persist] = true }
|
47
|
+
argv.on('-c', '--command') { options[:command] = true }
|
48
|
+
argv.on('-d', '--debug') { options[:debug] = true }
|
49
|
+
argv.on('--host=v') { |addr| options[:Host] = addr }
|
50
|
+
argv.on('--port=v') { |port| options[:Port] = port.to_i }
|
51
|
+
argv.on_tail('--help') { exec "grep ^#/ <#{__FILE__} | cut -c4-" }
|
52
|
+
argv.parse!
|
53
|
+
end
|
54
|
+
ARGV.push '-' if ARGV.empty?
|
55
|
+
|
56
|
+
require 'bcat'
|
57
|
+
notice "loaded bcat v#{Bcat::VERSION}"
|
58
|
+
|
59
|
+
browser = Bcat::Browser.new(options[:browser])
|
60
|
+
notice "env BCAT_BROWSER=#{options[:browser].inspect}"
|
61
|
+
notice "env BCAT_COMMAND='#{browser.command}'"
|
62
|
+
|
63
|
+
notice "starting server"
|
64
|
+
pid = nil
|
65
|
+
begin
|
66
|
+
bcat = Bcat.new(ARGV, options)
|
67
|
+
bcat.serve! do |sock|
|
68
|
+
port = sock.addr[1]
|
69
|
+
url = "http://#{bcat[:Host]}:#{port}/#{File.basename(Dir.pwd)}"
|
70
|
+
pid = browser.open(url)
|
71
|
+
end
|
72
|
+
rescue Interrupt
|
73
|
+
notice "interrupt"
|
74
|
+
end
|
75
|
+
|
76
|
+
Process.wait(pid) if pid
|
77
|
+
status = $?.exitstatus
|
78
|
+
notice "browser [pid: #{pid}] exited with #{status}"
|
79
|
+
exit status
|
data/bin/btee
ADDED
data/contrib/bman
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
# Usage: bman <man-args>
|
3
|
+
# Open manual page in browser with bcat.
|
4
|
+
#
|
5
|
+
# Original zsh version by Nick Stenning <http://github.com/nickstenning>
|
6
|
+
# http://github.com/rtomayko/bcat/issues#issue/8
|
7
|
+
#
|
8
|
+
# Ported to POSIX shell by Ryan Tomayko <http://github.com/rtomayko>
|
9
|
+
set -e
|
10
|
+
|
11
|
+
# we use normal bold and underline
|
12
|
+
BOLD="\033[1m"
|
13
|
+
EM="\033[3m"
|
14
|
+
RESET="\033[0m"
|
15
|
+
|
16
|
+
# pass argv directly over to man
|
17
|
+
man "$@" |
|
18
|
+
|
19
|
+
# replace ^H based bold and underline with ansi equivelants
|
20
|
+
sed "
|
21
|
+
s/_\(.\)/"$(echo "$EM")"\1"$(echo "$RESET")"/g
|
22
|
+
s/\(.\)\1/"$(echo "$BOLD")"\1"$(echo "$RESET")"/g
|
23
|
+
" |
|
24
|
+
|
25
|
+
# pipe it into bcat
|
26
|
+
bcat
|
data/lib/bcat.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'bcat/reader'
|
3
|
+
require 'bcat/ansi'
|
4
|
+
require 'bcat/html'
|
5
|
+
require 'bcat/server'
|
6
|
+
require 'bcat/browser'
|
7
|
+
|
8
|
+
class Bcat
|
9
|
+
VERSION = '0.6.0.1'
|
10
|
+
include Rack::Utils
|
11
|
+
|
12
|
+
attr_reader :format
|
13
|
+
|
14
|
+
def initialize(args=[], config={})
|
15
|
+
@config = {:Host => '127.0.0.1', :Port => 8091}.merge(config)
|
16
|
+
@reader = Bcat::Reader.new(@config[:command], args)
|
17
|
+
@format = @config[:format]
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](key)
|
21
|
+
@config[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_app
|
25
|
+
app = self
|
26
|
+
Rack::Builder.new do
|
27
|
+
use Rack::Chunked
|
28
|
+
run app
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def serve!(&bk)
|
33
|
+
Bcat::Server.run to_app, @config, &bk
|
34
|
+
end
|
35
|
+
|
36
|
+
def call(env)
|
37
|
+
notice "#{env['REQUEST_METHOD']} #{env['PATH_INFO'].inspect}"
|
38
|
+
[200, {"Content-Type" => "text/html;charset=utf-8"}, self]
|
39
|
+
end
|
40
|
+
|
41
|
+
def assemble
|
42
|
+
@reader.open
|
43
|
+
|
44
|
+
@format = @reader.sniff if @format.nil?
|
45
|
+
|
46
|
+
@filter = @reader
|
47
|
+
@filter = TeeFilter.new(@filter) if @config[:tee]
|
48
|
+
@filter = TextFilter.new(@filter) if @format == 'text'
|
49
|
+
@filter = ANSI.new(@filter) if @format == 'text' || @config[:ansi]
|
50
|
+
end
|
51
|
+
|
52
|
+
def each
|
53
|
+
assemble
|
54
|
+
|
55
|
+
head_parser = Bcat::HeadParser.new
|
56
|
+
|
57
|
+
@filter.each do |buf|
|
58
|
+
if head_parser.nil?
|
59
|
+
yield buf
|
60
|
+
elsif head_parser.feed(buf)
|
61
|
+
yield content_for_head(inject=head_parser.head)
|
62
|
+
yield "\n"
|
63
|
+
yield head_parser.body
|
64
|
+
head_parser = nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if head_parser
|
69
|
+
yield content_for_head(inject=head_parser.head) +
|
70
|
+
"\n" +
|
71
|
+
head_parser.body
|
72
|
+
end
|
73
|
+
|
74
|
+
yield foot
|
75
|
+
rescue Errno::EINVAL
|
76
|
+
# socket was closed
|
77
|
+
notice "browser client went away"
|
78
|
+
rescue => boom
|
79
|
+
notice "boom: #{boom.class}: #{boom.to_s}"
|
80
|
+
raise
|
81
|
+
end
|
82
|
+
|
83
|
+
def content_for_head(inject='')
|
84
|
+
[
|
85
|
+
"\n" * 1000,
|
86
|
+
"<!DOCTYPE html>",
|
87
|
+
"<html>",
|
88
|
+
"<head>",
|
89
|
+
"<!-- bcat was here -->",
|
90
|
+
inject.to_s,
|
91
|
+
"<link href=\"data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=\" rel=\"icon\" type=\"image/x-icon\" />",
|
92
|
+
"<title>#{self[:title] || 'bcat'}</title>",
|
93
|
+
"</head>"
|
94
|
+
].join("\n")
|
95
|
+
end
|
96
|
+
|
97
|
+
def foot
|
98
|
+
"</body>\n</html>\n"
|
99
|
+
end
|
100
|
+
|
101
|
+
def escape_js(string)
|
102
|
+
string = string.gsub(/['\\]/) { |char| "\\#{char}" }
|
103
|
+
string.gsub!(/\n/, '\n')
|
104
|
+
string
|
105
|
+
end
|
106
|
+
|
107
|
+
def close
|
108
|
+
unless @config[:persist]
|
109
|
+
notice "closing with interrupt"
|
110
|
+
raise Interrupt, "connection closed"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def notice(message)
|
115
|
+
return if !@config[:debug]
|
116
|
+
warn "#{File.basename($0)}: #{message}"
|
117
|
+
end
|
118
|
+
end
|