bcat-0.6.2/0000755000175000017500000000000012063024111012240 5ustar henrichhenrichbcat-0.6.2/lib/0000755000175000017500000000000012063024111013006 5ustar henrichhenrichbcat-0.6.2/lib/bcat.rb0000644000175000017500000000505412063024111014250 0ustar henrichhenrichrequire 'rack' require 'bcat/reader' require 'bcat/ansi' require 'bcat/html' require 'bcat/server' require 'bcat/browser' class Bcat VERSION = '0.6.2' include Rack::Utils attr_reader :format def initialize(args=[], config={}) @config = {:Host => '127.0.0.1', :Port => 8091}.merge(config) @reader = Bcat::Reader.new(@config[:command], args) @format = @config[:format] end def [](key) @config[key] end def to_app app = self Rack::Builder.new do use Rack::Chunked run app end end def serve!(&bk) Bcat::Server.run to_app, @config, &bk end def call(env) notice "#{env['REQUEST_METHOD']} #{env['PATH_INFO'].inspect}" [200, {"Content-Type" => "text/html;charset=utf-8"}, self] end def assemble @reader.open @format = @reader.sniff if @format.nil? @filter = @reader @filter = TeeFilter.new(@filter) if @config[:tee] @filter = TextFilter.new(@filter) if @format == 'text' @filter = ANSI.new(@filter) if @format == 'text' || @config[:ansi] end def each assemble head_parser = Bcat::HeadParser.new @filter.each do |buf| if head_parser.nil? yield buf elsif head_parser.feed(buf) yield content_for_head(inject=head_parser.head) yield "\n" yield head_parser.body head_parser = nil end end if head_parser yield content_for_head(inject=head_parser.head) + "\n" + head_parser.body end yield foot rescue Errno::EINVAL # socket was closed notice "browser client went away" rescue => boom notice "boom: #{boom.class}: #{boom.to_s}" raise end def content_for_head(inject='') [ "\n" * 1000, "", "", "", "", inject.to_s, "", "#{self[:title] || 'bcat'}", "" ].join("\n") end def foot "\n\n" end def escape_js(string) string = string.gsub(/['\\]/) { |char| "\\#{char}" } string.gsub!(/\n/, '\n') string end def close unless @config[:persist] notice "closing with interrupt" raise Interrupt, "connection closed" end end def notice(message) return if !@config[:debug] warn "#{File.basename($0)}: #{message}" end end bcat-0.6.2/lib/bcat/0000755000175000017500000000000012063024111013717 5ustar henrichhenrichbcat-0.6.2/lib/bcat/server.rb0000644000175000017500000000571212063024111015557 0ustar henrichhenrichrequire 'socket' require 'stringio' require 'rack/utils' class Bcat # Simple Rack handler based largely on Scott Chacon's kidgloves library: # http://github.com/schacon/kidgloves class Server attr_accessor :app def self.run(app, options={}, &block) new(app, options).listen(&block) end def initialize(app, options={}) @app = app @host = options[:Host] || '0.0.0.0' @port = options[:Port] || 8089 end def bind(host, port) TCPServer.new(host, port) rescue Errno::EADDRINUSE port += 1 retry end def listen server = TCPServer.new(@host, @port) yield server if block_given? loop do socket = server.accept socket.sync = true log "#{socket.peeraddr[2]} (#{socket.peeraddr[3]})" begin req = {} # parse the request line request = socket.gets method, path, version = request.split(" ", 3) req["REQUEST_METHOD"] = method info, query = path.split("?") req["PATH_INFO"] = info req["QUERY_STRING"] = query # parse the headers while (line = socket.gets) line.strip! break if line.size == 0 key, val = line.split(": ") key = key.upcase.gsub('-', '_') key = "HTTP_#{key}" if !%w[CONTENT_TYPE CONTENT_LENGTH].include?(key) req[key] = val end # parse the body body = if len = req['CONTENT_LENGTH'] socket.read(len.to_i) else '' end # process the request process_request(req, body, socket) ensure socket.close if not socket.closed? end end end def log(message) # $stderr.puts message end def status_message(code) Rack::Utils::HTTP_STATUS_CODES[code] end def process_request(request, input_body, socket) env = {}.replace(request) env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] env["QUERY_STRING"] ||= "" env["SCRIPT_NAME"] = "" rack_input = StringIO.new(input_body) rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding) env.update( "rack.version" => [1,0], "rack.input" => rack_input, "rack.errors" => $stderr, "rack.multithread" => true, "rack.multiprocess" => true, "rack.run_once" => false, "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" ) status, headers, body = app.call(env) begin socket.write("HTTP/1.1 #{status} #{status_message(status)}\r\n") headers.each do |k, vs| vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")} end socket.write("\r\n") body.each { |s| socket.write(s) } ensure body.close if body.respond_to? :close end end end end bcat-0.6.2/lib/bcat/reader.rb0000644000175000017500000000373012063024111015511 0ustar henrichhenrichrequire 'rack/utils' class Bcat # ARGF style multi-file streaming interface. Input is read with IO#readpartial # to avoid buffering. class Reader attr_reader :is_command attr_reader :args attr_reader :fds def initialize(is_command, args=[]) @is_command = is_command @args = args end def open @fds = is_command ? open_command : open_files @buf = [] end def open_command [IO.popen(args.join(' '), 'rb')] end def open_files args.map do |f| if f == '-' $stdin else File.open(f, 'rb') end end end def each yield @buf.shift while @buf.any? while fd = fds.first fds.shift and next if fd.closed? fd.sync = true begin while buf = fd.readpartial(4096) yield buf end rescue EOFError fd.close end fds.shift end end def sniff @format ||= catch :detect do each do |chunk| @buf << chunk case chunk when /\A\s*" @source.each do |chunk| chunk = escape_html(chunk) chunk = "#{chunk}" if !chunk.gsub!(/\n/, "
") yield chunk end yield "" end end end bcat-0.6.2/lib/bcat/html.rb0000644000175000017500000000535112063024111015214 0ustar henrichhenrichclass Bcat # Parses HTML until the first displayable body character and provides methods # for accessing head and body contents. class HeadParser attr_accessor :buf def initialize @buf = '' @head = [] @body = nil @html = nil end # Called to parse new data as it arrives. def feed(data) if complete? @body << data else @buf << data parse(@buf) end complete? end # Truthy once the first displayed character of the body has arrived. def complete? !@body.nil? end # Determine if the input is HTML. This is nil before the first non-whitespace # character is received, true if the first non-whitespace character is a # '<', and false if the first non-whitespace character is something other # than '<'. def html? @html end # The head contents without any DOCTYPE, , or tags. This should # consist of only

|bcat

pipe to browser utility

README, INSTALLING, COPYING, CONTRIBUTING

Manuals

bcat(1), btee(1)
browser cat and browser tee.
a2h(1)
VT100/ANSI escape sequence to HTML converter.

Examples

With build tools:

make test |bcat
rake test |bcat

As a clipboard viewer:

pbpaste  |bcat   # macos
xclip -o |bcat   # X11

For previewing HTML:

markdown README.md |bcat
redcloth README.textile |bcat
erb -T - template.erb |bcat
mustache < template.mustache |bcat
pygmentize -Ofull,style=colorful -f html main.c |bcat

As a simple man pager:

export MANPAGER='col -b |bcat'
man grep

With git, selectively:

git log -p --color |bcat
git diff --color HEAD@{5d} HEAD |bcat

With git, as the default PAGER:

export GIT_PAGER=bcat
git log -p
git diff HEAD@{5d} HEAD

As a log viewer:

tail -n 1000 -f /var/log/messages |bcat
tail -f $RAILS_ROOT/log/development.log |bcat

Or, a remote log viewer:

ssh example.org 'tail -n 1000 -f /var/log/syslog' |bcat

Vim and vi Examples

Preview current buffer as HTML:

:!markdown % |bcat
:!ronn -5 --pipe % |bcat

Create keymappings:

:map ,pm :!markdown % \|bcat
:map ,pp :!pygmentize -Ofull,style=colorful -f html % \|bcat

Use with makeprg:

:set makeprg=make\ \\\|bcat
:set makeprg=markdown\ %\ \\\|bcat
:set makeprg=testrb\ %\ \\\|bcat

See Also

Copyright © 2010 Ryan Tomayko

bcat-0.6.2/man/a2h.1.ronn0000644000175000017500000000214112063024111014520 0ustar henrichhenricha2h(1) -- convert ANSI/VT100 escape sequences to HTML ===================================================== ## SYNOPSIS `a2h` [-] [...] ## DESCRIPTION The `a2h` utility reads from standard input, or one or more s, and converts ANSI/VT100 escape sequences to inline HTML. ## ESCAPE SEQUENCES The following escape sequences are supported: * `[0m`: Resets all attributes / closes all HTML tags. * `[1m`=``: Bold. * `[4m`=``: Underscore. * `[5m`=``: Blink. Really. * `[8m`=``: Hidden. * `[30-37m`=``>`: Background color. * `[90-97m`=``>`: Light background color. ## SEE ALSO [ansi2html.sh](http://github.com/pixelb/scripts/blob/master/scripts/ansi2html.sh), [HTML::FromANSI](http://cpansearch.perl.org/src/NUFFIN/HTML-FromANSI-2.03/lib/HTML/FromANSI.pm) bcat-0.6.2/man/bcat.1.ronn0000644000175000017500000001126612063024111014767 0ustar henrichhenrichbcat(1) -- browser cat ====================== ## SYNOPSIS `bcat` [-htapd] [...]
`bcat` [-htapd] -c ...
`btee` [-htad] [...] ## DESCRIPTION The `bcat` utility reads from standard input, or one or more s, and pipes output into a web browser. may be '-', in which case standard input is concatenated at that position. When invoked as `btee`, all input is written immediately to standard output in addition to being piped into the browser. ## OPTIONS `bcat` opens a simple, undecorated page with the system default web browser and immediately begins streaming input. The following options control the browser display: * `-b`, `--browser`=default|firefox|safari|chrome|opera|: The name of the browser application. Defaults to the value of the `BCAT_BROWSER` environment variable, or the system default browser when no `BCAT_BROWSER` is defined. * `-T`, `--title`=: Use as the page ``. By default, the path to the current working directory is used as the title. * `-a`, `--ansi`: Turns on VT100/ANSI escape sequence conversion. This causes all input to be piped through a2h(1), replacing ANSI escape sequences with HTML for things like bold, underline, and colors. On by default when the input is text; use the `-a` option to turn it on when the input is HTML. By default, `bcat` attempts to detect whether input is HTML or plain text using a simple heuristic, but you can force input to be treated as one or the other with these options: * `-t`, `--text`: The input is non-HTML encoded text. All bare `<` and `&` characters are entity encoded, end-of-line characters are converted to `<br>`, and the entire output is wrapped in a `<pre>`. * `-h`, `--html`: The input is already HTML encoded. Under this mode, `bcat` passes input through to the browser mostly unmodified. The input may be a full HTML document, or it may be an HTML fragment. `bcat` outputs `<html>`, `<head>`, and `<body>` elements even if they are not included in the input. Miscellaneous options: * `-c`, `--command`: Interpret the remaining options as a command to be run whose output should be piped into the web browser. * `-p`, `--persist`: Have `bcat` serve requests until it is interrupted. Reloading the page in the browser will cause `bcat` to re-read the files (or re-run the command if used with the `--command` option). Standard input can only be read once and will produce no content on subsequent requests. * `-d`, `--debug`: Turn on verbose debug logging to standard error. Include this output when reporting defects if applicable. ## ENVIRONMENT * `BCAT_BROWSER`=default|firefox|safari|chrome|opera|<other>: The name of the browser to use by default. `bcat` maps this to an actual browser command based on the current platform. The special value "default" maps to the system default browser. * `BCAT_COMMAND`=<command>: The entire browser command line (to be executed by `/bin/sh`). This overrides the `BCAT_BROWSER` environment variable and makes the `--browser` (`-b`) option a no-op. This should only be necessary when running a browser unknown to bcat or in order to pass special arguments. ## EXAMPLES ### Basic Shell Examples With build tools: make test |bcat rake test |bcat As a clipboard viewer: pbpaste |bcat # mac xclip -o |bcat # X11 For previewing HTML: markdown README.md |bcat redcloth README.textile |bcat erb -T - template.erb |bcat mustache < template.mustache |bcat pygmentize -Ofull,style=colorful -f html main.c |bcat Regenerate the content each time the page is reloaded: bcat -pc markdown README.md As a simple man pager: export MANPAGER='col -b |bcat' man grep With git, selectively: git log -p --color |bcat git diff --color HEAD@{5d} HEAD |bcat With git, as the default PAGER: export GIT_PAGER=bcat git log -p git diff HEAD@{5d} HEAD As a log viewer: tail -n 1000 -f /var/log/messages |bcat tail -f $RAILS_ROOT/log/development.log |bcat Or, a remote log viewer: ssh example.org 'tail -n 1000 -f /var/log/syslog' |bcat ### Vim and vi Examples Preview current buffer as HTML: :!markdown % |bcat :!ronn -5 --pipe % |bcat Create keymappings: map ,pm :!markdown % \|bcat map ,pp :!pygmentize -Ofull,style=colorful -f html % \|bcat Use with `makeprg`: set makeprg=make\ \\\|bcat set makeprg=markdown\ %\ \\\|bcat set makeprg=testrb\ %\ \\\|bcat (Note that you may need to escape the `%` character with quotes if there's spaces in the pathname. For example: `!markdown '%' |bcat`.) ## SEE ALSO cat(1), tee(1), open(1) ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/man/a2h.1��������������������������������������������������������������������������������0000644�0001750�0001750�00000002517�12063024111�013554� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������.\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . .TH "A2H" "1" "June 2010" "Ryan Tomayko" "Bcat 0.5.0" . .SH "NAME" \fBa2h\fR \- convert ANSI/VT100 escape sequences to HTML . .SH "SYNOPSIS" \fBa2h\fR [\-] [\fIfile\fR\.\.\.] . .SH "DESCRIPTION" The \fBa2h\fR utility reads from standard input, or one or more \fIfile\fRs, and converts ANSI/VT100 escape sequences to inline HTML\. . .SH "ESCAPE SEQUENCES" The following escape sequences are supported: . .TP \fB<ESC>[0m\fR Resets all attributes / closes all HTML tags\. . .TP \fB<ESC>[1m\fR=\fB<b>\fR Bold\. . .TP \fB<ESC>[4m\fR=\fB<u>\fR Underscore\. . .TP \fB<ESC>[5m\fR=\fB<blink>\fR Blink\. Really\. . .TP \fB<ESC>[8m\fR=\fB<span style=\'display:none\'>\fR Hidden\. . .TP \fB<ESC>[30\-37m\fR=\fB<span style=\'color:\fR\fIcolor\fR\fB>\fR Foreground color\. . .TP \fB<ESC>[40\-47m\fR=\fB<span style=\'background\-color:\fR\fIcolor\fR\fB>\fR Background color\. . .TP \fB<ESC>[90\-97m\fR=\fB<span style=\'color:\fR\fIcolor\fR\fB>\fR Light foreground colors\. . .TP \fB<ESC>[100\-107m\fR=\fB<span style=\'background\-color:\fR\fIcolor\fR\fB>\fR Light background color\. . .SH "SEE ALSO" ansi2html\.sh \fIhttp://github\.com/pixelb/scripts/blob/master/scripts/ansi2html\.sh\fR, HTML::FromANSI \fIhttp://cpansearch\.perl\.org/src/NUFFIN/HTML\-FromANSI\-2\.03/lib/HTML/FromANSI\.pm\fR ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/man/btee.1.ronn��������������������������������������������������������������������������0000644�0001750�0001750�00000011266�12063024111�014775� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat(1) -- browser cat ====================== ## SYNOPSIS `bcat` [-htapd] [<file>...]<br> `bcat` [-htapd] -c <command>...<br> `btee` [-htad] [<file>...] ## DESCRIPTION The `bcat` utility reads from standard input, or one or more <file>s, and pipes output into a web browser. <file> may be '-', in which case standard input is concatenated at that position. When invoked as `btee`, all input is written immediately to standard output in addition to being piped into the browser. ## OPTIONS `bcat` opens a simple, undecorated page with the system default web browser and immediately begins streaming input. The following options control the browser display: * `-b`, `--browser`=default|firefox|safari|chrome|opera|<other>: The name of the browser application. Defaults to the value of the `BCAT_BROWSER` environment variable, or the system default browser when no `BCAT_BROWSER` is defined. * `-T`, `--title`=<text>: Use <text> as the page `<title>`. By default, the path to the current working directory is used as the title. * `-a`, `--ansi`: Turns on VT100/ANSI escape sequence conversion. This causes all input to be piped through a2h(1), replacing ANSI escape sequences with HTML for things like bold, underline, and colors. On by default when the input is text; use the `-a` option to turn it on when the input is HTML. By default, `bcat` attempts to detect whether input is HTML or plain text using a simple heuristic, but you can force input to be treated as one or the other with these options: * `-t`, `--text`: The input is non-HTML encoded text. All bare `<` and `&` characters are entity encoded, end-of-line characters are converted to `<br>`, and the entire output is wrapped in a `<pre>`. * `-h`, `--html`: The input is already HTML encoded. Under this mode, `bcat` passes input through to the browser mostly unmodified. The input may be a full HTML document, or it may be an HTML fragment. `bcat` outputs `<html>`, `<head>`, and `<body>` elements even if they are not included in the input. Miscellaneous options: * `-c`, `--command`: Interpret the remaining options as a command to be run whose output should be piped into the web browser. * `-p`, `--persist`: Have `bcat` serve requests until it is interrupted. Reloading the page in the browser will cause `bcat` to re-read the files (or re-run the command if used with the `--command` option). Standard input can only be read once and will produce no content on subsequent requests. * `-d`, `--debug`: Turn on verbose debug logging to standard error. Include this output when reporting defects if applicable. ## ENVIRONMENT * `BCAT_BROWSER`=default|firefox|safari|chrome|opera|<other>: The name of the browser to use by default. `bcat` maps this to an actual browser command based on the current platform. The special value "default" maps to the system default browser. * `BCAT_COMMAND`=<command>: The entire browser command line (to be executed by `/bin/sh`). This overrides the `BCAT_BROWSER` environment variable and makes the `--browser` (`-b`) option a no-op. This should only be necessary when running a browser unknown to bcat or in order to pass special arguments. ## EXAMPLES ### Basic Shell Examples With build tools: make test |bcat rake test |bcat As a clipboard viewer: pbpaste |bcat # mac xclip -o |bcat # X11 For previewing HTML: markdown README.md |bcat redcloth README.textile |bcat erb -T - template.erb |bcat mustache < template.mustache |bcat pygmentize -Ofull,style=colorful -f html main.c |bcat Regenerate the content each time the page is reloaded: bcat -pc markdown README.md As a simple man pager: export MANPAGER='col -b |bcat' man grep With git, selectively: git log -p --color |bcat git diff --color HEAD@{5d} HEAD |bcat With git, as the default PAGER: export GIT_PAGER=bcat git log -p git diff HEAD@{5d} HEAD As a log viewer: tail -n 1000 -f /var/log/messages |bcat tail -f $RAILS_ROOT/log/development.log |bcat Or, a remote log viewer: ssh example.org 'tail -n 1000 -f /var/log/syslog' |bcat ### Vim and vi Examples Preview current buffer as HTML: :!markdown % |bcat :!ronn -5 --pipe % |bcat Create keymappings: map ,pm :!markdown % \|bcat map ,pp :!pygmentize -Ofull,style=colorful -f html % \|bcat Use with `makeprg`: set makeprg=make\ \\\|bcat set makeprg=markdown\ %\ \\\|bcat set makeprg=testrb\ %\ \\\|bcat (Note that you may need to escape the `%` character with quotes if there's spaces in the pathname. For example: `!markdown '%' |bcat`.) ## SEE ALSO cat(1), tee(1), open(1) ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/contrib/���������������������������������������������������������������������������������0000755�0001750�0001750�00000000000�12063024111�013700� 5����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/contrib/bman�����������������������������������������������������������������������������0000755�0001750�0001750�00000001146�12063024111�014545� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/sh # Usage: bman <man-args> # Open manual page in browser with bcat. # # Original zsh version by Nick Stenning <http://github.com/nickstenning> # http://github.com/rtomayko/bcat/issues#issue/8 # # Ported to POSIX shell by Ryan Tomayko <http://github.com/rtomayko> set -e # we use normal bold and underline BOLD="\033[1m" EM="\033[3m" RESET="\033[0m" # pass argv directly over to man man "$@" | # replace ^H based bold and underline with ansi equivelants sed " s/_\(.\)/"$(echo "$EM")"\1"$(echo "$RESET")"/g s/\(.\)\1/"$(echo "$BOLD")"\1"$(echo "$RESET")"/g " | # pipe it into bcat bcat ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/metadata.yml�����������������������������������������������������������������������������0000644�0001750�0001750�00000003650�12063024111�014547� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������--- !ruby/object:Gem::Specification name: bcat version: !ruby/object:Gem::Version prerelease: false segments: - 0 - 6 - 2 version: 0.6.2 platform: ruby authors: - Ryan Tomayko autorequire: bindir: bin cert_chain: [] date: 2011-09-10 00:00:00 -07:00 default_executable: bcat dependencies: - !ruby/object:Gem::Dependency name: rack prerelease: false requirement: &id001 !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version segments: - 1 - 0 version: "1.0" type: :runtime version_requirements: *id001 description: pipe to browser utility email: rtomayko@gmail.com executables: - a2h - bcat - btee extensions: [] extra_rdoc_files: - COPYING files: - CONTRIBUTING - COPYING - INSTALLING - README - RELEASING - Rakefile - bcat.gemspec - bin/a2h - bin/bcat - bin/btee - contrib/bman - lib/bcat.rb - lib/bcat/ansi.rb - lib/bcat/browser.rb - lib/bcat/html.rb - lib/bcat/reader.rb - lib/bcat/server.rb - man/a2h.1 - man/a2h.1.ronn - man/bcat.1 - man/bcat.1.ronn - man/btee.1 - man/btee.1.ronn - man/index.html - test/contest.rb - test/test_bcat_a2h.rb - test/test_bcat_ansi.rb - test/test_bcat_browser.rb - test/test_bcat_head_parser.rb has_rdoc: true homepage: http://rtomayko.github.com/bcat/ licenses: [] post_install_message: rdoc_options: - --line-numbers - --inline-source require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version segments: - 0 version: "0" required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version segments: - 0 version: "0" requirements: [] rubyforge_project: rubygems_version: 1.3.6 signing_key: specification_version: 3 summary: Concatenate input from standard input, or one or more files, and write progressive output to a browser. test_files: [] ����������������������������������������������������������������������������������������bcat-0.6.2/README�����������������������������������������������������������������������������������0000644�0001750�0001750�00000003431�12063024111�013121� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat http://github.com/rtomayko/bcat git clone git://github.com/rtomayko/bcat.git gem install bcat bcat is a pipe to browser utility for use at the shell and within editors like Vim or Emacs. It reads from standard input, or one or more files, and streams output to a browser window: $ echo "hi mom" |bcat $ echo "hi mom" |bcat -T 'Important Message' $ echo "hi mom" |bcat -b chrome Plain text is converted to simple preformatted HTML with rudimentary support for ANSI/VT100 escape sequences (color, background, bold, underline, etc.) You can also pipe HTML into bcat, in which case input is written through to the browser unmodified: $ echo "<h1>hi mom</h1>" |bcat $ echo "*hi mom*" |markdown |bcat Output is displayed progressively as it's being read, making bcat especially useful with build tools or even commands like tail(1) that generate output over longer periods of time: $ make all |bcat $ rake test |bcat $ tail -f /var/log/syslog |bcat $ (while printf .; do sleep 1; done) |bcat See the bcat(1) EXAMPLES section for more on using bcat from the shell or within editors like Vim: <http://rtomayko.github.com/bcat/bcat.1.html#EXAMPLES> bcat was inspired by TextMate's HTML output capabilities and a desire to have them at the shell and also within editors like Vim or Emacs. See: <http://manual.macromates.com/en/commands#html_output> <http://blog.macromates.com/2005/html-output-for-commands/> Only a small portion of TextMate's HTML output features are currently supported, although more will be added in the future (like hyperlinking file:line references and injecting CSS/JavaScript). See the INSTALLING, COPYING, and CONTRIBUTING files for more information on those things. Copyright (c) 2010 by Ryan Tomayko <http://tomayko.com/about> ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/test/������������������������������������������������������������������������������������0000755�0001750�0001750�00000000000�12063024111�013217� 5����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/test/test_bcat_a2h.rb��������������������������������������������������������������������0000644�0001750�0001750�00000001030�12063024111�016240� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������require 'contest' ENV['PATH'] = [File.expand_path('../../bin'), ENV['PATH']].join(':') class ANSI2HTMLCommandTest < Test::Unit::TestCase test "piping stuff through a2h" do IO.popen("a2h", 'w+') do |io| io.sync = true io.puts "hello there" io.flush assert_equal "hello there\n", io.read("hello there\n".size) io.puts "and \x1b[1mhere's some bold" assert_equal "and <b>here's some bold\n", io.read(24) io.close_write assert_equal "</b>", io.read(4) io.close end end end ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/test/test_bcat_browser.rb����������������������������������������������������������������0000644�0001750�0001750�00000000601�12063024111�017254� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������require 'contest' require 'bcat/browser' class BrowserTest < Test::Unit::TestCase setup { @browser = Bcat::Browser.new('default', nil) } test 'shell quotes double-quotes, backticks, and parameter expansion' do assert_equal "\"http://example.com/\\\"/\\$(echo oops)/\\`echo howdy\\`\"", @browser.shell_quote("http://example.com/\"/$(echo oops)/`echo howdy`") end end �������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/test/contest.rb��������������������������������������������������������������������������0000644�0001750�0001750�00000003333�12063024111�015225� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������require "test/unit" # Test::Unit loads a default test if the suite is empty, whose purpose is to # fail. Since having empty contexts is a common practice, we decided to # overwrite TestSuite#empty? in order to allow them. Having a failure when no # tests have been defined seems counter-intuitive. class Test::Unit::TestSuite def empty? false end end # Contest adds +teardown+, +test+ and +context+ as class methods, and the # instance methods +setup+ and +teardown+ now iterate on the corresponding # blocks. Note that all setup and teardown blocks must be defined with the # block syntax. Adding setup or teardown instance methods defeats the purpose # of this library. class Test::Unit::TestCase def self.setup(&block) define_method :setup do super(&block) instance_eval(&block) end end def self.teardown(&block) define_method :teardown do instance_eval(&block) super(&block) end end def self.context(name, &block) subclass = Class.new(self) remove_tests(subclass) subclass.class_eval(&block) if block_given? const_set(context_name(name), subclass) end def self.test(name, &block) define_method(test_name(name), &block) end class << self alias_method :should, :test alias_method :describe, :context end private def self.context_name(name) "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym end def self.test_name(name) "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym end def self.sanitize_name(name) name.gsub(/\W+/, ' ').strip end def self.remove_tests(subclass) subclass.public_instance_methods.grep(/^test_/).each do |meth| subclass.send(:undef_method, meth.to_sym) end end end �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������bcat-0.6.2/test/test_bcat_head_parser.rb������������������������������������������������������������0000644�0001750�0001750�00000003132�12063024111�020050� 0����������������������������������������������������������������������������������������������������ustar �henrich�������������������������henrich����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������require 'contest' require 'bcat/html' class HeadParserTest < Test::Unit::TestCase setup { @parser = Bcat::HeadParser.new } test 'starts in an unknown state' do assert @parser.html?.nil? assert @parser.buf.empty? end test 'detects non-HTML input' do @parser.feed("HOWDY <h1>") assert_equal false, @parser.html? assert_equal '', @parser.head end test 'separates head elements from body' do @parser.feed("<style>h1{ font-size:500% }</style>") @parser.feed("<h1>HOLLA</h1>") assert_equal "<style>h1{ font-size:500% }</style>", @parser.head.strip assert_equal "<body>\n<h1>HOLLA</h1>", @parser.body end test 'handles multiple head elements' do stuff = [ "<style>h1{ font-size:500% }</style>", "<link rel=alternate>", "<script type='text/javascript'>{};</script>" ] stuff.each { |html| @parser.feed(html) } @parser.feed("\n \n\n\n<h1>HOLLA</h1>") assert_equal stuff.join, @parser.head.strip end test 'handles full documents' do @parser.feed("<!DOCTYPE html>\n") @parser.feed("<html><head><title>YO") @parser.feed("

OY

") assert_equal "YO", @parser.head.strip assert_equal "\n

OY

", @parser.body end test 'knows when the head is fully parsed' do @parser.feed("\n") assert !@parser.complete? @parser.feed("YO") assert !@parser.complete? @parser.feed("

OY

") assert @parser.complete? end end bcat-0.6.2/test/test_bcat_ansi.rb0000644000175000017500000000755312063024111016540 0ustar henrichhenrichrequire 'contest' require 'bcat/ansi' class ANSITest < Test::Unit::TestCase test 'should not modify input string' do text = "some text" Bcat::ANSI.new(text).to_html assert_equal "some text", text end test 'passing through text with no escapes' do text = "hello\nthis is bcat\n" ansi = Bcat::ANSI.new(text) assert_equal text, ansi.to_html end test "removing backspace characters" do text = "like this" ansi = Bcat::ANSI.new(text) assert_equal "like this", ansi.to_html end test "foreground colors" do text = "colors: \x1b[30mblack\x1b[37mwhite" expect = "colors: " + "black" + "white" + "" assert_equal expect, Bcat::ANSI.new(text).to_html end test "light foreground colors" do text = "colors: \x1b[90mblack\x1b[97mwhite" expect = "colors: " + "black" + "white" + "" assert_equal expect, Bcat::ANSI.new(text).to_html end test "background colors" do text = "colors: \x1b[40mblack\x1b[47mwhite" expect = "colors: " + "black" + "white" + "" assert_equal expect, Bcat::ANSI.new(text).to_html end test "light background colors" do text = "colors: \x1b[100mblack\x1b[107mwhite" expect = "colors: " + "black" + "white" + "" assert_equal expect, Bcat::ANSI.new(text).to_html end test "strikethrough" do text = "strike: \x1b[9mthat" expect = "strike: that" assert_equal expect, Bcat::ANSI.new(text).to_html end test "blink!" do text = "blink: \x1b[5mwhat" expect = "blink: what" assert_equal expect, Bcat::ANSI.new(text).to_html end test "underline" do text = "underline: \x1b[3mstuff" expect = "underline: stuff" assert_equal expect, Bcat::ANSI.new(text).to_html end test "bold" do text = "bold: \x1b[1mstuff" expect = "bold: stuff" assert_equal expect, Bcat::ANSI.new(text).to_html end test "resetting a single sequence" do text = "\x1b[1mthis is bold\x1b[0m, but this isn't" expect = "this is bold, but this isn't" assert_equal expect, Bcat::ANSI.new(text).to_html end test "resetting many sequences" do text = "normal, \x1b[1mbold, \x1b[3munderline, \x1b[31mred\x1b[0m, normal" expect = "normal, bold, underline, " + "red, normal" assert_equal expect, Bcat::ANSI.new(text).to_html end test "resetting without an implicit 0 argument" do text = "\x1b[1mthis is bold\x1b[m, but this isn't" expect = "this is bold, but this isn't" assert_equal expect, Bcat::ANSI.new(text).to_html end test "multi-attribute sequences" do text = "normal, \x1b[1;3;31mbold, underline, and red\x1b[0m, normal" expect = "normal, " + "bold, underline, and red, normal" assert_equal expect, Bcat::ANSI.new(text).to_html end test "multi-attribute sequences with a trailing semi-colon" do text = "normal, \x1b[1;3;31;mbold, underline, and red\x1b[0m, normal" expect = "normal, " + "bold, underline, and red, normal" assert_equal expect, Bcat::ANSI.new(text).to_html end test "eating malformed sequences" do text = "\x1b[25oops forgot the 'm'" expect = "oops forgot the 'm'" assert_equal expect, Bcat::ANSI.new(text).to_html end test "xterm-256" do text = "\x1b[38;5;196mhello" expect = "hello" assert_equal expect, Bcat::ANSI.new(text).to_html end end bcat-0.6.2/CONTRIBUTING0000644000175000017500000000061412063024111014073 0ustar henrichhenrichPlease submit pull requests to: For information on forking repositories and sending pull requests: If you prefer sending text patches, please use git-format-patch(1) to generate them so I can attribute you properly. Text patches can be submitted to the issue tracker: bcat-0.6.2/bcat.gemspec0000644000175000017500000000245012063024111014517 0ustar henrichhenrichGem::Specification.new do |s| s.name = 'bcat' s.version = '0.6.2' s.date = '2011-09-10' s.description = "pipe to browser utility" s.summary = "Concatenate input from standard input, or one or more files, " + "and write progressive output to a browser." s.authors = ["Ryan Tomayko"] s.email = "rtomayko@gmail.com" # = MANIFEST = s.files = %w[ CONTRIBUTING COPYING INSTALLING README RELEASING Rakefile bcat.gemspec bin/a2h bin/bcat bin/btee contrib/bman lib/bcat.rb lib/bcat/ansi.rb lib/bcat/browser.rb lib/bcat/html.rb lib/bcat/reader.rb lib/bcat/server.rb man/a2h.1 man/a2h.1.ronn man/bcat.1 man/bcat.1.ronn man/btee.1 man/btee.1.ronn man/index.html test/contest.rb test/test_bcat_a2h.rb test/test_bcat_ansi.rb test/test_bcat_browser.rb test/test_bcat_head_parser.rb ] # = MANIFEST = s.default_executable = 'bcat' s.executables = ['a2h', 'bcat', 'btee'] s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/} s.add_dependency 'rack', '~> 1.0' s.extra_rdoc_files = %w[COPYING] s.has_rdoc = true s.homepage = "http://rtomayko.github.com/bcat/" s.rdoc_options = ["--line-numbers", "--inline-source"] s.require_paths = %w[lib] end bcat-0.6.2/Rakefile0000644000175000017500000000447012063024111013712 0ustar henrichhenrichrequire 'date' task :default => :test ROOTDIR = File.expand_path('..', __FILE__).sub(/#{Dir.pwd}(?=\/)/, '.') LIBDIR = "#{ROOTDIR}/lib" BINDIR = "#{ROOTDIR}/bin" task :environment do $:.unshift ROOTDIR if !$:.include?(ROOTDIR) $:.unshift LIBDIR if !$:.include?(LIBDIR) ENV['RUBYLIB'] = $LOAD_PATH.join(':') ENV['PATH'] = "#{BINDIR}:#{ENV['PATH']}" end desc 'Run tests' task :test => :environment do $LOAD_PATH.unshift "#{ROOTDIR}/test" Dir['test/test_*.rb'].each { |f| require(f) } end def source_version @source_version ||= `ruby -Ilib -rbcat -e 'puts Bcat::VERSION'`.chomp end require 'rubygems' $spec = eval(File.read('bcat.gemspec')) desc "Build gem package" task :package => 'bcat.gemspec' do sh "gem build bcat.gemspec" end desc 'Build the manual' task :man do ENV['RONN_MANUAL'] = "Bcat #{source_version}" ENV['RONN_ORGANIZATION'] = "Ryan Tomayko" sh "ronn -stoc -w -r5 man/*.ronn" end desc 'Publish to github pages' task :pages => :man do puts '----------------------------------------------' puts 'Rebuilding pages ...' verbose(false) { rm_rf 'pages' push_url = `git remote show origin`.grep(/Push.*URL/).first[/git@.*/] sh " set -e git fetch -q origin rev=$(git rev-parse origin/gh-pages) git clone -q -b gh-pages . pages cd pages git reset --hard $rev rm -f *.html cp -rp ../man/*.html ../man/index.* ./ git add -u *.html index.* git commit -m 'rebuild manual' git push #{push_url} gh-pages ", :verbose => false } end file 'bcat.gemspec' => FileList['{lib,test,bin}/**','Rakefile'] do |f| # read spec file and split out manifest section spec = File.read(f.name) head, manifest, tail = spec.split(" # = MANIFEST =\n") # replace version and date head.sub!(/\.version = '.*'/, ".version = '#{source_version}'") head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'") # determine file list from git ls-files files = `git ls-files`. split("\n"). sort. reject{ |file| file =~ /^\./ }. reject { |file| file =~ /^doc/ }. map{ |file| " #{file}" }. join("\n") # piece file back together and write... manifest = " s.files = %w[\n#{files}\n ]\n" spec = [head,manifest,tail].join(" # = MANIFEST =\n") File.open(f.name, 'w') { |io| io.write(spec) } puts "updated #{f.name}" end bcat-0.6.2/COPYING0000644000175000017500000000205312063024111013273 0ustar henrichhenrichbcat Copyright (c) 2010 Ryan Tomayko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. bcat-0.6.2/INSTALLING0000644000175000017500000000060412063024111013627 0ustar henrichhenrichbcat is known to work under MacOS X, Linux, and FreeBSD (other UNIX-like environments with freedesktop.org integration should work fine too). Progressive output has been tested under Safari, Firefox, Chrome, and GNOME Epiphany. bcat is written in Ruby and requires a basic Ruby installation. Install bcat using the gem command: $ gem install bcat bcat depends on the rack package. bcat-0.6.2/RELEASING0000644000175000017500000000035212063024111013474 0ustar henrichhenrichRELEASING 1. Change Bcat::VERSION in lib/bcat.rb 2. rake bcat.gemspec 3. rake package 4. git add lib/bcat.rb bcat.gemspec 5. git commit -m "0.5.3 release" 6. git tag v0.5.3 7. git push origin master v0.5.3 8. gem push bcat-0.5.3.gem