ansi-sys 0.2.0
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/ChangeLog +188 -0
- data/History.txt +7 -0
- data/License.txt +34 -0
- data/Makefile +56 -0
- data/Manifest.txt +38 -0
- data/README.txt +37 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/gpl.rd.txt +674 -0
- data/lgpl.rd.txt +512 -0
- data/lib/ansisys.rb +595 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1637 -0
- data/spec/attach/test_data.html +17 -0
- data/spec/attach/test_data.txt +16 -0
- data/spec/character_screen_spec.rb +32 -0
- data/spec/character_spec.rb +45 -0
- data/spec/cursor_spec.rb +165 -0
- data/spec/hiki_spec.rb +39 -0
- data/spec/lexer_spec.rb +95 -0
- data/spec/screen_spec.rb +164 -0
- data/spec/sgr_spec.rb +172 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/terminal_spec.rb +82 -0
- data/tasks/deployment.rake +27 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +113 -0
- data/website/index.txt +57 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +132 -0
- data/website/template.rhtml +48 -0
- metadata +91 -0
data/spec/sgr_spec.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
$:.unshift('lib')
|
2
|
+
require 'ansisys'
|
3
|
+
|
4
|
+
include AnsiSys
|
5
|
+
describe SGR, 'when initialized' do
|
6
|
+
before do
|
7
|
+
@sgr = SGR.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have normal intensity" do @sgr.intensity.should == :normal; end
|
11
|
+
it "should have italic off" do @sgr.italic.should == :off; end
|
12
|
+
it "should have no underline" do @sgr.underline.should == :none; end
|
13
|
+
it "should have blink off" do @sgr.blink.should == :off; end
|
14
|
+
it "should have positive image" do @sgr.image.should == :positive; end
|
15
|
+
it "should have conceal off" do @sgr.conceal.should == :off; end
|
16
|
+
it "should have white foreground color" do @sgr.foreground.should == :white; end
|
17
|
+
it "should have black background color" do @sgr.background.should == :black; end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe SGR, 'when two are initialized' do
|
21
|
+
before do
|
22
|
+
@sgr1 = SGR.new
|
23
|
+
@sgr2 = SGR.new
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should be equal when initialized' do @sgr1.should == @sgr2; end
|
27
|
+
it 'should be different after a code is executed' do
|
28
|
+
@sgr2.apply_code!(%w(1 m))
|
29
|
+
@sgr1.should_not == @sgr2
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe SGR, 'when a code is executed' do
|
34
|
+
before do
|
35
|
+
@sgr = SGR.new
|
36
|
+
end
|
37
|
+
|
38
|
+
class Object
|
39
|
+
def change_only(accessor, expected, &block)
|
40
|
+
yield(self)
|
41
|
+
self.send(accessor).should == expected
|
42
|
+
other = self.class.new
|
43
|
+
other.instance_variable_set("@#{accessor}", expected)
|
44
|
+
other.should == self
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should treat empty parameter as a code 0' do
|
49
|
+
@sgr.apply_code!(['m'])
|
50
|
+
@sgr.should == SGR.new
|
51
|
+
end
|
52
|
+
it 'should have bold intensity with a code 1' do
|
53
|
+
@sgr.change_only(:intensity, :bold){|x| x.apply_code!(%w(1 m))}
|
54
|
+
end
|
55
|
+
it 'should have faint intensity with a code 2' do
|
56
|
+
@sgr.change_only(:intensity, :faint){|x| x.apply_code!(%w(2 m))}
|
57
|
+
end
|
58
|
+
it 'should be italic with a code 3' do
|
59
|
+
@sgr.change_only(:italic, :on){|x| x.apply_code!(%w(3 m))}
|
60
|
+
end
|
61
|
+
it 'should have single underline with a code 4' do
|
62
|
+
@sgr.change_only(:underline, :single){|x| x.apply_code!(%w(4 m))}
|
63
|
+
end
|
64
|
+
it 'should be concealed with a code 8' do
|
65
|
+
@sgr.change_only(:conceal, :on){|x| x.apply_code!(%w(8 m))}
|
66
|
+
end
|
67
|
+
it 'should be revealed with a code 28' do
|
68
|
+
@sgr.change_only(:conceal, :off) do |x|
|
69
|
+
x.apply_code!(%w(8 m))
|
70
|
+
x.apply_code!(%w(28 m))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
it 'should have green foreground with normal intensity with a code 32' do
|
74
|
+
@sgr.apply_code!(%w(1 m))
|
75
|
+
@sgr.apply_code!(%w(32 m))
|
76
|
+
@sgr.foreground.should == :green
|
77
|
+
@sgr.intensity.should == :normal
|
78
|
+
end
|
79
|
+
it 'should have white foreground with normal intensity with a code 39' do
|
80
|
+
@sgr.apply_code!(%w(32 m))
|
81
|
+
@sgr.apply_code!(%w(1 m))
|
82
|
+
@sgr.apply_code!(%w(39 m))
|
83
|
+
@sgr.foreground.should == :white
|
84
|
+
@sgr.intensity.should == :normal
|
85
|
+
end
|
86
|
+
it 'should have yellow background with normal intensity with a code 43' do
|
87
|
+
@sgr.apply_code!(%w(1 m))
|
88
|
+
@sgr.apply_code!(%w(43 m))
|
89
|
+
@sgr.background.should == :yellow
|
90
|
+
@sgr.intensity.should == :normal
|
91
|
+
end
|
92
|
+
it 'should have blue foreground with bold intensity with a code 94' do
|
93
|
+
@sgr.apply_code!(%w(1 m))
|
94
|
+
@sgr.apply_code!(%w(94 m))
|
95
|
+
@sgr.foreground.should == :blue
|
96
|
+
@sgr.intensity.should == :bold
|
97
|
+
end
|
98
|
+
it 'should have magenta background with bold intensity with a code 105' do
|
99
|
+
@sgr.apply_code!(%w(1 m))
|
100
|
+
@sgr.apply_code!(%w(105 m))
|
101
|
+
@sgr.background.should == :magenta
|
102
|
+
@sgr.intensity.should == :bold
|
103
|
+
end
|
104
|
+
it 'should have white background with bold intensity with a code 107' do
|
105
|
+
@sgr.apply_code!(%w(1 m))
|
106
|
+
@sgr.apply_code!(%w(107 m))
|
107
|
+
@sgr.background.should == :white
|
108
|
+
@sgr.intensity.should == :bold
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe SGR, 'when an invalid code is executed' do
|
113
|
+
before do
|
114
|
+
@sgr = SGR.new
|
115
|
+
end
|
116
|
+
|
117
|
+
[10, -1, 108].each do |invalid_code|
|
118
|
+
it "should raise an error with a code #{invalid_code}" do
|
119
|
+
lambda{@sgr.apply_code!([invalid_code, 'm'])}.should raise_error(AnsiSysError)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe SGR, 'to be rendered in HTML' do
|
125
|
+
before do
|
126
|
+
@sgr = SGR.new
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should make no CSS with defalt properties" do
|
130
|
+
@sgr.css_style.should == nil
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should change foreground color" do
|
134
|
+
@sgr.apply_code!(%w(32 m))
|
135
|
+
@sgr.css_styles.should == {'color' => ['green']}
|
136
|
+
end
|
137
|
+
|
138
|
+
it "shuold show underline for ANSI single underline" do
|
139
|
+
@sgr.apply_code!(%w(4 m))
|
140
|
+
@sgr.css_styles.should == {'text-decoration' => ['underline']}
|
141
|
+
end
|
142
|
+
|
143
|
+
it "shuold show underline for ANSI double underline" do
|
144
|
+
@sgr.apply_code!(%w(4 m))
|
145
|
+
@sgr.css_styles.should == {'text-decoration' => ['underline']}
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should switch foreground and background colors with reverse video" do
|
149
|
+
@sgr.apply_code!(%w(7 m))
|
150
|
+
@sgr.css_styles.should == {'color' => ['black'], 'background-color' => ['silver']}
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should blink for ANSI slow blink" do
|
154
|
+
@sgr.apply_code!(%w(5 m))
|
155
|
+
@sgr.css_styles.should == {'text-decoration' => ['blink']}
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should blink for ANSI fast blink" do
|
159
|
+
@sgr.apply_code!(%w(6 m))
|
160
|
+
@sgr.css_styles.should == {'text-decoration' => ['blink']}
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should be able to be italic" do
|
164
|
+
@sgr.apply_code!(%w(3 m))
|
165
|
+
@sgr.css_styles.should == {'font-style' => ['italic']}
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should be able to be invisible" do
|
169
|
+
@sgr.apply_code!(%w(8 m))
|
170
|
+
@sgr.css_styles.should == {'color' => ['black']}
|
171
|
+
end
|
172
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
$:.unshift('lib')
|
2
|
+
require 'ansisys'
|
3
|
+
|
4
|
+
include AnsiSys
|
5
|
+
|
6
|
+
describe Terminal, "when ascii is echoed" do
|
7
|
+
before do
|
8
|
+
@terminal = Terminal.new
|
9
|
+
@terminal.echo("Hello world")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should render an HTML as the original string" do
|
13
|
+
@terminal.render.should == %Q|<pre class="screen">\nHello world</pre>|
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should render a plain text as the original string" do
|
17
|
+
@terminal.render(:text).should == 'Hello world'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Terminal, 'when \n is echoed' do
|
22
|
+
before do
|
23
|
+
@terminal = Terminal.new
|
24
|
+
@terminal.echo("Hello\nworld")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should render an HTML with two rows" do
|
28
|
+
@terminal.render.should == %Q|<pre class="screen">\nHello\nworld</pre>|
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should render a plain text with two rows" do
|
32
|
+
@terminal.render(:text).should == %Q|Hello\nworld|
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Terminal, 'when SGR codes are echoed' do
|
37
|
+
before do
|
38
|
+
@terminal = Terminal.new
|
39
|
+
@terminal.echo("Hello \e[32mworld")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should render an HTML with color in span" do
|
43
|
+
@terminal.render.should == %Q|<pre class="screen">\nHello <span style="color: green">world</span></pre>|
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should render a plain text without colors" do
|
47
|
+
@terminal.render(:text).should == 'Hello world'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe Terminal, 'when SGR codes are echoed and non-standard colors are used' do
|
52
|
+
before do
|
53
|
+
@terminal = Terminal.new
|
54
|
+
@terminal.echo("Hello \e[32mworld")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should render an HTML with color in span" do
|
58
|
+
@terminal.render(:html, 80, 25, Screen.default_css_colors(false, true)).should == %Q|<pre class="screen">\nHello <span style="color: lime">world</span></pre>|
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Terminal do
|
63
|
+
before do
|
64
|
+
@terminal = Terminal.new
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should give CSS style-let" do
|
68
|
+
c = @terminal.css_style.split(/\n/)
|
69
|
+
e = <<"_CSS".split(/\n/)
|
70
|
+
pre.screen {
|
71
|
+
\tcolor: silver;
|
72
|
+
\tbackground-color: black;
|
73
|
+
\twidth: 40.0em;
|
74
|
+
\tpadding: 0.5em;
|
75
|
+
}
|
76
|
+
_CSS
|
77
|
+
c.size.should == e.size
|
78
|
+
c.each do |line|
|
79
|
+
e.should include(line)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
21
|
+
end
|
data/tasks/website.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate => :ruby_env do
|
3
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
+
remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
|
12
|
+
local_dir = 'website'
|
13
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate and upload website files'
|
17
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/website/index.html
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
Ruby-ANSI.SYS
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
12
|
+
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
32
|
+
|
33
|
+
<h1>Ruby-ANSI.SYS</h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/ansi-sys"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://rubyforge.org/projects/ansi-sys" class="numbers">0.2.0</a>
|
37
|
+
</div>
|
38
|
+
<h1>→ ‘ansi-sys’</h1>
|
39
|
+
|
40
|
+
|
41
|
+
<h2>What</h2>
|
42
|
+
|
43
|
+
|
44
|
+
<p>MS-DOS console (with <code>DEVICE=ANSI.SYS</code>), Linux
|
45
|
+
console, and other terminal emulators usually accept escape
|
46
|
+
sequences which tell the terminal change colors of the text or
|
47
|
+
move the cursor.</p>
|
48
|
+
|
49
|
+
|
50
|
+
<p>Ruby-ANSI.SYS is a Ruby library to render texts with
|
51
|
+
<a href="http://en.wikipedia.org/wiki/ANSI_escape_code"><span class="caps">ANSI</span> escape sequences</a>
|
52
|
+
(Wikipedia) as an <span class="caps">HTML</span> fragment . It can also be used as a plugin
|
53
|
+
for Hiki.</p>
|
54
|
+
|
55
|
+
|
56
|
+
<h2>Download</h2>
|
57
|
+
|
58
|
+
|
59
|
+
<p>Have a look at
|
60
|
+
<a href="http://rubyforge.org/projects/ansi-sys">the RubyForge Project Info</a></p>
|
61
|
+
|
62
|
+
|
63
|
+
<h2>Installation</h2>
|
64
|
+
|
65
|
+
|
66
|
+
<p>As a Ruby library:</p>
|
67
|
+
|
68
|
+
|
69
|
+
<pre>$ ruby setup.rb config
|
70
|
+
$ ruby setup.rb setup
|
71
|
+
# ruby setup.rb install</pre>
|
72
|
+
|
73
|
+
<p>As a Hiki plugin, copy the file lib/ansisys.rb into the
|
74
|
+
misc/plugin directory and configure Hiki to enable the plugin.</p>
|
75
|
+
|
76
|
+
|
77
|
+
<h2>Usage</h2>
|
78
|
+
|
79
|
+
|
80
|
+
<p>As a Ruby library:</p>
|
81
|
+
|
82
|
+
|
83
|
+
<pre>terminal = Terminal.new
|
84
|
+
terminal.echo("ansi-escaped-text")
|
85
|
+
terminal.render #=> HTML fragment</pre>
|
86
|
+
|
87
|
+
<p>As a Hiki plugin:</p>
|
88
|
+
|
89
|
+
|
90
|
+
<pre>{{ansi_screen(attach_file_name)}}</pre>
|
91
|
+
|
92
|
+
<h2>Contact</h2>
|
93
|
+
|
94
|
+
|
95
|
+
<p>Please send your comments and patches to
|
96
|
+
<a href="http://rubyforge.org/tracker/?group_id=4656">the RubyForge Trackers</a></p>
|
97
|
+
|
98
|
+
|
99
|
+
<h2>License</h2>
|
100
|
+
|
101
|
+
|
102
|
+
<p>Please refer
|
103
|
+
<a href="rdoc/files/License_txt.html">License.txt</a></p>
|
104
|
+
<p class="coda">
|
105
|
+
zunda, 20th October 2007<br>
|
106
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
107
|
+
</p>
|
108
|
+
</div>
|
109
|
+
|
110
|
+
<!-- insert site tracking codes here, like Google Urchin -->
|
111
|
+
|
112
|
+
</body>
|
113
|
+
</html>
|