ansi-sys 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +14 -0
- data/Manifest.txt +1 -0
- data/lib/ansisys.rb +86 -34
- data/spec/attach/test_utf8.txt +1 -0
- data/spec/cursor_spec.rb +33 -35
- data/spec/screen_spec.rb +4 -4
- data/spec/sgr_spec.rb +30 -30
- data/spec/terminal_spec.rb +144 -0
- data/website/index.html +2 -2
- metadata +5 -3
data/ChangeLog
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
* 2007-10-27 zunda <zunda at freeshell.org>
|
2
|
+
- (0.4.0)
|
3
|
+
- lib/ansisys.rb: implemented SU, SD, SCP, and RCP onto Terminal
|
4
|
+
- not to be implemented: DSR
|
5
|
+
|
6
|
+
* 2007-10-26 zunda <zunda at freeshell.org>
|
7
|
+
- lib/ansisys.rb: implemented ED and EL onto Terminal
|
8
|
+
- more to be done: SU SD DSR SCP RCP
|
9
|
+
|
10
|
+
* 2007-10-26 zunda <zunda at freeshell.org>
|
11
|
+
- lib/ansisys.rb: modified arguments of apply_code! to avoid
|
12
|
+
decoding of arguments into a letter and parameters
|
13
|
+
- spec/attach/test_utf8.txt: added
|
14
|
+
|
1
15
|
* 2007-10-23 zunda <zunda at freeshell.org>
|
2
16
|
- (0.3.0)
|
3
17
|
- lib/ansisys.rb: convert string to EUC as a Hiki plugin
|
data/Manifest.txt
CHANGED
data/lib/ansisys.rb
CHANGED
@@ -11,7 +11,7 @@ require 'webrick'
|
|
11
11
|
module AnsiSys
|
12
12
|
module VERSION #:nodoc:
|
13
13
|
MAJOR = 0
|
14
|
-
MINOR =
|
14
|
+
MINOR = 4
|
15
15
|
TINY = 0
|
16
16
|
|
17
17
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
@@ -136,18 +136,7 @@ module AnsiSys
|
|
136
136
|
@max_row = max_row
|
137
137
|
end
|
138
138
|
|
139
|
-
def apply_code!(
|
140
|
-
letter = args.pop
|
141
|
-
pars = args.map do |arg|
|
142
|
-
case arg
|
143
|
-
when nil
|
144
|
-
nil
|
145
|
-
when ''
|
146
|
-
nil
|
147
|
-
else
|
148
|
-
Integer(arg)
|
149
|
-
end
|
150
|
-
end
|
139
|
+
def apply_code!(letter, *pars)
|
151
140
|
case letter
|
152
141
|
when 'A'
|
153
142
|
@cur_row -= pars[0] ? pars[0] : 1
|
@@ -229,14 +218,12 @@ module AnsiSys
|
|
229
218
|
end
|
230
219
|
|
231
220
|
def reset!
|
232
|
-
apply_code!(
|
221
|
+
apply_code!('m', 0)
|
233
222
|
end
|
234
223
|
|
235
|
-
def apply_code!(
|
236
|
-
letter
|
237
|
-
|
238
|
-
pars = args.map{|arg| arg.to_i}
|
239
|
-
pars = [0] if pars.empty?
|
224
|
+
def apply_code!(letter = 'm', *pars)
|
225
|
+
raise AnsiSysError, "Invalid code for SGR: #{letter.inspect}" unless 'm' == letter
|
226
|
+
pars = [0] unless pars
|
240
227
|
pars.each do |code|
|
241
228
|
case code
|
242
229
|
when 0
|
@@ -435,6 +422,8 @@ module AnsiSys
|
|
435
422
|
return "pre.screen {\n\t" + CSSFormatter.hash_to_styles(self.css_styles(*args), ";\n\t") + ";\n}\n"
|
436
423
|
end
|
437
424
|
|
425
|
+
attr_reader :lines
|
426
|
+
|
438
427
|
def initialize(colors = Screen.default_css_colors, max_col = nil, max_row = nil)
|
439
428
|
@colors = colors
|
440
429
|
@max_col = max_col
|
@@ -501,13 +490,13 @@ module AnsiSys
|
|
501
490
|
return result
|
502
491
|
end
|
503
492
|
|
504
|
-
def apply_code!(
|
493
|
+
def apply_code!(letter, *pars) # TODO - some codes
|
505
494
|
return self
|
506
495
|
end
|
507
496
|
end
|
508
497
|
|
509
498
|
class Terminal
|
510
|
-
CODE_LETTERS =
|
499
|
+
CODE_LETTERS = %w(J K S T n s u)
|
511
500
|
|
512
501
|
def initialize(csis = ["\x1b["])
|
513
502
|
@lexer = Lexer.new(csis)
|
@@ -539,38 +528,101 @@ module AnsiSys
|
|
539
528
|
return screens.map{|screen| screen.render(format, css_class, css_style)}.join(separator)
|
540
529
|
end
|
541
530
|
|
531
|
+
def apply_code!(letter, *pars)
|
532
|
+
case letter
|
533
|
+
when 'J'
|
534
|
+
cur_col = @cursor.cur_col
|
535
|
+
cur_row = @cursor.cur_row
|
536
|
+
lines = @screens[-1].lines
|
537
|
+
if pars.empty? or 0 == pars[0]
|
538
|
+
rs = lines.keys.select{|r| r > cur_row}
|
539
|
+
cs = lines[cur_row].keys.select{|c| c >= cur_col}
|
540
|
+
elsif 1 == pars[0]
|
541
|
+
rs = lines.keys.select{|r| r < cur_row}
|
542
|
+
cs = lines[cur_row].keys.select{|c| c <= cur_col}
|
543
|
+
elsif 2 == pars[0]
|
544
|
+
rs = lines.keys
|
545
|
+
cs = []
|
546
|
+
@cursor.apply_code!('H', 1, 1)
|
547
|
+
end
|
548
|
+
rs.each do |r|
|
549
|
+
lines.delete(r)
|
550
|
+
end
|
551
|
+
cs.each do |c|
|
552
|
+
lines[cur_row].delete(c)
|
553
|
+
end
|
554
|
+
when 'K'
|
555
|
+
cur_col = @cursor.cur_col
|
556
|
+
cur_row = @cursor.cur_row
|
557
|
+
line = @screens[-1].lines[cur_row]
|
558
|
+
if pars.empty? or 0 == pars[0]
|
559
|
+
cs = line.keys.select{|c| c >= cur_col}
|
560
|
+
elsif 1 == pars[0]
|
561
|
+
cs = line.keys.select{|c| c <= cur_col}
|
562
|
+
elsif 2 == pars[0]
|
563
|
+
cs = line.keys
|
564
|
+
end
|
565
|
+
cs.each do |c|
|
566
|
+
line.delete(c)
|
567
|
+
end
|
568
|
+
when 'S'
|
569
|
+
lines = @screens[-1].lines
|
570
|
+
n = pars.empty? ? 1 : pars[0]
|
571
|
+
n.times do |l|
|
572
|
+
lines.delete(l)
|
573
|
+
end
|
574
|
+
rs = lines.keys.sort
|
575
|
+
rs.each do |r|
|
576
|
+
lines[r-n] = lines[r]
|
577
|
+
lines.delete(r)
|
578
|
+
end
|
579
|
+
@cursor.apply_code!('H', rs[-1] - n + 1, 1)
|
580
|
+
when 'T'
|
581
|
+
lines = @screens[-1].lines
|
582
|
+
n = pars.empty? ? 1 : pars[0]
|
583
|
+
rs = lines.keys.sort_by{|a| -a} # sort.reverse
|
584
|
+
rs.each do |r|
|
585
|
+
lines[r+n] = lines[r]
|
586
|
+
lines.delete(r)
|
587
|
+
end
|
588
|
+
@cursor.apply_code!('H', rs[-1] - n + 1, 1)
|
589
|
+
when 's'
|
590
|
+
@stored_cursor = @cursor.dup
|
591
|
+
when 'u'
|
592
|
+
@cursor = @stored_cursor.dup if @stored_cursor
|
593
|
+
end
|
594
|
+
|
595
|
+
return self
|
596
|
+
end
|
597
|
+
|
542
598
|
private
|
543
599
|
def populate(format = :html, max_col = 80, max_row = nil, colors = Screen.default_css_colors)
|
544
|
-
cursor = Cursor.new(1, 1, max_col, max_row)
|
545
|
-
|
546
|
-
|
600
|
+
@cursor = Cursor.new(1, 1, max_col, max_row)
|
601
|
+
@stored_cursor = nil
|
602
|
+
@screens = [Screen.new(colors, max_col, max_row)]
|
603
|
+
@sgr = SGR.new
|
547
604
|
@stream += @lexer.lex!
|
548
605
|
@stream.each do |type, payload|
|
549
606
|
case type
|
550
607
|
when :string
|
551
|
-
Characters.new(payload, sgr).echo_on(screens[-1], cursor)
|
608
|
+
Characters.new(payload, @sgr).echo_on(@screens[-1], @cursor)
|
552
609
|
when :code
|
553
610
|
unless Lexer::PARAMETER_AND_LETTER =~ payload
|
554
611
|
raise AnsiSysError, "Invalid code: #{payload.inspect}"
|
555
612
|
end
|
556
|
-
parameters = $1
|
557
613
|
letter = $2
|
558
|
-
|
614
|
+
pars = $1.split(/;/).map{|i| i.to_i}
|
559
615
|
applied = false
|
560
|
-
[sgr, cursor, screens[-1], self].each do |recv|
|
616
|
+
[@sgr, @cursor, @screens[-1], self].each do |recv|
|
561
617
|
if recv.class.const_get(:CODE_LETTERS).include?(letter)
|
562
|
-
recv.apply_code!(
|
618
|
+
recv.apply_code!(letter, *pars)
|
563
619
|
applied = true
|
564
620
|
end
|
565
621
|
end
|
566
622
|
raise AnsiSysError, "Invalid code or not implemented: #{payload.inspect}" unless applied
|
567
623
|
end
|
568
624
|
end
|
569
|
-
return screens
|
570
|
-
end
|
571
|
-
|
572
|
-
def apply_code!(args) # TODO - make a new screen
|
573
|
-
return self
|
625
|
+
return @screens
|
574
626
|
end
|
575
627
|
end
|
576
628
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
日本語でUTF-8のテキストファイル。
|
data/spec/cursor_spec.rb
CHANGED
@@ -26,46 +26,46 @@ describe Cursor, 'when moved normally' do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should move up with code CUU" do
|
29
|
-
lambda{@cursor.apply_code!(
|
30
|
-
lambda{@cursor.apply_code!(
|
31
|
-
lambda{@cursor.apply_code!(
|
29
|
+
lambda{@cursor.apply_code!('A')}.should change(@cursor, :cur_row).by(-1)
|
30
|
+
lambda{@cursor.apply_code!('A', 1)}.should change(@cursor, :cur_row).by(-1)
|
31
|
+
lambda{@cursor.apply_code!('A', 2)}.should change(@cursor, :cur_row).by(-2)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should move down with code CUD" do
|
35
|
-
lambda{@cursor.apply_code!(
|
36
|
-
lambda{@cursor.apply_code!(
|
37
|
-
lambda{@cursor.apply_code!(
|
35
|
+
lambda{@cursor.apply_code!('B')}.should change(@cursor, :cur_row).by(1)
|
36
|
+
lambda{@cursor.apply_code!('B', 1)}.should change(@cursor, :cur_row).by(1)
|
37
|
+
lambda{@cursor.apply_code!('B', 2)}.should change(@cursor, :cur_row).by(2)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should move to right with code CUF" do
|
41
|
-
lambda{@cursor.apply_code!(
|
42
|
-
lambda{@cursor.apply_code!(
|
43
|
-
lambda{@cursor.apply_code!(
|
41
|
+
lambda{@cursor.apply_code!('C')}.should change(@cursor, :cur_col).by(1)
|
42
|
+
lambda{@cursor.apply_code!('C', 1)}.should change(@cursor, :cur_col).by(1)
|
43
|
+
lambda{@cursor.apply_code!('C', 2)}.should change(@cursor, :cur_col).by(2)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should move to left with code CUB" do
|
47
|
-
lambda{@cursor.apply_code!(
|
48
|
-
lambda{@cursor.apply_code!(
|
49
|
-
lambda{@cursor.apply_code!(
|
47
|
+
lambda{@cursor.apply_code!('D')}.should change(@cursor, :cur_col).by(-1)
|
48
|
+
lambda{@cursor.apply_code!('D', 1)}.should change(@cursor, :cur_col).by(-1)
|
49
|
+
lambda{@cursor.apply_code!('D', 2)}.should change(@cursor, :cur_col).by(-2)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should move to beggining of lower line with CNL" do
|
53
|
-
[[1,
|
54
|
-
lambda{@cursor.apply_code!(code)}.should change(@cursor, :cur_row).by(d)
|
53
|
+
[[1, 'E'], [1, ['E', 1]], [2, ['E', 2]]].each do |d, code|
|
54
|
+
lambda{@cursor.apply_code!(*code)}.should change(@cursor, :cur_row).by(d)
|
55
55
|
@cursor.cur_col.should == 1
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should move to beggining of upper line with CPL" do
|
60
|
-
[[-1,
|
61
|
-
lambda{@cursor.apply_code!(code)}.should change(@cursor, :cur_row).by(d)
|
60
|
+
[[-1, ['F']], [-1, ['F', 1]], [-2, ['F', 2]]].each do |d, code|
|
61
|
+
lambda{@cursor.apply_code!(*code)}.should change(@cursor, :cur_row).by(d)
|
62
62
|
@cursor.cur_col.should == 1
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should move to specified column with CHA" do
|
67
|
-
[[1,
|
68
|
-
lambda{@cursor.apply_code!(code)}.should_not change(@cursor, :cur_row)
|
67
|
+
[[1, ['G']], [1, ['G', 1]], [2, ['G', 2]]].each do |c, code|
|
68
|
+
lambda{@cursor.apply_code!(*code)}.should_not change(@cursor, :cur_row)
|
69
69
|
@cursor.cur_col.should == c
|
70
70
|
end
|
71
71
|
end
|
@@ -73,16 +73,14 @@ describe Cursor, 'when moved normally' do
|
|
73
73
|
it "should move to specified position with CUP and HVP" do
|
74
74
|
%w(H f).each do |letter|
|
75
75
|
[
|
76
|
-
# row, column,
|
77
|
-
[1, 5, [nil,
|
78
|
-
[1, 5, [
|
79
|
-
[
|
80
|
-
[17, 1, [
|
81
|
-
[
|
82
|
-
|
83
|
-
|
84
|
-
].each do |r, c, code|
|
85
|
-
@cursor.apply_code!(code + [letter])
|
76
|
+
# row, column, pars
|
77
|
+
[1, 5, [nil, 5]],
|
78
|
+
[1, 5, [1, 5]],
|
79
|
+
[17, 1, [17, nil]],
|
80
|
+
[17, 1, [17, 1]],
|
81
|
+
[9, 8, [9, 8]],
|
82
|
+
].each do |r, c, pars|
|
83
|
+
@cursor.apply_code!(letter, *pars)
|
86
84
|
@cursor.cur_col.should == c
|
87
85
|
@cursor.cur_row.should == r
|
88
86
|
end
|
@@ -98,36 +96,36 @@ describe Cursor, 'when tried to be moved beyond edge' do
|
|
98
96
|
|
99
97
|
it "should not move with code CUU" do
|
100
98
|
@cursor.instance_variable_set('@cur_row', 1)
|
101
|
-
lambda{@cursor.apply_code!(
|
99
|
+
lambda{@cursor.apply_code!('A', 1)}.should_not change(@cursor, :cur_row)
|
102
100
|
end
|
103
101
|
|
104
102
|
it "should not move with code CUD" do
|
105
103
|
@cursor.instance_variable_set('@cur_row', @cursor.max_row)
|
106
|
-
lambda{@cursor.apply_code!(
|
104
|
+
lambda{@cursor.apply_code!('B', 1)}.should_not change(@cursor, :cur_row)
|
107
105
|
end
|
108
106
|
|
109
107
|
it "should not move with code CUF" do
|
110
108
|
@cursor.instance_variable_set('@cur_col', @cursor.max_col)
|
111
|
-
lambda{@cursor.apply_code!(
|
109
|
+
lambda{@cursor.apply_code!('C', 1)}.should_not change(@cursor, :cur_col)
|
112
110
|
end
|
113
111
|
|
114
112
|
it "should not move with code CUB" do
|
115
113
|
@cursor.instance_variable_set('@cur_col', 1)
|
116
|
-
lambda{@cursor.apply_code!(
|
114
|
+
lambda{@cursor.apply_code!('D', 1)}.should_not change(@cursor, :cur_col)
|
117
115
|
end
|
118
116
|
|
119
117
|
it "should make screen longer with code CNL" do
|
120
118
|
@cursor.instance_variable_set('@cur_row', @cursor.max_row)
|
121
|
-
lambda{@cursor.apply_code!(
|
119
|
+
lambda{@cursor.apply_code!('E', 1)}.should change(@cursor, :max_row).by(1)
|
122
120
|
end
|
123
121
|
|
124
122
|
it "should not change row with code CNL" do
|
125
123
|
@cursor.instance_variable_set('@cur_row', 1)
|
126
|
-
lambda{@cursor.apply_code!(
|
124
|
+
lambda{@cursor.apply_code!('F', 1)}.should_not change(@cursor, :cur_row)
|
127
125
|
end
|
128
126
|
|
129
127
|
it "should move to edge column with code CHA" do
|
130
|
-
lambda{@cursor.apply_code!(
|
128
|
+
lambda{@cursor.apply_code!('G', 99)}.should change(@cursor, :cur_col).to(@cursor.max_col)
|
131
129
|
end
|
132
130
|
|
133
131
|
end
|
data/spec/screen_spec.rb
CHANGED
@@ -73,7 +73,7 @@ _SCREEN
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should change colors" do
|
76
|
-
@sgr.apply_code!(
|
76
|
+
@sgr.apply_code!('m', 32)
|
77
77
|
@screen.write(':', 1, 1, 1, @sgr)
|
78
78
|
@screen.write(')', 1, 2, 1, @sgr)
|
79
79
|
@screen.render(:html).should == <<_SCREEN.chomp
|
@@ -99,7 +99,7 @@ describe Screen, "with default colors" do
|
|
99
99
|
@screen.write('l', 1, 5, 1, @sgr)
|
100
100
|
@screen.write('l', 1, 6, 1, @sgr)
|
101
101
|
@screen.write('o', 1, 7, 1, @sgr)
|
102
|
-
@sgr.apply_code!(
|
102
|
+
@sgr.apply_code!('m', 32)
|
103
103
|
@screen.write(':', 1, 1, 1, @sgr)
|
104
104
|
@screen.write(')', 1, 2, 1, @sgr)
|
105
105
|
end
|
@@ -122,7 +122,7 @@ describe Screen, "with inverted colors" do
|
|
122
122
|
@screen.write('l', 1, 5, 1, @sgr)
|
123
123
|
@screen.write('l', 1, 6, 1, @sgr)
|
124
124
|
@screen.write('o', 1, 7, 1, @sgr)
|
125
|
-
@sgr.apply_code!(
|
125
|
+
@sgr.apply_code!('m', 32)
|
126
126
|
@screen.write(':', 1, 1, 1, @sgr)
|
127
127
|
@screen.write(')', 1, 2, 1, @sgr)
|
128
128
|
end
|
@@ -145,7 +145,7 @@ describe Screen, "with bright colors" do
|
|
145
145
|
@screen.write('l', 1, 5, 1, @sgr)
|
146
146
|
@screen.write('l', 1, 6, 1, @sgr)
|
147
147
|
@screen.write('o', 1, 7, 1, @sgr)
|
148
|
-
@sgr.apply_code!(
|
148
|
+
@sgr.apply_code!('m', 32)
|
149
149
|
@screen.write(':', 1, 1, 1, @sgr)
|
150
150
|
@screen.write(')', 1, 2, 1, @sgr)
|
151
151
|
end
|
data/spec/sgr_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe SGR, 'when two are initialized' do
|
|
25
25
|
|
26
26
|
it 'should be equal when initialized' do @sgr1.should == @sgr2; end
|
27
27
|
it 'should be different after a code is executed' do
|
28
|
-
@sgr2.apply_code!(
|
28
|
+
@sgr2.apply_code!('m', 1)
|
29
29
|
@sgr1.should_not == @sgr2
|
30
30
|
end
|
31
31
|
end
|
@@ -46,64 +46,64 @@ describe SGR, 'when a code is executed' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should treat empty parameter as a code 0' do
|
49
|
-
@sgr.apply_code!(
|
49
|
+
@sgr.apply_code!('m')
|
50
50
|
@sgr.should == SGR.new
|
51
51
|
end
|
52
52
|
it 'should have bold intensity with a code 1' do
|
53
|
-
@sgr.change_only(:intensity, :bold){|x| x.apply_code!(
|
53
|
+
@sgr.change_only(:intensity, :bold){|x| x.apply_code!('m', 1)}
|
54
54
|
end
|
55
55
|
it 'should have faint intensity with a code 2' do
|
56
|
-
@sgr.change_only(:intensity, :faint){|x| x.apply_code!(
|
56
|
+
@sgr.change_only(:intensity, :faint){|x| x.apply_code!('m', 2)}
|
57
57
|
end
|
58
58
|
it 'should be italic with a code 3' do
|
59
|
-
@sgr.change_only(:italic, :on){|x| x.apply_code!(
|
59
|
+
@sgr.change_only(:italic, :on){|x| x.apply_code!('m', 3)}
|
60
60
|
end
|
61
61
|
it 'should have single underline with a code 4' do
|
62
|
-
@sgr.change_only(:underline, :single){|x| x.apply_code!(
|
62
|
+
@sgr.change_only(:underline, :single){|x| x.apply_code!('m', 4)}
|
63
63
|
end
|
64
64
|
it 'should be concealed with a code 8' do
|
65
|
-
@sgr.change_only(:conceal, :on){|x| x.apply_code!(
|
65
|
+
@sgr.change_only(:conceal, :on){|x| x.apply_code!('m', 8)}
|
66
66
|
end
|
67
67
|
it 'should be revealed with a code 28' do
|
68
68
|
@sgr.change_only(:conceal, :off) do |x|
|
69
|
-
x.apply_code!(
|
70
|
-
x.apply_code!(
|
69
|
+
x.apply_code!('m', 8)
|
70
|
+
x.apply_code!('m', 28)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
it 'should have green foreground with normal intensity with a code 32' do
|
74
|
-
@sgr.apply_code!(
|
75
|
-
@sgr.apply_code!(
|
74
|
+
@sgr.apply_code!('m', 1)
|
75
|
+
@sgr.apply_code!('m', 32)
|
76
76
|
@sgr.foreground.should == :green
|
77
77
|
@sgr.intensity.should == :normal
|
78
78
|
end
|
79
79
|
it 'should have white foreground with normal intensity with a code 39' do
|
80
|
-
@sgr.apply_code!(
|
81
|
-
@sgr.apply_code!(
|
82
|
-
@sgr.apply_code!(
|
80
|
+
@sgr.apply_code!('m', 32)
|
81
|
+
@sgr.apply_code!('m', 1)
|
82
|
+
@sgr.apply_code!('m', 39)
|
83
83
|
@sgr.foreground.should == :white
|
84
84
|
@sgr.intensity.should == :normal
|
85
85
|
end
|
86
86
|
it 'should have yellow background with normal intensity with a code 43' do
|
87
|
-
@sgr.apply_code!(
|
88
|
-
@sgr.apply_code!(
|
87
|
+
@sgr.apply_code!('m', 1)
|
88
|
+
@sgr.apply_code!('m', 43)
|
89
89
|
@sgr.background.should == :yellow
|
90
90
|
@sgr.intensity.should == :normal
|
91
91
|
end
|
92
92
|
it 'should have blue foreground with bold intensity with a code 94' do
|
93
|
-
@sgr.apply_code!(
|
94
|
-
@sgr.apply_code!(
|
93
|
+
@sgr.apply_code!('m', 1)
|
94
|
+
@sgr.apply_code!('m', 94)
|
95
95
|
@sgr.foreground.should == :blue
|
96
96
|
@sgr.intensity.should == :bold
|
97
97
|
end
|
98
98
|
it 'should have magenta background with bold intensity with a code 105' do
|
99
|
-
@sgr.apply_code!(
|
100
|
-
@sgr.apply_code!(
|
99
|
+
@sgr.apply_code!('m', 1)
|
100
|
+
@sgr.apply_code!('m', 105)
|
101
101
|
@sgr.background.should == :magenta
|
102
102
|
@sgr.intensity.should == :bold
|
103
103
|
end
|
104
104
|
it 'should have white background with bold intensity with a code 107' do
|
105
|
-
@sgr.apply_code!(
|
106
|
-
@sgr.apply_code!(
|
105
|
+
@sgr.apply_code!('m', 1)
|
106
|
+
@sgr.apply_code!('m', 107)
|
107
107
|
@sgr.background.should == :white
|
108
108
|
@sgr.intensity.should == :bold
|
109
109
|
end
|
@@ -131,42 +131,42 @@ describe SGR, 'to be rendered in HTML' do
|
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should change foreground color" do
|
134
|
-
@sgr.apply_code!(
|
134
|
+
@sgr.apply_code!('m', 32)
|
135
135
|
@sgr.css_styles.should == {'color' => ['green']}
|
136
136
|
end
|
137
137
|
|
138
138
|
it "shuold show underline for ANSI single underline" do
|
139
|
-
@sgr.apply_code!(
|
139
|
+
@sgr.apply_code!('m', 4)
|
140
140
|
@sgr.css_styles.should == {'text-decoration' => ['underline']}
|
141
141
|
end
|
142
142
|
|
143
143
|
it "shuold show underline for ANSI double underline" do
|
144
|
-
@sgr.apply_code!(
|
144
|
+
@sgr.apply_code!('m', 4)
|
145
145
|
@sgr.css_styles.should == {'text-decoration' => ['underline']}
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should switch foreground and background colors with reverse video" do
|
149
|
-
@sgr.apply_code!(
|
149
|
+
@sgr.apply_code!('m', 7)
|
150
150
|
@sgr.css_styles.should == {'color' => ['black'], 'background-color' => ['silver']}
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should blink for ANSI slow blink" do
|
154
|
-
@sgr.apply_code!(
|
154
|
+
@sgr.apply_code!('m', 5)
|
155
155
|
@sgr.css_styles.should == {'text-decoration' => ['blink']}
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should blink for ANSI fast blink" do
|
159
|
-
@sgr.apply_code!(
|
159
|
+
@sgr.apply_code!('m', 6)
|
160
160
|
@sgr.css_styles.should == {'text-decoration' => ['blink']}
|
161
161
|
end
|
162
162
|
|
163
163
|
it "should be able to be italic" do
|
164
|
-
@sgr.apply_code!(
|
164
|
+
@sgr.apply_code!('m', 3)
|
165
165
|
@sgr.css_styles.should == {'font-style' => ['italic']}
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should be able to be invisible" do
|
169
|
-
@sgr.apply_code!(
|
169
|
+
@sgr.apply_code!('m', 8)
|
170
170
|
@sgr.css_styles.should == {'color' => ['black']}
|
171
171
|
end
|
172
172
|
end
|
data/spec/terminal_spec.rb
CHANGED
@@ -80,3 +80,147 @@ _CSS
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe Terminal, 'when code ED is sent' do
|
85
|
+
before do
|
86
|
+
@terminal = Terminal.new
|
87
|
+
@terminal.echo("Hello\nand\ngood bye\nworld\e[2;2H")
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should clear from cursor to end of screen with J' do
|
91
|
+
@terminal.echo("\e[J")
|
92
|
+
@terminal.render(:text).should == "Hello\na"
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should clear from cursor to end of screen with 0J' do
|
96
|
+
@terminal.echo("\e[0J")
|
97
|
+
@terminal.render(:text).should == "Hello\na"
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should clear from cursor to beggining of screen with 1J' do
|
101
|
+
@terminal.echo("\e[1J")
|
102
|
+
@terminal.render(:text).should == "\n d\ngood bye\nworld"
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should clear entier screen with 2J' do
|
106
|
+
@terminal.echo("\e[2J")
|
107
|
+
@terminal.render(:text).should == ""
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should move cursor to top left with 2J' do
|
111
|
+
@terminal.echo("\e[2JX")
|
112
|
+
@terminal.render(:text).should == "X"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe Terminal, 'when code EL is sent' do
|
117
|
+
before do
|
118
|
+
@terminal = Terminal.new
|
119
|
+
@terminal.echo("red\ngreen\nrefactor\e[2;2H")
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should clear from cursor to end of line with K' do
|
123
|
+
@terminal.echo("\e[K")
|
124
|
+
@terminal.render(:text).should == "red\ng\nrefactor"
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should clear from cursor to end of line with K' do
|
128
|
+
@terminal.echo("\e[0K")
|
129
|
+
@terminal.render(:text).should == "red\ng\nrefactor"
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should clear from cursor to beginning of line with K' do
|
133
|
+
@terminal.echo("\e[1K")
|
134
|
+
@terminal.render(:text).should == "red\n een\nrefactor"
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should clear entier line with 2K' do
|
138
|
+
@terminal.echo("\e[2K")
|
139
|
+
@terminal.render(:text).should == "red\n\nrefactor"
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should not move cursor with 2K' do
|
143
|
+
@terminal.echo("\e[2KX")
|
144
|
+
@terminal.render(:text).should == "red\n X\nrefactor"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe Terminal, 'when code SU is sent' do
|
149
|
+
before do
|
150
|
+
@terminal = Terminal.new
|
151
|
+
@terminal.echo("red\ngreen\n\nrefactor\e[2;2H")
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'shuold scroll down by one line with S' do
|
155
|
+
@terminal.echo("\e[S")
|
156
|
+
@terminal.render(:text).should == "green\n\nrefactor"
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'shuold scroll down by one line with 1S' do
|
160
|
+
@terminal.echo("\e[1S")
|
161
|
+
@terminal.render(:text).should == "green\n\nrefactor"
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'shuold scroll down by two lines with 2S' do
|
165
|
+
@terminal.echo("\e[2S")
|
166
|
+
@terminal.render(:text).should == "\nrefactor"
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'shuold append a line at the bottom after S' do
|
170
|
+
@terminal.echo("\e[2SX")
|
171
|
+
@terminal.render(:text).should == "\nrefactor\nX"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe Terminal, 'when code SD is sent' do
|
176
|
+
before do
|
177
|
+
@terminal = Terminal.new
|
178
|
+
@terminal.echo("red\ngreen\n\nrefactor\e[2;2H")
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'shuold scroll up by one line with T' do
|
182
|
+
@terminal.echo("\e[T")
|
183
|
+
@terminal.render(:text).should == "\nred\ngreen\n\nrefactor"
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'shuold scroll up by one line with 1T' do
|
187
|
+
@terminal.echo("\e[1T")
|
188
|
+
@terminal.render(:text).should == "\nred\ngreen\n\nrefactor"
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'shuold scroll up by two lines with 2T' do
|
192
|
+
@terminal.echo("\e[2T")
|
193
|
+
@terminal.render(:text).should == "\n\nred\ngreen\n\nrefactor"
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'shuold append a line at the top after T' do
|
197
|
+
@terminal.echo("\e[2TX")
|
198
|
+
@terminal.render(:text).should == "X\n\nred\ngreen\n\nrefactor"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe Terminal, 'when code SCP and RCP is sent' do
|
203
|
+
before do
|
204
|
+
@terminal = Terminal.new
|
205
|
+
@terminal.echo("red\ngreen\nrefactor\e[2;2H")
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should save and restore the cursor position' do
|
209
|
+
@terminal.echo("\e[sXX\nY\e[uZ")
|
210
|
+
@terminal.render(:text).should == "red\ngZXen\nYefactor"
|
211
|
+
@terminal.echo("\e[uz")
|
212
|
+
@terminal.render(:text).should == "red\ngzXen\nYefactor"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe Terminal, 'when only code RCP is sent' do
|
217
|
+
before do
|
218
|
+
@terminal = Terminal.new
|
219
|
+
@terminal.echo("red\ngreen\nrefactor\n\e[2;2H")
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should ignore the code' do
|
223
|
+
@terminal.echo("\e[udone")
|
224
|
+
@terminal.render(:text).should == "red\ngdone\nrefactor"
|
225
|
+
end
|
226
|
+
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Ruby-ANSI.SYS</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/ansi-sys"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/ansi-sys" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/ansi-sys" class="numbers">0.4.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘ansi-sys’</h1>
|
39
39
|
|
@@ -110,7 +110,7 @@ terminal.render #=> HTML fragment</pre>
|
|
110
110
|
<p>Please refer
|
111
111
|
<a href="rdoc/files/License_txt.html">License.txt</a></p>
|
112
112
|
<p class="coda">
|
113
|
-
zunda,
|
113
|
+
zunda, 21st October 2007<br>
|
114
114
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
115
115
|
</p>
|
116
116
|
</div>
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: ansi-sys
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-10-
|
6
|
+
version: 0.4.0
|
7
|
+
date: 2007-10-27 00:00:00 -10:00
|
8
8
|
summary: Ruby-ANSI.SYS is a library to render texts with ANSI escape sequences.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- setup.rb
|
49
49
|
- spec/attach/test_data.html
|
50
50
|
- spec/attach/test_data.txt
|
51
|
+
- spec/attach/test_utf8.txt
|
51
52
|
- spec/character_screen_spec.rb
|
52
53
|
- spec/character_spec.rb
|
53
54
|
- spec/cursor_spec.rb
|
@@ -80,6 +81,7 @@ extra_rdoc_files:
|
|
80
81
|
- gpl.rd.txt
|
81
82
|
- lgpl.rd.txt
|
82
83
|
- spec/attach/test_data.txt
|
84
|
+
- spec/attach/test_utf8.txt
|
83
85
|
- website/index.txt
|
84
86
|
executables: []
|
85
87
|
|