scriptty 0.5.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitattributes +1 -0
  2. data/.gitignore +3 -0
  3. data/COPYING +674 -0
  4. data/COPYING.LESSER +165 -0
  5. data/README.rdoc +31 -0
  6. data/Rakefile +49 -0
  7. data/VERSION +1 -0
  8. data/bin/scriptty-capture +5 -0
  9. data/bin/scriptty-dump-screens +4 -0
  10. data/bin/scriptty-replay +5 -0
  11. data/bin/scriptty-term-test +4 -0
  12. data/bin/scriptty-transcript-parse +4 -0
  13. data/examples/captures/xterm-overlong-line-prompt.bin +9 -0
  14. data/examples/captures/xterm-vim-session.bin +262 -0
  15. data/examples/demo-capture.rb +19 -0
  16. data/examples/telnet-nego.rb +55 -0
  17. data/lib/scriptty/apps/capture_app/console.rb +104 -0
  18. data/lib/scriptty/apps/capture_app/password_prompt.rb +65 -0
  19. data/lib/scriptty/apps/capture_app.rb +213 -0
  20. data/lib/scriptty/apps/dump_screens_app.rb +166 -0
  21. data/lib/scriptty/apps/replay_app.rb +229 -0
  22. data/lib/scriptty/apps/term_test_app.rb +124 -0
  23. data/lib/scriptty/apps/transcript_parse_app.rb +143 -0
  24. data/lib/scriptty/cursor.rb +39 -0
  25. data/lib/scriptty/exception.rb +38 -0
  26. data/lib/scriptty/expect.rb +392 -0
  27. data/lib/scriptty/multiline_buffer.rb +192 -0
  28. data/lib/scriptty/net/event_loop.rb +610 -0
  29. data/lib/scriptty/screen_pattern/generator.rb +398 -0
  30. data/lib/scriptty/screen_pattern/parser.rb +558 -0
  31. data/lib/scriptty/screen_pattern.rb +104 -0
  32. data/lib/scriptty/term/dg410/dg410-client-escapes.txt +37 -0
  33. data/lib/scriptty/term/dg410/dg410-escapes.txt +82 -0
  34. data/lib/scriptty/term/dg410/parser.rb +162 -0
  35. data/lib/scriptty/term/dg410.rb +489 -0
  36. data/lib/scriptty/term/xterm/xterm-escapes.txt +73 -0
  37. data/lib/scriptty/term/xterm.rb +661 -0
  38. data/lib/scriptty/term.rb +40 -0
  39. data/lib/scriptty/util/fsm/definition_parser.rb +111 -0
  40. data/lib/scriptty/util/fsm/scriptty_fsm_definition.treetop +189 -0
  41. data/lib/scriptty/util/fsm.rb +177 -0
  42. data/lib/scriptty/util/transcript/reader.rb +96 -0
  43. data/lib/scriptty/util/transcript/writer.rb +111 -0
  44. data/test/apps/capture_app_test.rb +123 -0
  45. data/test/apps/transcript_parse_app_test.rb +118 -0
  46. data/test/cursor_test.rb +51 -0
  47. data/test/fsm_definition_parser_test.rb +220 -0
  48. data/test/fsm_test.rb +322 -0
  49. data/test/multiline_buffer_test.rb +275 -0
  50. data/test/net/event_loop_test.rb +402 -0
  51. data/test/screen_pattern/generator_test.rb +408 -0
  52. data/test/screen_pattern/parser_test/explicit_cursor_pattern.txt +14 -0
  53. data/test/screen_pattern/parser_test/explicit_fields.txt +22 -0
  54. data/test/screen_pattern/parser_test/multiple_patterns.txt +42 -0
  55. data/test/screen_pattern/parser_test/simple_pattern.txt +14 -0
  56. data/test/screen_pattern/parser_test/truncated_heredoc.txt +12 -0
  57. data/test/screen_pattern/parser_test/utf16bebom_pattern.bin +0 -0
  58. data/test/screen_pattern/parser_test/utf16lebom_pattern.bin +0 -0
  59. data/test/screen_pattern/parser_test/utf8_pattern.bin +14 -0
  60. data/test/screen_pattern/parser_test/utf8_unix_pattern.bin +14 -0
  61. data/test/screen_pattern/parser_test/utf8bom_pattern.bin +14 -0
  62. data/test/screen_pattern/parser_test.rb +266 -0
  63. data/test/term/dg410/parser_test.rb +139 -0
  64. data/test/term/xterm_test.rb +327 -0
  65. data/test/test_helper.rb +3 -0
  66. data/test/util/transcript/reader_test.rb +131 -0
  67. data/test/util/transcript/writer_test.rb +126 -0
  68. data/test.watchr +29 -0
  69. metadata +175 -0
@@ -0,0 +1,408 @@
1
+ # = Tests for ScripTTY::ScreenPattern::Generator
2
+ # Copyright (C) 2010 Infonium Inc.
3
+ #
4
+ # This file is part of ScripTTY.
5
+ #
6
+ # ScripTTY is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # ScripTTY is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with ScripTTY. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require File.dirname(__FILE__) + "/../test_helper.rb"
20
+ require 'scriptty/screen_pattern/generator'
21
+
22
+ class GeneratorTest < Test::Unit::TestCase
23
+ def test_simple_pattern
24
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
25
+ :size => [3,5],
26
+ :matches => [
27
+ [[0,0], "Hello"],
28
+ ],
29
+ :fields => {
30
+ "one" => [1, 2..4],
31
+ })
32
+ expected = <<EOT
33
+ [foo]
34
+ size: (3, 5)
35
+ char_ignore: "."
36
+ char_field: "#"
37
+ text: <<END
38
+ +-----+
39
+ |Hello|
40
+ |..###| ("one")
41
+ |.....|
42
+ +-----+
43
+ END
44
+ EOT
45
+ assert_equal expected, actual
46
+ end
47
+
48
+ def test_field_overlaps_match
49
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
50
+ :size => [3,5],
51
+ :matches => [
52
+ [[0,0], "Hello"],
53
+ ],
54
+ :fields => {
55
+ "one" => [0, 2..4],
56
+ })
57
+ expected = <<EOT
58
+ [foo]
59
+ size: (3, 5)
60
+ char_ignore: "."
61
+ fields: <<END
62
+ ("one", (0, 2), 3)
63
+ END
64
+ text: <<END
65
+ +-----+
66
+ |Hello|
67
+ |.....|
68
+ |.....|
69
+ +-----+
70
+ END
71
+ EOT
72
+ assert_equal expected, actual
73
+ end
74
+
75
+ def test_field_partly_overlaps_match
76
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
77
+ :size => [3,5],
78
+ :matches => [
79
+ [[0,0], "abc"],
80
+ ],
81
+ :fields => {
82
+ "one" => [0, 2..4],
83
+ })
84
+ expected = <<EOT
85
+ [foo]
86
+ size: (3, 5)
87
+ char_ignore: "."
88
+ fields: <<END
89
+ ("one", (0, 2), 3)
90
+ END
91
+ text: <<END
92
+ +-----+
93
+ |abc..|
94
+ |.....|
95
+ |.....|
96
+ +-----+
97
+ END
98
+ EOT
99
+ assert_equal expected, actual
100
+ end
101
+
102
+ def test_field_partly_overlaps_match_with_force_fields
103
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo", :force_fields => true,
104
+ :size => [3,5],
105
+ :matches => [
106
+ [[0,0], "abc"],
107
+ ],
108
+ :fields => {
109
+ "one" => [0, 2..4],
110
+ })
111
+ expected = <<EOT
112
+ [foo]
113
+ size: (3, 5)
114
+ char_ignore: "."
115
+ char_field: "#"
116
+ text: <<END
117
+ +-----+
118
+ |ab###| ("one")
119
+ |.....|
120
+ |.....|
121
+ +-----+
122
+ END
123
+ EOT
124
+ assert_equal expected, actual
125
+ end
126
+
127
+ def test_2_adjacent_fields
128
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
129
+ :size => [3,5],
130
+ :fields => {
131
+ "one" => [0, 0..1],
132
+ "two" => [0, 2..4],
133
+ })
134
+ expected = <<EOT
135
+ [foo]
136
+ size: (3, 5)
137
+ char_ignore: "."
138
+ char_field: "#"
139
+ fields: <<END
140
+ ("two", (0, 2), 3)
141
+ END
142
+ text: <<END
143
+ +-----+
144
+ |##...| ("one")
145
+ |.....|
146
+ |.....|
147
+ +-----+
148
+ END
149
+ EOT
150
+ assert_equal expected, actual, "When fields are adjacent, the first should be implicit and the second should be explicit"
151
+ end
152
+
153
+ def test_3_adjacent_fields
154
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
155
+ :size => [3,5],
156
+ :fields => {
157
+ "one" => [0, 0..0],
158
+ "two" => [0, 1..1],
159
+ "three" => [0, 2..3],
160
+ })
161
+ expected = <<EOT
162
+ [foo]
163
+ size: (3, 5)
164
+ char_ignore: "."
165
+ char_field: "#"
166
+ fields: <<END
167
+ ("two", (0, 1), 1)
168
+ END
169
+ text: <<END
170
+ +-----+
171
+ |#.##.| ("one", "three")
172
+ |.....|
173
+ |.....|
174
+ +-----+
175
+ END
176
+ EOT
177
+ assert_equal expected, actual, "When more than two fields are adjacent, every other one should be explicit"
178
+ end
179
+
180
+ def test_simple_pattern_with_cursor
181
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
182
+ :size => [3,5],
183
+ :cursor_pos => [1,0],
184
+ :matches => [
185
+ [[0,0], "Hello"],
186
+ ],
187
+ :fields => {
188
+ "one" => [1, 2..4],
189
+ })
190
+ expected = <<EOT
191
+ [foo]
192
+ size: (3, 5)
193
+ char_cursor: "@"
194
+ char_ignore: "."
195
+ char_field: "#"
196
+ text: <<END
197
+ +-----+
198
+ |Hello|
199
+ |@.###| ("one")
200
+ |.....|
201
+ +-----+
202
+ END
203
+ EOT
204
+ assert_equal expected, actual
205
+ end
206
+
207
+ def test_cursor_overlaps_match
208
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
209
+ :size => [3,5],
210
+ :cursor_pos => [0,0],
211
+ :matches => [
212
+ [[0,0], "Hello"],
213
+ ],
214
+ :fields => {
215
+ "one" => [1, 2..4],
216
+ })
217
+ expected = <<EOT
218
+ [foo]
219
+ size: (3, 5)
220
+ cursor_pos: (0, 0)
221
+ char_ignore: "."
222
+ char_field: "#"
223
+ text: <<END
224
+ +-----+
225
+ |Hello|
226
+ |..###| ("one")
227
+ |.....|
228
+ +-----+
229
+ END
230
+ EOT
231
+ assert_equal expected, actual
232
+ end
233
+
234
+ def test_cursor_overlaps_match_with_force_cursor
235
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo", :force_cursor => true,
236
+ :size => [3,5],
237
+ :cursor_pos => [0,0],
238
+ :matches => [
239
+ [[0,0], "Hello"],
240
+ ],
241
+ :fields => {
242
+ "one" => [1, 2..4],
243
+ })
244
+ expected = <<EOT
245
+ [foo]
246
+ size: (3, 5)
247
+ char_cursor: "@"
248
+ char_ignore: "."
249
+ char_field: "#"
250
+ text: <<END
251
+ +-----+
252
+ |@ello|
253
+ |..###| ("one")
254
+ |.....|
255
+ +-----+
256
+ END
257
+ EOT
258
+ assert_equal expected, actual
259
+ end
260
+
261
+ def test_force_cursor_regexp_match
262
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo", :force_cursor => /H/,
263
+ :size => [3,5],
264
+ :cursor_pos => [0,0],
265
+ :matches => [
266
+ [[0,0], "Hello"],
267
+ ],
268
+ :fields => {
269
+ "one" => [1, 2..4],
270
+ })
271
+ expected = <<EOT
272
+ [foo]
273
+ size: (3, 5)
274
+ char_cursor: "@"
275
+ char_ignore: "."
276
+ char_field: "#"
277
+ text: <<END
278
+ +-----+
279
+ |@ello|
280
+ |..###| ("one")
281
+ |.....|
282
+ +-----+
283
+ END
284
+ EOT
285
+ assert_equal expected, actual
286
+ end
287
+
288
+ def test_force_cursor_regexp_nomatch
289
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo", :force_cursor => /x/,
290
+ :size => [3,5],
291
+ :cursor_pos => [0,0],
292
+ :matches => [
293
+ [[0,0], "Hello"],
294
+ ],
295
+ :fields => {
296
+ "one" => [1, 2..4],
297
+ })
298
+ expected = <<EOT
299
+ [foo]
300
+ size: (3, 5)
301
+ cursor_pos: (0, 0)
302
+ char_ignore: "."
303
+ char_field: "#"
304
+ text: <<END
305
+ +-----+
306
+ |Hello|
307
+ |..###| ("one")
308
+ |.....|
309
+ +-----+
310
+ END
311
+ EOT
312
+ assert_equal expected, actual
313
+ end
314
+
315
+ def test_second_choice_chars
316
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
317
+ :size => [3,5],
318
+ :cursor_pos => [1,0],
319
+ :matches => [
320
+ [[0,0], ".@#"],
321
+ ],
322
+ :fields => {
323
+ "one" => [1, 2..4],
324
+ })
325
+ expected = <<EOT
326
+ [foo]
327
+ size: (3, 5)
328
+ char_cursor: "+"
329
+ char_ignore: "~"
330
+ char_field: "*"
331
+ text: <<END
332
+ +-----+
333
+ |.@#~~|
334
+ |+~***| ("one")
335
+ |~~~~~|
336
+ +-----+
337
+ END
338
+ EOT
339
+ assert_equal expected, actual
340
+ end
341
+
342
+ def test_position_offset
343
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
344
+ :position => [1,1],
345
+ :size => [3,5],
346
+ :cursor_pos => [2,1],
347
+ :matches => [
348
+ [[1,1], "Hello"],
349
+ ],
350
+ :fields => {
351
+ "one" => [2, 3..5],
352
+ })
353
+ expected = <<EOT
354
+ [foo]
355
+ position: (1, 1)
356
+ size: (3, 5)
357
+ char_cursor: "@"
358
+ char_ignore: "."
359
+ char_field: "#"
360
+ text: <<END
361
+ +-----+
362
+ |Hello|
363
+ |@.###| ("one")
364
+ |.....|
365
+ +-----+
366
+ END
367
+ EOT
368
+ assert_equal expected, actual
369
+ end
370
+
371
+ def test_ignore
372
+ actual = ScripTTY::ScreenPattern::Generator.generate("foo",
373
+ :ignore => [[0, 1..1]],
374
+ :size => [3,5],
375
+ :matches => [
376
+ [[0,0], "Hello"],
377
+ ],
378
+ :fields => {
379
+ "one" => [1, 2..4],
380
+ })
381
+ expected = <<EOT
382
+ [foo]
383
+ size: (3, 5)
384
+ char_ignore: "."
385
+ char_field: "#"
386
+ text: <<END
387
+ +-----+
388
+ |H.llo|
389
+ |..###| ("one")
390
+ |.....|
391
+ +-----+
392
+ END
393
+ EOT
394
+ assert_equal expected, actual
395
+ end
396
+
397
+ def test_parsed_patterns_raise_no_errors
398
+ require 'scriptty/screen_pattern/parser'
399
+ Dir.glob(File.join(File.dirname(__FILE__), "parser_test", "*_pattern.{txt,bin}")).each do |pathname|
400
+ ScripTTY::ScreenPattern::Parser.parse(File.read(pathname)) do |parsed|
401
+ assert_nothing_raised("parsed #{File.basename(pathname)} should generate successfully") do
402
+ ScripTTY::ScreenPattern::Generator.generate(parsed[:name], parsed[:properties])
403
+ end
404
+ end
405
+ end
406
+ end
407
+
408
+ end
@@ -0,0 +1,14 @@
1
+ # Screen pattern with explicit cursor positioning
2
+ [simple_pattern]
3
+ rectangle: (3,4)-(6,8) # rectangle is (row0, col0) - (row1, col1)
4
+ cursor_pos: (1, 1)
5
+ char_ignore: "."
6
+ char_field: "#"
7
+ text: <<END
8
+ +-----+
9
+ |..###| ("field1")
10
+ |#.#.#| ("apple", "orange", "banana")
11
+ |##.##| ("foo",nil)
12
+ |##.##| (nil,"bar")
13
+ +-----+
14
+ END
@@ -0,0 +1,22 @@
1
+ # Screen pattern with explicit fields
2
+ [explicit_fields]
3
+ position: (3,4)
4
+ size: (4,5)
5
+ char_cursor: "@"
6
+ char_ignore: "."
7
+ char_field: "#"
8
+ fields: <<END
9
+ ("field1", (0,2), 3)
10
+ ("apple", (1,0), 1)
11
+ ("orange", (1,2), 1)
12
+ ("banana", (1,4), 1)
13
+ ("foo", (2,0), 2)
14
+ END
15
+ text: <<END
16
+ +-----+
17
+ |@....|
18
+ |.....|
19
+ |.....|
20
+ |...##| ("bar") # Mixing explicit and implicit fields is allowed.
21
+ +-----+
22
+ END
@@ -0,0 +1,42 @@
1
+ [simple_pattern_1]
2
+ rectangle: (3,4) - (6,8)
3
+ char_cursor: "@"
4
+ char_ignore: "."
5
+ char_field: "#"
6
+ text: <<END
7
+ +-----+
8
+ |@.###| ("field1")
9
+ |#.#.#| ("apple", "orange", "banana")
10
+ |##.##| ("foo",nil)
11
+ |##.##| (nil,"bar")
12
+ +-----+
13
+ END
14
+
15
+ [simple_pattern_2]
16
+ rectangle: (0 ,0 )- ( 3, 4)
17
+ char_cursor: "~"
18
+ char_ignore: "."
19
+ char_field: "#"
20
+ text: <<END
21
+ +-----+
22
+ |~:###| ("field1")
23
+ |#.#.#| (nil,nil,nil)
24
+ |Hello|
25
+ |World|
26
+ +-----+
27
+ END
28
+
29
+ [simple_pattern_3]
30
+ position: (0,0) # location of the top-left corner of the pattern within the window
31
+ size: (4,5) # (height, width) of the pattern
32
+ char_cursor: "~"
33
+ char_ignore: "."
34
+ char_field: "#"
35
+ text: <<END
36
+ +-----+
37
+ |~:###| ("field1")
38
+ |#.#.#| (nil,nil,nil)
39
+ |Hello|
40
+ |World|
41
+ +-----+
42
+ END
@@ -0,0 +1,14 @@
1
+ # Basic ASCII screen pattern
2
+ [simple_pattern]
3
+ rectangle: (3,4)-(6,8) # rectangle is (row0, col0) - (row1, col1)
4
+ char_cursor: "@"
5
+ char_ignore: "."
6
+ char_field: "#"
7
+ text: <<END
8
+ +-----+
9
+ |@.###| ("field1")
10
+ |#.#.#| ("apple", "orange", "banana")
11
+ |##.##| ("foo",nil)
12
+ |##X##| (nil,"bar")
13
+ +-----+
14
+ END
@@ -0,0 +1,12 @@
1
+ [simple_pattern_1]
2
+ rectangle: (3,4) - (6,8)
3
+ char_cursor: "@"
4
+ char_ignore: "."
5
+ char_field: "#"
6
+ text: <<END
7
+ +-----+
8
+ |@.###| ("field1")
9
+ |#.#.#| ("apple", "orange", "banana")
10
+ |##.##| ("foo",nil)
11
+ |##.##| (nil,"bar")
12
+ +-----+
@@ -0,0 +1,14 @@
1
+ # Saved in Notepad++ as "UTF-8 without BOM"
2
+ [unicode_pattern]
3
+ rectangle: (3,4)-(6,8)
4
+ char_cursor: "█"
5
+ char_field: "Ø"
6
+ char_ignore: "."
7
+ text: <<END
8
+ +-----+
9
+ |█.ØØØ| ("field1")
10
+ |Ø.Ø.Ø| ("apple", "orange", "banana")
11
+ |ØØ.ØØ| ("foo",nil)
12
+ |ØØ.ØØ| (nil,"bar")
13
+ +-----+
14
+ END
@@ -0,0 +1,14 @@
1
+ # Saved in Vim with fileformat=unix fileencoding=utf-8
2
+ [unicode_pattern]
3
+ rectangle: (3,4)-(6,8)
4
+ char_cursor: "█"
5
+ char_field: "Ø"
6
+ char_ignore: "."
7
+ text: <<END
8
+ +-----+
9
+ |█.ØØØ| ("field1")
10
+ |Ø.Ø.Ø| ("apple", "orange", "banana")
11
+ |ØØ.ØØ| ("foo",nil)
12
+ |ØØ.ØØ| (nil,"bar")
13
+ +-----+
14
+ END
@@ -0,0 +1,14 @@
1
+ # Saved in Notepad as "UTF-8"
2
+ [unicode_pattern]
3
+ rectangle: (3,4)-(6,8)
4
+ char_cursor: "█"
5
+ char_field: "Ø"
6
+ char_ignore: "."
7
+ text: <<END
8
+ +-----+
9
+ |█.ØØØ| ("field1")
10
+ |Ø.Ø.Ø| ("apple", "orange", "banana")
11
+ |ØØ.ØØ| ("foo",nil)
12
+ |ØØ.ØØ| (nil,"bar")
13
+ +-----+
14
+ END