window_blessing 0.0.1 → 0.0.4

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.
Files changed (39) hide show
  1. data/CHANGELOG.md +30 -0
  2. data/README.md +1 -1
  3. data/bin/buffered_screen_demo.rb +4 -4
  4. data/bin/color_picker_demo.rb +1 -0
  5. data/bin/windowed_screen_demo.rb +1 -1
  6. data/bin/xterm_screen_demo.rb +6 -4
  7. data/lib/window_blessing.rb +2 -2
  8. data/lib/window_blessing/buffer.rb +16 -6
  9. data/lib/window_blessing/buffered_screen.rb +2 -2
  10. data/lib/window_blessing/color.rb +1 -0
  11. data/lib/window_blessing/debug_tools/log_request_redraw_internal.rb +16 -0
  12. data/lib/window_blessing/event_manager.rb +11 -6
  13. data/lib/window_blessing/evented.rb +1 -1
  14. data/lib/window_blessing/evented_variable.rb +10 -1
  15. data/lib/window_blessing/tools.rb +11 -1
  16. data/lib/window_blessing/version.rb +1 -1
  17. data/lib/window_blessing/widgets/draggable_background.rb +1 -1
  18. data/lib/window_blessing/widgets/label.rb +1 -1
  19. data/lib/window_blessing/widgets/slider.rb +10 -2
  20. data/lib/window_blessing/widgets/text_field.rb +1 -1
  21. data/lib/window_blessing/window.rb +48 -45
  22. data/lib/window_blessing/window_redraw_areas.rb +23 -0
  23. data/lib/window_blessing/windowed_screen.rb +11 -13
  24. data/lib/window_blessing/xterm_event_parser.rb +68 -59
  25. data/lib/window_blessing/xterm_screen.rb +2 -2
  26. data/lib/window_blessing/xterm_state.rb +1 -1
  27. data/spec/buffer_spec.rb +56 -0
  28. data/spec/color_spec.rb +14 -0
  29. data/spec/event_manager_spec.rb +107 -0
  30. data/spec/event_queue_spec.rb +46 -0
  31. data/spec/evented_variable_spec.rb +43 -0
  32. data/spec/tools_spec.rb +18 -0
  33. data/spec/window_redraw_areas_spec.rb +79 -0
  34. data/spec/window_spec.rb +138 -3
  35. data/spec/xterm_event_parser_spec.rb +86 -0
  36. data/window_blessing.gemspec +4 -3
  37. metadata +20 -11
  38. data/bin/foiled_demo.rb +0 -27
  39. data/bin/text_editor_demo.rb +0 -292
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: window_blessing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: babel_bridge
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.2.2
37
+ version: 0.3.1
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.2.2
45
+ version: 0.3.1
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -139,21 +139,20 @@ dependencies:
139
139
  - - ! '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
- description: Forget Curses! Try Blessings instead! WindowBlessing is an evented windowing
142
+ description: Forget curses. Try blessings. WindowBlessing is an evented, windowing
143
143
  framework for terminal apps.
144
144
  email:
145
145
  - shanebdavis@gmail.com
146
146
  executables:
147
147
  - buffered_screen_demo.rb
148
148
  - color_picker_demo.rb
149
- - foiled_demo.rb
150
- - text_editor_demo.rb
151
149
  - windowed_screen_demo.rb
152
150
  - xterm_screen_demo.rb
153
151
  extensions: []
154
152
  extra_rdoc_files: []
155
153
  files:
156
154
  - .gitignore
155
+ - CHANGELOG.md
157
156
  - Gemfile
158
157
  - Guardfile
159
158
  - LICENSE.txt
@@ -161,8 +160,6 @@ files:
161
160
  - Rakefile
162
161
  - bin/buffered_screen_demo.rb
163
162
  - bin/color_picker_demo.rb
164
- - bin/foiled_demo.rb
165
- - bin/text_editor_demo.rb
166
163
  - bin/windowed_screen_demo.rb
167
164
  - bin/xterm_screen_demo.rb
168
165
  - lib/window_blessing.rb
@@ -170,6 +167,7 @@ files:
170
167
  - lib/window_blessing/buffered_screen.rb
171
168
  - lib/window_blessing/color.rb
172
169
  - lib/window_blessing/constants.rb
170
+ - lib/window_blessing/debug_tools/log_request_redraw_internal.rb
173
171
  - lib/window_blessing/event_manager.rb
174
172
  - lib/window_blessing/event_queue.rb
175
173
  - lib/window_blessing/evented.rb
@@ -181,6 +179,7 @@ files:
181
179
  - lib/window_blessing/widgets/slider.rb
182
180
  - lib/window_blessing/widgets/text_field.rb
183
181
  - lib/window_blessing/window.rb
182
+ - lib/window_blessing/window_redraw_areas.rb
184
183
  - lib/window_blessing/windowed_screen.rb
185
184
  - lib/window_blessing/xterm_event_parser.rb
186
185
  - lib/window_blessing/xterm_input.rb
@@ -190,9 +189,14 @@ files:
190
189
  - lib/window_blessing/xterm_state.rb
191
190
  - spec/buffer_spec.rb
192
191
  - spec/color_spec.rb
192
+ - spec/event_manager_spec.rb
193
+ - spec/event_queue_spec.rb
194
+ - spec/evented_variable_spec.rb
193
195
  - spec/spec_helper.rb
194
196
  - spec/tools_spec.rb
197
+ - spec/window_redraw_areas_spec.rb
195
198
  - spec/window_spec.rb
199
+ - spec/xterm_event_parser_spec.rb
196
200
  - window_blessing.gemspec
197
201
  homepage: https://github.com/shanebdavis/window_blessing
198
202
  licenses: []
@@ -214,13 +218,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
218
  version: '0'
215
219
  requirements: []
216
220
  rubyforge_project:
217
- rubygems_version: 1.8.23
221
+ rubygems_version: 1.8.25
218
222
  signing_key:
219
223
  specification_version: 3
220
- summary: ''
224
+ summary: Evented windowing framework for terminal apps.
221
225
  test_files:
222
226
  - spec/buffer_spec.rb
223
227
  - spec/color_spec.rb
228
+ - spec/event_manager_spec.rb
229
+ - spec/event_queue_spec.rb
230
+ - spec/evented_variable_spec.rb
224
231
  - spec/spec_helper.rb
225
232
  - spec/tools_spec.rb
233
+ - spec/window_redraw_areas_spec.rb
226
234
  - spec/window_spec.rb
235
+ - spec/xterm_event_parser_spec.rb
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path File.join(File.dirname(__FILE__), %w{.. lib window_blessing})
3
-
4
-
5
- WindowBlessing.main do |main_window|
6
- # raise main_window.inspect
7
- (c1 = window(rect(10,10,15,7))).background='-='
8
- main_window.add_child c1
9
-
10
- on_key do |key|
11
- case key
12
- when ?Q, ?q then break
13
- when Curses::Key::UP then c1.area += point(0,-1)
14
- when Curses::Key::DOWN then c1.area += point(0,1)
15
- when Curses::Key::LEFT then c1.area += point(-1,0)
16
- when Curses::Key::RIGHT then c1.area += point(1,0)
17
- end
18
- end
19
-
20
- on_tick do
21
- time = Time.now
22
- if time.sec != @last_sec
23
- write point(0,0), time.to_s
24
- @last_sec = time.sec
25
- end
26
- end
27
- end
@@ -1,292 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
- require File.expand_path File.join(File.dirname(__FILE__), %w{.. lib window_blessing})
4
- include GuiGeo
5
- include WindowBlessing::Tools
6
- include WindowBlessing
7
- include Widgets
8
-
9
- class Theme
10
- include WindowBlessing::Tools
11
- COLORS = {
12
- background: color("ffc").to_screen_color,
13
- foreground: color(0.25).to_screen_color,
14
- comment: color(0.5).to_screen_color,
15
- keyword: color("4a744a").to_screen_color,
16
- string: color("4a7494").to_screen_color,
17
- number: color("4a7494").to_screen_color,
18
- regexp: color("4a7494").to_screen_color,
19
- constant: color("c96600").to_screen_color,
20
- operator: color("4a744a").to_screen_color
21
- }
22
- end
23
-
24
- class CodeMarkup < BabelBridge::Parser
25
-
26
- rule :file, :space, many?(:element) do
27
- def colors
28
- [[Theme::COLORS[:foreground]]*space.match_length,element.collect{|a| a.colors}].flatten
29
- end
30
- end
31
-
32
- rule :element, :comment, :space do
33
- def colors; [Theme::COLORS[:comment]] * match_length; end
34
- end
35
-
36
- rule :element, :keyword, :space do
37
- def colors; [Theme::COLORS[:keyword]] * match_length; end
38
- end
39
-
40
- rule :element, :string, :space do
41
- def colors; [Theme::COLORS[:string]] * match_length; end
42
- end
43
-
44
- rule :element, :regexp, :space do
45
- def colors; [Theme::COLORS[:regex]] * match_length; end
46
- end
47
-
48
- rule :element, :constant, :space do
49
- def colors; [Theme::COLORS[:constant]] * match_length; end
50
- end
51
-
52
- rule :element, :operator, :space do
53
- def colors; [Theme::COLORS[:operator]] * match_length; end
54
- end
55
-
56
- rule :element, :number, :space do
57
- def colors; [Theme::COLORS[:number]] * match_length; end
58
- end
59
-
60
- rule :element, :identifier, :space do
61
- def colors; [Theme::COLORS[:foreground]] * match_length; end
62
- end
63
-
64
- rule :element, :non_space, :space do
65
- def colors; [Theme::COLORS[:foreground]] * match_length; end
66
- end
67
-
68
- rule :space, /\s*/
69
- rule :number, /[0-9]+(\.[0-9]+)?/
70
- rule :comment, /#([^\n]|$)*/
71
- rule :string, /"(\\.|[^\\"])*"/
72
- rule :string, /:[_a-zA-Z0-9]+[?!]?/
73
- rule :regexp, /\/(\\.|[^\\\/])*\//
74
- rule :operator, /[-!@$%^&*()_+={}|\[\];:<>\?,\.\/~]+/
75
- rule :keyword, /class|end|def|and|or|do|if|then/
76
- rule :keyword, /else|elsif|case|then|when|require|include/
77
- rule :identifier, /[_a-zA-Z][0-9_a-zA-Z]*/
78
- rule :constant, /[A-Z][0-9_a-zA-Z]*/
79
- rule :non_space, /[^\s]/
80
- end
81
-
82
- class TextEditor < Window
83
- attr_accessor_with_redraw :edit_buffer, :cursor_loc, :cursor_bg
84
-
85
- def initialize(filename)
86
- super rect(0,0,80,20)
87
- self.bg = Theme::COLORS[:background]
88
- self.fg = Theme::COLORS[:foreground]
89
- @cursor_loc = point
90
- @cursor_bg = Color.yellow
91
-
92
- init_event_handlers
93
- self.text = File.read(filename)
94
-
95
- on :parent_resize do |event|
96
- self.size = event[:size]
97
- end
98
- on :parent_set do |event|
99
- self.size = parent.size
100
- end
101
- end
102
-
103
- def init_event_handlers
104
- on :string_input do |event|
105
- string = event[:string]
106
- line = current_line
107
- x,y = cursor_loc.x,cursor_loc.y
108
- if x > line.length
109
- line += " "*(x - line.length)
110
- end
111
- new_line = if x == 0
112
- string + line
113
- elsif x == line.length
114
- line + string
115
- else
116
- line[0..x-1] + string + line[x..-1]
117
- end
118
- new_lines = new_line.split "\n"
119
-
120
- #cop-out for now
121
- edit_buffer[cursor_loc.y]= new_lines[0]
122
- request_redraw_internal(rect(cursor_loc,point(size.x,1)))
123
- cursor_loc.x += string.length
124
- color_lines[y]=nil
125
- end
126
-
127
- on :key_press do |event|
128
- c = cursor_loc.clone
129
- case event[:key]
130
- when :control_m then c = newline_at_cursor
131
- when :backspace then c = backspace
132
- when :home then c = point(0,c.y)
133
- when :page_up then #c = point(0,c.y)
134
- when :page_down then #c = point(0,c.y)
135
- when :end then c = point(edit_buffer[c.y].length,c.y)
136
- when :left then
137
- if c.x == 0
138
- if c.y > 0
139
- c.y-=1
140
- c.x = edit_buffer[c.y].length
141
- end
142
- else
143
- c.x -= 1
144
- end
145
- when :right then c.x += 1
146
- when :up then c.y = max(0, c.y-1)
147
- when :down then c.y = min(c.y+1, edit_buffer.length-1)
148
- end
149
- self.cursor_loc = c
150
- end
151
-
152
- on :focus do
153
- request_redraw_internal
154
- end
155
-
156
- on :blur do
157
- request_redraw_internal
158
- end
159
- end
160
-
161
- def cursor_area
162
- rect(cursor_loc - scroll_pos,point(1,1))
163
- end
164
-
165
- def cursor_loc=(c)
166
- request_redraw_internal cursor_area
167
- @cursor_loc = c
168
- request_redraw_internal cursor_area
169
- end
170
-
171
- def newline_at_cursor
172
- c = cursor_loc.clone
173
- x,y = c.x, c.y
174
- if x == 0
175
- edit_buffer.insert(y,"")
176
- color_lines.insert(y,nil)
177
- elsif x >= current_line.length
178
- edit_buffer.insert(y+1,"")
179
- color_lines.insert(y+1,nil)
180
- else
181
- l = current_line
182
- edit_buffer.insert(y,l[0..x-1])
183
- color_lines.insert(y,nil)
184
- edit_buffer[y+1] = l[x..-1]
185
- end
186
- color_lines[y]=color_lines[y+1]=nil
187
- request_redraw_internal
188
- point(0,y+1)
189
- end
190
-
191
- def backspace
192
- c = cursor_loc.clone
193
- x,y = c.x, c.y
194
- if x == 0
195
- if y > 0
196
- c.x = edit_buffer[y-1].length
197
- edit_buffer[y-1] += edit_buffer[y]
198
- color_lines[y-1] = nil
199
- c.y -= 1
200
-
201
- edit_buffer.delete_at(y)
202
- color_lines.delete_at(y)
203
-
204
- request_redraw_internal
205
- end
206
- else
207
- edit_buffer[y] = if x == 1
208
- current_line[1..-1]
209
- elsif x == current_line.length
210
- current_line[0..-2]
211
- else
212
- current_line[0..x-2] + current_line[x..-1]
213
- end
214
- c.x -= 1
215
- request_redraw_current_line
216
- end
217
- color_lines[y]=nil
218
- c
219
- end
220
-
221
- def request_redraw_current_line
222
- request_redraw_internal current_line_area
223
- end
224
-
225
- def line_area(line_number)
226
- rect(point(0,line_number),point(edit_buffer[line_number].length,1))
227
- end
228
-
229
- def current_line_area
230
- line_area(cursor_loc.y)
231
- end
232
-
233
- def current_line
234
- edit_buffer[cursor_loc.y]
235
- end
236
-
237
- def text
238
- edit_buffer.join("\n")
239
- end
240
-
241
- def text=(t)
242
- self.edit_buffer = t.split("\n")
243
- end
244
-
245
- def scroll_pos
246
- point
247
- end
248
-
249
- def line_range
250
- scroll_pos.y..scroll_pos.y+size.y-1
251
- end
252
-
253
- def visible_lines
254
- edit_buffer[line_range]
255
- end
256
-
257
- def color_lines
258
- @color_lines ||= []
259
- end
260
-
261
- def draw_background
262
- syntax_highlighter = CodeMarkup.new
263
- crop_area = buffer.crop_area
264
-
265
- range = (crop_area+scroll_pos).y_range
266
- lines = edit_buffer[range]
267
- clines = color_lines[range]
268
-
269
- lines.each_with_index do |a,i|
270
- clines[i] ||= begin
271
- p = syntax_highlighter.parse(a.clone)
272
- log syntax_highlighter.parser_failure_info unless p
273
- p.colors
274
- end
275
- buffer.contents[i+crop_area.y] = a
276
- buffer.fg_buffer[i+crop_area.y] = clines[i]
277
- end
278
-
279
- color_lines[range] = clines
280
-
281
- buffer.sanitize_contents crop_area.y_range
282
- buffer.normalize crop_area.y_range
283
- buffer.fill bg:bg
284
- buffer.fill :area => cursor_area, :bg => cursor_bg if focused?
285
- end
286
- end
287
-
288
- WindowedScreen.new.start(:full=>true, :utf8 => true) do |screen|
289
- filename = __FILE__
290
- screen.root_window.add_child te=TextEditor.new(filename)
291
- te.focus
292
- end