window_blessing 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/Guardfile +7 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +43 -0
  6. data/Rakefile +12 -0
  7. data/bin/buffered_screen_demo.rb +92 -0
  8. data/bin/color_picker_demo.rb +176 -0
  9. data/bin/foiled_demo.rb +27 -0
  10. data/bin/text_editor_demo.rb +292 -0
  11. data/bin/windowed_screen_demo.rb +71 -0
  12. data/bin/xterm_screen_demo.rb +33 -0
  13. data/lib/window_blessing.rb +54 -0
  14. data/lib/window_blessing/buffer.rb +216 -0
  15. data/lib/window_blessing/buffered_screen.rb +29 -0
  16. data/lib/window_blessing/color.rb +71 -0
  17. data/lib/window_blessing/constants.rb +3 -0
  18. data/lib/window_blessing/event_manager.rb +75 -0
  19. data/lib/window_blessing/event_queue.rb +20 -0
  20. data/lib/window_blessing/evented.rb +19 -0
  21. data/lib/window_blessing/evented_variable.rb +47 -0
  22. data/lib/window_blessing/tools.rb +124 -0
  23. data/lib/window_blessing/version.rb +3 -0
  24. data/lib/window_blessing/widgets/draggable_background.rb +13 -0
  25. data/lib/window_blessing/widgets/label.rb +23 -0
  26. data/lib/window_blessing/widgets/slider.rb +53 -0
  27. data/lib/window_blessing/widgets/text_field.rb +92 -0
  28. data/lib/window_blessing/window.rb +273 -0
  29. data/lib/window_blessing/windowed_screen.rb +53 -0
  30. data/lib/window_blessing/xterm_event_parser.rb +156 -0
  31. data/lib/window_blessing/xterm_input.rb +40 -0
  32. data/lib/window_blessing/xterm_log.rb +7 -0
  33. data/lib/window_blessing/xterm_output.rb +213 -0
  34. data/lib/window_blessing/xterm_screen.rb +109 -0
  35. data/lib/window_blessing/xterm_state.rb +27 -0
  36. data/spec/buffer_spec.rb +170 -0
  37. data/spec/color_spec.rb +36 -0
  38. data/spec/spec_helper.rb +6 -0
  39. data/spec/tools_spec.rb +142 -0
  40. data/spec/window_spec.rb +61 -0
  41. data/window_blessing.gemspec +28 -0
  42. metadata +226 -0
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module WindowBlessing
4
+ describe "Color" do
5
+ include Tools
6
+
7
+ it "to_hex" do
8
+ color(1,0.5,0.25).to_hex.should == "#ff7f3f"
9
+ end
10
+
11
+ it "init" do
12
+ c = color
13
+ c[:r] = 1.0
14
+ c[:g] = 0.5
15
+ c[:b] = 0.25
16
+ c.to_hex.should == "#ff7f3f"
17
+ c[:r].should == 1.0
18
+ c[:g].should == 0.5
19
+ c[:b].should == 0.25
20
+
21
+ c = color
22
+ c[0] = 1.0
23
+ c[1] = 0.5
24
+ c[2] = 0.25
25
+ c.to_hex.should == "#ff7f3f"
26
+ c[0].should == 1.0
27
+ c[1].should == 0.5
28
+ c[2].should == 0.25
29
+ end
30
+
31
+ it "from hex" do
32
+ color("#abc").to_hex.should == "#aabbcc"
33
+ color("#abcdef").to_hex.should == "#abcdef"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "vendor/ruby"
4
+ end
5
+
6
+ require File.join(File.dirname(__FILE__),"..","lib","window_blessing")
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ module WindowBlessing
4
+ describe "Tools" do
5
+ include Tools
6
+
7
+ it "overlapping_span with strings" do
8
+ overlapping_span(13, "abcd", 12).should == [12,""]
9
+ overlapping_span(13, "a", 12).should == [12,""]
10
+ overlapping_span(13, "", 12).should == [12,""]
11
+ overlapping_span(10, "abcd", 12).should == [10,"ab"]
12
+ overlapping_span(10, "abcd", 14).should == [10,"abcd"]
13
+ overlapping_span(10, "abcd", 16).should == [10,"abcd"]
14
+ overlapping_span(9, "abcd", 12).should == [9,"abc"]
15
+
16
+ overlapping_span(0, "abcd", 12).should == [0,"abcd"]
17
+ overlapping_span(-2, "abcd", 12).should == [0,"cd"]
18
+ end
19
+
20
+ it "overlapping_span with strings where length is less than span" do
21
+ overlapping_span(-5, "abcd", 0).should == [0,""]
22
+ overlapping_span(-1, "abcd", 0).should == [0,""]
23
+ overlapping_span(0, "abcd", 0).should == [0,""]
24
+ overlapping_span(1, "abcd", 0).should == [0,""]
25
+
26
+ overlapping_span(-5, "abcd", 1).should == [1,""]
27
+ overlapping_span(-1, "abcd", 1).should == [0,"b"]
28
+ overlapping_span(0, "abcd", 1).should == [0,"a"]
29
+ overlapping_span(1, "abcd", 1).should == [1,""]
30
+ end
31
+
32
+ it "overlapping_span with arrays" do
33
+ overlapping_span(13, %w{a b c d}, 12).should == [12,[]]
34
+ overlapping_span(13, [], 12).should == [12,[]]
35
+ overlapping_span(12, %w{a b c d}, 12).should == [12,[]]
36
+ overlapping_span(10, %w{a b c d}, 12).should == [10,%w{a b}]
37
+ overlapping_span(9, %w{a b c d}, 12).should == [9,%w{a b c}]
38
+ overlapping_span(0, %w{a b c d}, 12).should == [0,%w{a b c d}]
39
+ overlapping_span(-2, %w{a b c d}, 12).should == [0,%w{c d}]
40
+ end
41
+
42
+ it "overlay_span" do
43
+ overlay_span(-5, "abcd", "").should == ""
44
+ overlay_span(-1, "abcd", "").should == ""
45
+ overlay_span( 0, "abcd", "").should == ""
46
+ overlay_span( 1, "abcd", "").should == ""
47
+
48
+ overlay_span(-5, "abcd", "0").should == "0"
49
+ overlay_span(-1, "abcd", "0").should == "b"
50
+ overlay_span( 0, "abcd", "0").should == "a"
51
+ overlay_span( 1, "abcd", "0").should == "0"
52
+
53
+ overlay_span(-5, "abcd", "0123456789").should == "0123456789"
54
+ overlay_span(-4, "abcd", "0123456789").should == "0123456789"
55
+ overlay_span(-3, "abcd", "0123456789").should == "d123456789"
56
+ overlay_span(-1, "abcd", "0123456789").should == "bcd3456789"
57
+ overlay_span(0, "abcd", "0123456789").should == "abcd456789"
58
+ overlay_span(1, "abcd", "0123456789").should == "0abcd56789"
59
+ overlay_span(5, "abcd", "0123456789").should == "01234abcd9"
60
+ overlay_span(8, "abcd", "0123456789").should == "01234567ab"
61
+ overlay_span(9, "abcd", "0123456789").should == "012345678a"
62
+ overlay_span(10, "abcd", "0123456789").should == "0123456789"
63
+ overlay_span(11, "abcd", "0123456789").should == "0123456789"
64
+
65
+ end
66
+
67
+ it "overlay_span with block" do
68
+ overlay_span(2, [1, 2, 3, 4], 10.times.collect {|a|-a}) {|e| e+10}.should == [0, -1, 11, 12, 13, 14, -6, -7, -8, -9]
69
+ overlay_span(2, [1, 2, 3, 4], 10.times.collect {|a|-a}) {|e,i| e+i}.should == [0, -1, -1, -1, -1, -1, -6, -7, -8, -9]
70
+ end
71
+
72
+ it "fill_line" do
73
+ fill_line("a", 5).should == "aaaaa"
74
+ fill_line("ab", 5).should == "ababa"
75
+ fill_line("ab", 6).should == "ababab"
76
+ fill_line("ab", 1).should == "a"
77
+ fill_line("ab", 0).should == ""
78
+ end
79
+
80
+ it "resize2d string" do
81
+ r = resize2d([],point(2,3),"1")
82
+ r.should == ["11", "11", "11"]
83
+
84
+ r = resize2d(r,point(3,3),"2")
85
+ r.should == ["112", "112", "112"]
86
+
87
+ r = resize2d(r,point(3,2),"3")
88
+ r.should == ["112", "112"]
89
+
90
+ r = ["1","22","333"]
91
+ r = resize2d(r,point(3,4),"-")
92
+ r.should == ["1--", "22-", "333", "---"]
93
+ end
94
+
95
+ it "resize2d array" do
96
+ r = resize2d([],point(2,3),1)
97
+ r.should == [[1, 1], [1, 1], [1, 1]]
98
+
99
+ r = resize2d(r,point(3,3),2)
100
+ r.should == [[1, 1, 2], [1, 1, 2], [1, 1, 2]]
101
+
102
+ r = resize2d(r,point(3,2),3)
103
+ r.should == [[1, 1, 2], [1, 1, 2]]
104
+
105
+ r = [[1],[2,2],[3,3,3]]
106
+ r = resize2d(r,point(3,4),4)
107
+ r.should == [[1, 4, 4], [2, 2, 4], [3, 3, 3], [4, 4, 4]]
108
+ end
109
+
110
+ it "subarray2d string" do
111
+ r = ["123", "456", "789"]
112
+ subarray2d(r,rect(1,1,2,2)).should == ["56", "89"]
113
+ subarray2d(r,rect(1,2,2,2)).should == ["89"]
114
+ subarray2d(r,rect(2,1,2,2)).should == ["6", "9"]
115
+
116
+ subarray2d(r,rect(-1,1,2,2)).should == ["4", "7"]
117
+ subarray2d(r,rect(1,-1,2,2)).should == ["23"]
118
+ end
119
+
120
+ it "subarray2d array" do
121
+ r = [[1,2,3], [4,5,6], [7,8,9]]
122
+ subarray2d(r,rect(1,1,2,2)).should == [[5,6], [8,9]]
123
+ subarray2d(r,rect(1,2,2,2)).should == [[8,9]]
124
+ subarray2d(r,rect(2,1,2,2)).should == [[6], [9]]
125
+
126
+ subarray2d(r,rect(-1,1,2,2)).should == [[4], [7]]
127
+ subarray2d(r,rect(1,-1,2,2)).should == [[2,3]]
128
+ end
129
+
130
+ it "gen_array2d string" do
131
+ gen_array2d(point(1,1), "-=").should == ["-"]
132
+ gen_array2d(point(3,3), "-=").should == ["-=-", "=-=", "-=-"]
133
+ gen_array2d(point(4,4), "123").should == ["1231", "2312", "3123", "1231"]
134
+ end
135
+
136
+ it "gen_array2d array" do
137
+ gen_array2d(point(1,1), [1, 2]).should == [[1]]
138
+ gen_array2d(point(3,3), [1, 2]).should == [[1,2,1], [2,1,2], [1,2,1]]
139
+ gen_array2d(point(4,4), [1, 2, 3]).should == [[1, 2, 3, 1], [2, 3, 1, 2], [3, 1, 2, 3], [1,2,3,1]]
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ module WindowBlessing
4
+ describe "Window" do
5
+ include Tools
6
+
7
+ it "init" do
8
+ w = window rect(0,0,4,4)
9
+ w.area.should == rect(0,0,4,4)
10
+ w.buffer.to_s.should == " \n \n \n "
11
+ end
12
+
13
+ it "inspect" do
14
+ w = window rect(0,0,4,4)
15
+ w.inspect.class.should == String
16
+ end
17
+
18
+ it "resize" do
19
+ w = window rect(0,0,4,4)
20
+ w.area = rect 0,0,5,5
21
+ w.buffer.to_s.should == " \n \n \n \n "
22
+ end
23
+
24
+ it 'add_child' do
25
+ w = window rect(0,0,4,4)
26
+ c = window rect(1,1,1,2)
27
+ c.buffer.contents = "*\n*"
28
+ c.clean
29
+ w.add_child c
30
+ w.draw
31
+ w.buffer.to_s.should == " \n * \n * \n "
32
+ end
33
+
34
+ it 'remove_child' do
35
+ w = window rect(0,0,4,4)
36
+ (c=w.add_child(window rect(1,1,1,2))).buffer.fill :string=> "*"
37
+ w.draw
38
+ (w.remove_child c).should == c
39
+ w.draw
40
+ w.buffer.to_s.should == " \n \n \n "
41
+ end
42
+
43
+ it 'stacked children' do
44
+ w = window rect(0,0,4,4)
45
+ (c1=w.add_child(window(rect(1,1,2,2)))).buffer.fill :string=>"*"
46
+ (c2=w.add_child(window(rect(2,0,2,2)))).buffer.fill :string=>"@"
47
+ c1.clean
48
+ c2.clean
49
+ w.draw
50
+ w.buffer.to_s.should == " @@\n *@@\n ** \n "
51
+ end
52
+
53
+ it "each_child" do
54
+ w = window rect(0,0,4,4)
55
+ (c1=w.add_child(window(rect(1,1,2,2)))).buffer.fill :string=>"*"
56
+ (c2=w.add_child(window(rect(2,0,2,2)))).buffer.fill :string=>"@"
57
+ w.each_child.collect{|a|a}.should == [c1,c2]
58
+ w.each_child_with_index.collect{|a,i|[a,i]}.should == [[c1,0],[c2,1]]
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'window_blessing/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "window_blessing"
8
+ gem.version = WindowBlessing::VERSION
9
+ gem.authors = ["Shane Brinkman-Davis"]
10
+ gem.email = ["shanebdavis@gmail.com"]
11
+ gem.description = "Forget Curses! Try Blessings instead! WindowBlessing is an evented windowing framework for terminal apps."
12
+ gem.summary = ""
13
+ gem.homepage = "https://github.com/shanebdavis/window_blessing"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'babel_bridge', ">= 0.5.3"
21
+ gem.add_dependency 'gui_geometry', ">= 0.2.2"
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'guard-rspec'
25
+ gem.add_development_dependency 'guard-test'
26
+ gem.add_development_dependency 'rb-fsevent'
27
+ gem.add_development_dependency 'simplecov'
28
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: window_blessing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Shane Brinkman-Davis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: babel_bridge
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: gui_geometry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.2.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.2.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-test
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rb-fsevent
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Forget Curses! Try Blessings instead! WindowBlessing is an evented windowing
143
+ framework for terminal apps.
144
+ email:
145
+ - shanebdavis@gmail.com
146
+ executables:
147
+ - buffered_screen_demo.rb
148
+ - color_picker_demo.rb
149
+ - foiled_demo.rb
150
+ - text_editor_demo.rb
151
+ - windowed_screen_demo.rb
152
+ - xterm_screen_demo.rb
153
+ extensions: []
154
+ extra_rdoc_files: []
155
+ files:
156
+ - .gitignore
157
+ - Gemfile
158
+ - Guardfile
159
+ - LICENSE.txt
160
+ - README.md
161
+ - Rakefile
162
+ - bin/buffered_screen_demo.rb
163
+ - bin/color_picker_demo.rb
164
+ - bin/foiled_demo.rb
165
+ - bin/text_editor_demo.rb
166
+ - bin/windowed_screen_demo.rb
167
+ - bin/xterm_screen_demo.rb
168
+ - lib/window_blessing.rb
169
+ - lib/window_blessing/buffer.rb
170
+ - lib/window_blessing/buffered_screen.rb
171
+ - lib/window_blessing/color.rb
172
+ - lib/window_blessing/constants.rb
173
+ - lib/window_blessing/event_manager.rb
174
+ - lib/window_blessing/event_queue.rb
175
+ - lib/window_blessing/evented.rb
176
+ - lib/window_blessing/evented_variable.rb
177
+ - lib/window_blessing/tools.rb
178
+ - lib/window_blessing/version.rb
179
+ - lib/window_blessing/widgets/draggable_background.rb
180
+ - lib/window_blessing/widgets/label.rb
181
+ - lib/window_blessing/widgets/slider.rb
182
+ - lib/window_blessing/widgets/text_field.rb
183
+ - lib/window_blessing/window.rb
184
+ - lib/window_blessing/windowed_screen.rb
185
+ - lib/window_blessing/xterm_event_parser.rb
186
+ - lib/window_blessing/xterm_input.rb
187
+ - lib/window_blessing/xterm_log.rb
188
+ - lib/window_blessing/xterm_output.rb
189
+ - lib/window_blessing/xterm_screen.rb
190
+ - lib/window_blessing/xterm_state.rb
191
+ - spec/buffer_spec.rb
192
+ - spec/color_spec.rb
193
+ - spec/spec_helper.rb
194
+ - spec/tools_spec.rb
195
+ - spec/window_spec.rb
196
+ - window_blessing.gemspec
197
+ homepage: https://github.com/shanebdavis/window_blessing
198
+ licenses: []
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ none: false
205
+ requirements:
206
+ - - ! '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ none: false
211
+ requirements:
212
+ - - ! '>='
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 1.8.23
218
+ signing_key:
219
+ specification_version: 3
220
+ summary: ''
221
+ test_files:
222
+ - spec/buffer_spec.rb
223
+ - spec/color_spec.rb
224
+ - spec/spec_helper.rb
225
+ - spec/tools_spec.rb
226
+ - spec/window_spec.rb