few 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +49 -0
- data/bin/few +108 -0
- metadata +55 -0
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Few
|
2
|
+
|
3
|
+
When you're trying to build an application on your terminal, how would you see
|
4
|
+
the README file? `less` is common. But `less` uses a whole screen. These days
|
5
|
+
most terminal emulator softwares support transparency. You can see other
|
6
|
+
softwares under the terminal. If you can open the README file under the terminal
|
7
|
+
beautifully, it must be useful. That's the reason why `few` was created.
|
8
|
+
|
9
|
+
## USAGE
|
10
|
+
|
11
|
+
$ few README
|
12
|
+
|
13
|
+
$ cat README | few
|
14
|
+
|
15
|
+
$ few -v
|
16
|
+
0.0.1
|
17
|
+
|
18
|
+
$ few --selfupdate
|
19
|
+
0.0.2
|
20
|
+
|
21
|
+
## DEVELOPERS
|
22
|
+
|
23
|
+
The principles of `few`
|
24
|
+
|
25
|
+
* Does not require any non-standard libraries
|
26
|
+
* Works every Ruby from 1.8.6 to 1.9.2
|
27
|
+
* Which means you have to avoid Enumerators and to care about Encodings
|
28
|
+
|
29
|
+
Future plan
|
30
|
+
|
31
|
+
* markdown
|
32
|
+
* vim syntax highlight
|
33
|
+
* ssh over few
|
34
|
+
|
35
|
+
## LICENCE
|
36
|
+
|
37
|
+
Ruby's Licence (GPL + MIT)
|
38
|
+
|
39
|
+
## TWITTER BOT
|
40
|
+
|
41
|
+
[@fewc](http://twitter.com/fewc)
|
42
|
+
|
43
|
+
## AUTHORS
|
44
|
+
|
45
|
+
* Tatsuhiro Ujihisa <http://ujihisa.blogspot.com/>
|
46
|
+
* Sora Harakami <http://codnote.net/>
|
47
|
+
* Haruo Nanki <http://blog.netswitch.jp/>
|
48
|
+
|
49
|
+
vim: filetype=markdown
|
data/bin/few
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'cgi'
|
5
|
+
require 'kconv'
|
6
|
+
|
7
|
+
def open_browser(path)
|
8
|
+
case RUBY_PLATFORM
|
9
|
+
when /darwin/
|
10
|
+
system 'open', path
|
11
|
+
when /mswin(?!ce)|mingw|cygwin|bccwin/
|
12
|
+
system 'start', path
|
13
|
+
else
|
14
|
+
system 'firefox', path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def require_monad(*libraries)
|
19
|
+
libraries.all? {|l|
|
20
|
+
begin
|
21
|
+
require l.to_s
|
22
|
+
rescue LoadError
|
23
|
+
end
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
require_monad :rubygems, :markdown
|
28
|
+
|
29
|
+
def few(filetype = 'text')
|
30
|
+
t = Tempfile.new('few')
|
31
|
+
|
32
|
+
File.open(t.path, 'w') do |io|
|
33
|
+
a = CGI.escapeHTML ARGF.read.toutf8
|
34
|
+
a = a.gsub(/\r?\n/, "<br />\n")
|
35
|
+
|
36
|
+
# NOTE: Currently " " doesn't work on ujihisa's environment.
|
37
|
+
# This may be because of the font you use.
|
38
|
+
|
39
|
+
a = a.gsub(/^(\s+)(.+)<br \/>$/) { '<p style="text-indent: ' + ($1.size/2.0).to_s + 'em;">' + $2 + '</p>' }
|
40
|
+
a = a.gsub(/\s{2,}/) {|m| ' '*(m.size*1.5).to_i }
|
41
|
+
a = a.gsub(/.\x08/, '')
|
42
|
+
a = a.gsub(/\x1b\[([0-9]*)m/) do
|
43
|
+
case $1
|
44
|
+
when "","39"
|
45
|
+
'</font>'
|
46
|
+
when "30"
|
47
|
+
'<font color="black">'
|
48
|
+
when "31"
|
49
|
+
'<font color="red">'
|
50
|
+
when "32"
|
51
|
+
'<font color="green">'
|
52
|
+
when "33"
|
53
|
+
'<font color="yellow">'
|
54
|
+
when "34"
|
55
|
+
'<font color="blue">'
|
56
|
+
when "35"
|
57
|
+
'<font color="magenta">'
|
58
|
+
when "36"
|
59
|
+
'<font color="cyan">'
|
60
|
+
when "37"
|
61
|
+
'<font color="white">'
|
62
|
+
else
|
63
|
+
''
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
io.puts <<-EOF
|
68
|
+
<html>
|
69
|
+
<head>
|
70
|
+
<title>few: #{ARGF.filename} (#{filetype})</title>
|
71
|
+
<style type="text/css">
|
72
|
+
p { margin: 0; }
|
73
|
+
</style>
|
74
|
+
</head>
|
75
|
+
<body>
|
76
|
+
#{a}
|
77
|
+
</body>
|
78
|
+
</html>
|
79
|
+
EOF
|
80
|
+
end
|
81
|
+
|
82
|
+
t.close
|
83
|
+
|
84
|
+
File.rename(t.path, html = t.path + '.html')
|
85
|
+
|
86
|
+
open_browser(html)
|
87
|
+
end
|
88
|
+
|
89
|
+
case ARGV[0]
|
90
|
+
when '-h', '--help'
|
91
|
+
puts "[USAGE]: few {filename}"
|
92
|
+
puts " cat {filename} | few"
|
93
|
+
when '-v', '--version'
|
94
|
+
puts "0.0.1"
|
95
|
+
when '--selfupdate'
|
96
|
+
require 'open-uri'
|
97
|
+
code = open('http://github.com/ujihisa/few/raw/master/few') {|io| io.read }
|
98
|
+
raise unless /^#!/ =~ code
|
99
|
+
File.open(__FILE__, 'w') {|io| io.print code }
|
100
|
+
system __FILE__, '-v'
|
101
|
+
when /--filetype=([a-zA-Z0-9]+)/
|
102
|
+
ARGV.shift
|
103
|
+
few $1
|
104
|
+
else
|
105
|
+
few
|
106
|
+
end
|
107
|
+
|
108
|
+
# vim: set filetype=ruby : set tabstop=2 : set shiftwidth=2
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: few
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ujihisa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-06 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: more -> less -> few
|
17
|
+
email: ujihisa at gmail.com
|
18
|
+
executables:
|
19
|
+
- few
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.md
|
24
|
+
files:
|
25
|
+
- README.md
|
26
|
+
has_rdoc: true
|
27
|
+
homepage: https://github.com/ujihisa/few
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- bin
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: more -> less -> few
|
54
|
+
test_files: []
|
55
|
+
|