sc-ansi 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe ANSI::Cursor do
4
+ include ANSI
5
+
6
+ it "should save cursor position" do
7
+ save_cursor_position.should == "\e[s"
8
+ end
9
+
10
+ it "should restore cursor position" do
11
+ restore_cursor_position.should == "\e[u"
12
+ end
13
+
14
+ context "#move_up" do
15
+ it "should move up (2)" do
16
+ move_up(2).should == "\e[2A"
17
+ end
18
+
19
+ it "should move up ()" do
20
+ move_up().should == "\e[1A"
21
+ end
22
+ end
23
+
24
+ context "#move_to" do
25
+ it "should change cursor position (1, 2)" do
26
+ move_to(1, 2).should == "\e[2;1H"
27
+ end
28
+
29
+ it "should change cursor position (1)" do
30
+ move_to(1).should == "\e[0;1H"
31
+ end
32
+
33
+ it "should change cursor position ()" do
34
+ move_to.should == "\e[0;0H"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ANSI::Display do
4
+ include ANSI
5
+
6
+ it "should set 40x25m mode" do
7
+ set_40x25m.should == "\e[=0h"
8
+ end
9
+
10
+ it "should unset 40x25m mode" do
11
+ unset_40x25m.should == "\e[=0l"
12
+ end
13
+
14
+ it "should erase display" do
15
+ erase_display.should == "\e[2J"
16
+ end
17
+
18
+ it "should erase line" do
19
+ erase_line.should == "\e[K"
20
+ end
21
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe ANSI::Match do
4
+ include ANSI
5
+ # [ #<ANSI::Match:0x102162cd8 @args=["31"], @codes=[SET_COLOR, RED]>,
6
+ # #<ANSI::Match:0x101598c68 @args=["0"], @codes=[SET_COLOR, RESET_COLOR, REGULAR, VT100_CHAR_ATTRS_OFF]>
7
+ # ]
8
+
9
+ subject { s = ANSI::Match.new("31"); s.codes << ANSI::SET_COLOR << ANSI::RED; s }
10
+
11
+ it "should inspect more legibly" do
12
+ subject.inspect.should == '#<ANSI::Match(SET_COLOR|RED) args=["31"]>'
13
+ end
14
+
15
+ it "should equal any code it contains" do
16
+ subject.should == ANSI::SET_COLOR
17
+ subject.should == ANSI::RED
18
+ end
19
+
20
+ it "should not equal codes it does not contain" do
21
+ subject.should_not == ANSI::GREEN
22
+ end
23
+
24
+ it "should equal identical copies of itself" do
25
+ subject.should == subject.dup
26
+ end
27
+
28
+ it "should equal constants that are the same code with a different name" do
29
+ subject.should == ANSI::COLOR
30
+ end
31
+
32
+ context "with a copy of itself with different args" do
33
+ before(:each) { @copy = ANSI::Match.new("32"); @copy.codes << ANSI::SET_COLOR << ANSI::RED }
34
+
35
+ it "should not equal the copy" do
36
+ subject.should_not == @copy
37
+ end
38
+ end
39
+
40
+ context "with a copy of itself with different codes" do
41
+ before(:each) { @copy = ANSI::Match.new("31"); @copy.codes << ANSI::GREEN }
42
+
43
+ it "should not equal the copy" do
44
+ subject.should_not == @copy
45
+ end
46
+ end
47
+
48
+ context "with any other object" do
49
+ it "should not equal the object" do
50
+ subject.should_not == 1
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe ANSI do
4
+ include ANSI
5
+
6
+ context "#generate_sequence" do
7
+ it "should work for 'blink'" do
8
+ ANSI.generate_sequence('blink').should == "\e[5m"
9
+ end
10
+
11
+ it "should work for 'color'" do
12
+ ANSI.generate_sequence('color').should == "\e[m"
13
+ end
14
+
15
+ it "should work for 'move'" do
16
+ ANSI.generate_sequence('move').should == "\e[{?}{?}"
17
+ end
18
+
19
+ it "should work for 'move_up'" do
20
+ ANSI.generate_sequence('move_up').should == "\e[{?}A"
21
+ end
22
+ end
23
+
24
+ it "should define a new ANSI code with no arguments" do
25
+ ANSI.define(:bizarro) { "\e[asdf" }
26
+ bizarro.should == "\e[asdf"
27
+ end
28
+
29
+ context "for an ANSI code with 1 argument " do
30
+ before(:each) { ANSI.define(:bizarro) { |a| "\e[#{a}a" } }
31
+
32
+ it "should accept 0 arguments" do
33
+ bizarro.should == "\e[a"
34
+ end
35
+
36
+ it "should accept 1 argument" do
37
+ bizarro(1).should == "\e[1a"
38
+ end
39
+
40
+ it "should raise argument error with 2 arguments" do
41
+ proc { bizarro(1, 2) }.should raise_error(ArgumentError)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ describe Object do
2
+ context "#instance_exec" do
3
+ class Dummy
4
+ def value
5
+ :dummy_value
6
+ end
7
+ end
8
+
9
+ subject { Dummy.new }
10
+
11
+ it "should work with args" do
12
+ # Block returns the value passed to it and the value of #value from the Dummy, in whose context
13
+ # it will be eval'd.
14
+ block = lambda { |a| [a, value] }
15
+
16
+ subject.instance_exec(:arg_value, &block).should == [:arg_value, :dummy_value]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ describe String do
2
+ include ANSI
3
+
4
+ context "red { 'hello' }" do
5
+ subject { ANSI.red { "hello" } }
6
+
7
+ # this example is used in String core ext docs, so it better work!
8
+ it "another replace_ansi case test" do
9
+ subject.replace_ansi do |match|
10
+ case match
11
+ when ANSI::RED then "(red)"
12
+ when ANSI::RESET_COLOR then "(normal)"
13
+ else raise "not expected: #{match}"
14
+ end
15
+ end.should == "(red)hello(normal)"
16
+ end
17
+ end
18
+
19
+ context "move_up + hello + move_down" do
20
+ subject { move_up + " hello " + move_down }
21
+
22
+ it "should return an array of ANSI escape sequences" do
23
+ subject.ansi_sequences.should == [ ANSI::CURSOR_UP, ANSI::CURSOR_DOWN ]
24
+ end
25
+
26
+ # This example is used in README, so it better work!
27
+ it "should replace ansi with custom content" do
28
+ subject.replace_ansi do |match|
29
+ case match
30
+ when ANSI::CURSOR_UP
31
+ "(up)"
32
+ when ANSI::CURSOR_DOWN
33
+ "(down)"
34
+ else
35
+ raise "not expected: #{match}"
36
+ end
37
+ end.should == "(up) hello (down)"
38
+ end
39
+ end
40
+
41
+ context "red + hello + reset_color" do
42
+ subject { red { "hello there" } }
43
+
44
+ it "should return an array of ANSI escape sequences" do
45
+ subject.ansi_sequences.should == [ ANSI::RED, ANSI::RESET_COLOR ]
46
+ end
47
+ end
48
+
49
+ context "the regular expression" do
50
+ subject { String::ANSI_ESCAPE_SEQUENCE_RX }
51
+
52
+ it "should be able to find args in 'blink_red_on_white'" do
53
+ subject =~ blink_red_on_white
54
+ $~[2].should == "5;31;47"
55
+ end
56
+
57
+ it "should match all defined escape sequences" do
58
+ ANSI.dynamically_defined_methods.each do |method_name|
59
+ sequence = ANSI.generate_sequence(method_name)
60
+ begin
61
+ subject.should match(sequence)
62
+ rescue
63
+ raise "Regexp #{String::ANSI_ESCAPE_SEQUENCE_RX} did not match sequence #{sequence.inspect} (for #{method_name})"
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,10 @@
1
+ $DEBUG ||= ENV['DEBUG']
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'sc-ansi'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+ config.before(:each) { ANSI.reset! if $DEBUG }
10
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sc-ansi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Colin MacKenzie IV
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-05 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sc-core-ext
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 1
31
+ version: 1.2.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 9
45
+ version: 1.2.9
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Handles every aspect (that I could think of) of dealing with ANSI escape sequences.
49
+ email: sinisterchipmunk@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.rdoc
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - lib/ansi.rb
65
+ - lib/ansi/code.rb
66
+ - lib/ansi/color.rb
67
+ - lib/ansi/cursor.rb
68
+ - lib/ansi/display.rb
69
+ - lib/ansi/match.rb
70
+ - lib/ansi/vt100.rb
71
+ - lib/core_ext/object.rb
72
+ - lib/core_ext/string.rb
73
+ - lib/sc-ansi.rb
74
+ - sc-ansi.gemspec
75
+ - spec/lib/ansi/color_spec.rb
76
+ - spec/lib/ansi/cursor_spec.rb
77
+ - spec/lib/ansi/display_spec.rb
78
+ - spec/lib/ansi/match_spec.rb
79
+ - spec/lib/ansi_spec.rb
80
+ - spec/lib/core_ext/object_spec.rb
81
+ - spec/lib/core_ext/string_spec.rb
82
+ - spec/spec.opts
83
+ - spec/spec_helper.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/sinisterchipmunk/sc-ansi
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.6
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Handles every aspect (that I could think of) of dealing with ANSI escape sequences.
114
+ test_files:
115
+ - spec/lib/ansi/color_spec.rb
116
+ - spec/lib/ansi/cursor_spec.rb
117
+ - spec/lib/ansi/display_spec.rb
118
+ - spec/lib/ansi/match_spec.rb
119
+ - spec/lib/ansi_spec.rb
120
+ - spec/lib/core_ext/object_spec.rb
121
+ - spec/lib/core_ext/string_spec.rb
122
+ - spec/spec_helper.rb