scriptty 0.5.0-java

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 (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
data/COPYING.LESSER ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = Introduction
2
+
3
+ ScripTTY is a library for JRuby that lets you write scripts to control
4
+ full-screen terminal-based applications.
5
+
6
+ = Terminals supported
7
+
8
+ Limited DG410 and XTerm support.
9
+
10
+ = Requirements
11
+
12
+ - JRuby
13
+ - Treetop
14
+ - Multibyte
15
+
16
+ = License
17
+
18
+ Copyright © 2010 Infonium Inc.
19
+
20
+ ScripTTY is free software: you can redistribute it and/or modify
21
+ it under the terms of the GNU Lesser General Public License as published
22
+ by the Free Software Foundation, either version 3 of the License, or
23
+ (at your option) any later version.
24
+
25
+ ScripTTY is distributed in the hope that it will be useful,
26
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
+ GNU Lesser General Public License for more details.
29
+
30
+ You should have received a copy of the GNU Lesser General Public License
31
+ along with ScripTTY. If not, see <http://www.gnu.org/licenses/>.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "scriptty"
5
+ gemspec.summary = "write expect-like script to control full-screen terminal-based applications"
6
+ gemspec.description = <<EOF
7
+ ScripTTY is a JRuby application and library that lets you control full-screen
8
+ terminal applications using an expect-like scripting language and a full-screen
9
+ matching engine.
10
+ EOF
11
+ gemspec.platform = "java"
12
+ gemspec.email = "dlitz@infonium.ca"
13
+ gemspec.homepage = "http://github.com/infonium/scriptty"
14
+ gemspec.authors = ["Dwayne Litzenberger"]
15
+ gemspec.add_dependency "treetop"
16
+ gemspec.add_dependency "multibyte"
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rake/rdoctask'
24
+ Rake::RDocTask.new do |t|
25
+ t.rdoc_files = Dir.glob(%w( README* COPYING* lib/**/*.rb *.rdoc )).uniq
26
+ t.main = "README.rdoc"
27
+ t.title = "ScripTTY - RDoc Documentation"
28
+ t.options = %w( --charset -UTF-8 --line-numbers )
29
+ end
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.pattern = 'test/**/*_test.rb'
34
+ end
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |t|
39
+ t.pattern = 'test/**/*_test.rb'
40
+ t.rcov_opts = ['--text-report', '--exclude', 'gems,rcov,jruby.*,\(eval\)']
41
+ end
42
+ rescue LoadError
43
+ $stderr.puts "warning: rcov not installed; coverage testing not available."
44
+ end
45
+
46
+ task :clobber do
47
+ rm "scriptty.gemspec"
48
+ rm_r "pkg"
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'scriptty/apps/capture_app'
4
+ puts "\007Starting" # DEBUG FIXME
5
+ ScripTTY::Apps::CaptureApp.new(ARGV).main
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'scriptty/apps/dump_screens_app'
4
+ ScripTTY::Apps::DumpScreensApp.new(ARGV).main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'scriptty/apps/replay_app'
4
+ puts "\007Starting" # DEBUG FIXME
5
+ ScripTTY::Apps::ReplayApp.new(ARGV).main
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'scriptty/apps/term_test_app'
4
+ ScripTTY::Apps::TermTestApp.new(ARGV).main
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'scriptty/apps/transcript_parse_app'
4
+ ScripTTY::Apps::TranscriptParseApp.new(ARGV).main
@@ -0,0 +1,9 @@
1
+ Script started on Thu Mar 4 16:08:52 2010
2
+ iMac-002:~/components/scriptty/main
3
+ dwaynelitzenberger$
4
+ dwaynelitzenberger$ git commit -m 'FSM: include input_sequence instead of just in
5
+
6
+ iMac-002:~/components/scriptty/main
7
+ dwaynelitzenberger$ exit
8
+
9
+ Script done on Thu Mar 4 16:09:08 2010
@@ -0,0 +1,262 @@
1
+ Script started on Mon Mar 1 17:14:33 2010
2
+ iMac-002:~/components/scriptty/main
3
+ dwaynelitzenberger$ clear
4
+ iMac-002:~/components/scriptty/main
5
+ dwaynelitzenberger$
6
+ iMac-002:~/components/scriptty/main
7
+ dwaynelitzenberger$ ls
8
+ Rakefile lots_of_operations.bin xterm-vim-session.bin
9
+ dg410only.bin mytest.rb
10
+ lib test.txt
11
+ iMac-002:~/components/scriptty/main
12
+ dwaynelitzenberger$ vim mytest.rb
13
+ 7[?47h[?1h=E325: ATTENTION
14
+ Found a swap file by the name ".mytest.rb.swp"
15
+ owned by: dwaynelitzenberger dated: Mon Mar 1 16:23:54 2010
16
+ file name: ~dwaynelitzenberger/components/scriptty/main/mytest.rb
17
+ modified: no
18
+ user name: dwaynelitzenberger host name: iMac-002.local
19
+ process ID: 21299 (still running)
20
+ While opening file "mytest.rb"
21
+ dated: Mon Mar 1 16:23:51 2010
22
+
23
+ (1) Another program may be editing the same file.
24
+ If this is the case, be careful not to end up with two
25
+ different instances of the same file when making changes.
26
+ Quit, or continue with caution.
27
+
28
+ (2) An edit session for this file crashed.
29
+ If this is the case, use ":recover" or "vim -r mytest.rb"
30
+ to recover the changes (see ":help recovery").
31
+ If you did this already, delete the swap file ".mytest.rb.swp"
32
+ to avoid this message.
33
+
34
+ Swap file ".mytest.rb.swp" already exists!
35
+ [O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: "mytest.rb"
36
+  2  3 $LOAD_PATH.unshift "lib" 4  5 #require 'scriptty/async_sockets' 6 require 'scriptty/dg410-transition-table'
37
+  7 require 'scriptty/screen_buffer' 8  9 module Scriptty 10  module Term 11  class DG410
38
+  12  13  class ProprietaryEscapeParser 14  def initialize(target) 15  @target = target 16  @state = :opcode
39
+  17  @opcode = "" 18  @n = nil 19  @payload = "" 20  end 21  22  # <036> ~ <2-byte-opcode> <n> <n*bytes>
40
+ mytest.rb [RO] 1,1 Top2,0-1 Top3,1 Top4,0-1 Top5,1 Top6,1 Top7,1 Top8,0-1 Top9,1 Top10,1 Top11,1 Top12,0-1 Top13,1 Top14,1 Top15,1 Top16,1 Top17,1 Top18,1 Top19,1 Top20,1 Top21,0-1 Top22,1 Top
41
+  23  def feed_byte(input_byte)23,1 0%
42
+  24  case @state24,1 1%
43
+  25  when :opcode25,1 1%
44
+  26  @opcode << input_byte26,1 2%
45
+  27  if @opcode.length >= 227,1 3%
46
+  28  @state = :n28,1 3%
47
+  29  end29,1 4%
48
+  30  when :n30,1 5%
49
+  31  @n = input_byte.unpack("C*")[0]31,1 5%
50
+  32  if @n > 032,1 6%
51
+  33  @state = :payload33,1 6%
52
+  34  else34,1 7%
53
+  35  @state = :done35,1 8%
54
+  36  end36,1 8%
55
+  37  when :payload37,1 9%
56
+  38  @payload << input_byte38,1 10%
57
+  39  if @payload.length >= @n39,1 10%
58
+  40  @state = :done40,1 11%
59
+  41  end41,1 11%
60
+  42  else42,1 12%
61
+  43  raise "BUG"43,1 13%
62
+  44  end44,1 13%
63
+  45  if @state == :done45,1 14% 46  @target.handle(:proprietary_escape, "#{@opcode}#{[@n].pack("C*")) }#{@payload}")46,1 15%
64
+  47  return true47,1 16%
65
+  48  else48,1 16%
66
+  49  return false49,1 17%
67
+  50  end50,1 18%
68
+  51  end51,1 18%
69
+  52  end52,1 19%
70
+  53 53,0-1 20%
71
+  54  def initialize(target)54,1 20%
72
+  55  @byte = 1 # DEBUG FIXME55,1 21%
73
+  56  @target = target56,1 21%
74
+  57  @state = 1 # default state is 157,1 22%
75
+  58  @alt_parser = nil # alternative escape sequence parser58,1 23%
76
+  59  @current_escape_sequence = ""59,1 23% 60  load_transition_table(File.join(File.dirname(__FILE__), "lib/scripttt y/dg410-transition-table.rb")) # DEBUG FIXME60,1 24%
77
+  61  end61,1 25%
78
+  62 62,0-1 26%
79
+  63  def feed(input_bytes)63,1 26%
80
+  64  input_bytes.length.times do |i|64,1 27%
81
+  65  feed_byte(input_bytes[i,1])65,1 27% 66  @byte += 1 # DEBUG FIXME
82
+  67  end66,1 28%67,1 28%
83
+  68  end68,1 29%
84
+  69 69,0-1 30%
85
+  70  #private70,1 30%
86
+  71 71,0-1 31%
87
+  72  def feed_byte(input_byte)72,1 31%
88
+  73  if @state != 173,1 32%
89
+  74  @current_escape_sequence << input_byte74,1 33%
90
+  75  else75,1 33%
91
+  76  @current_escape_sequence = input_byte.dup76,1 34%
92
+  77  end77,1 35%
93
+  78  if @alt_parser78,1 35%
94
+  79  if @alt_parser.feed_byte(input_byte)79,1 36%
95
+  80  @state = @next_state80,1 36% 81  @alt_parser = nil
96
+  82  end81,1 37%82,1 37%
97
+  83  return83,1 38%
98
+  84  end84,1 38%
99
+  85  t = @state_transitions[@state][input_byte]85,1 39%
100
+  86  t ||= @state_transitions[@state][:any]86,1 40% 87  #raise ArgumentError.new("Unknown escape state=#{@state.inspect} inpp ut=#{input_byte.inspect}") unless t87,1 41% 88  raise ArgumentError.new("Unknown escape sequence #{@current_escape_ss equence.inspect} state=#{@state.inspect} input=#{input_byte.inspect} byte=0xx #{@byte.to_s(16)}") unless t # DEBUG FIXME88,1 42%
101
+  89  @next_state = t[:next_state]89,1 43%
102
+  90  if t[:callback]90,1 43%
103
+  91  method_name = "handle_#{t[:callback]}".to_sym91,1 44% 92  if respond_to?(method_name) # check for the method in this objecc t92,1 45%
104
+  93  send(method_name, @current_escape_sequence)93,1 46%
105
+  94  else94,1 46%
106
+  95  @target.handle(t[:callback], @current_escape_sequence)95,1 47%
107
+  96  end96,1 47%
108
+  97  #elsif target.respond_to?(:unhandled)97,1 48%
109
+  98  # target.unhandled(t[:callback].to_sym, input_byte)98,1 49%
110
+  99  #else99,1 49%100  # print "[#{t[:callback]}]" # DEBUG FIXME: should we die if thh is happens?100,1 50%
111
+ 101  # $stdout.flush101,1 51%
112
+ 102  #end102,1 51%
113
+ 103  end103,1 52%104  @state = @next_state
114
+ 105  end104,1 53%105,1 53%106
115
+ 107  # escapes starting with "\036~"
116
+ 108  # <036> ~ <2-byte-opcode> <n> <n*bytes>106,0-1 54%107,1 54%108,1 54%
117
+ 109  def handle_proprietary_escape(input_byte)109,1 55%
118
+ 110  @alt_parser = ProprietaryEscapeParser.new(@target)110,1 55%
119
+ 111  end111,1 56%112
120
+ 113  def load_transition_table(filename)112,0-1 57%113,1 57%114  # @state_transitions[current_state][input] = {:next_state => x, :evee nt => x}114,1 58%
121
+ 115  @state_transitions = {}115,1 59%116  eval(File.read(filename), nil, filename, 1).each do |state, input, nn ext_state, callback| # FIXME116,1 59%
122
+ 117  @state_transitions[state] ||= {}117,1 60%118  @state_transitions[state][input] = {:next_state => next_state, :caa llback => callback}
123
+ 119  end118,1 61%119,1 61%
124
+ 120  end120,1 62%
125
+ 121  end121,1 62%
126
+ 122  end122,1 63%
127
+ 123 end123,1 64%
128
+ 124 124,0-1 64%
129
+ 125 125,0-1 65%
130
+ 126 class Target126,1 66%
131
+ 127 127,0-1 66%128  IGNORE = %w( blink_enable blink_disable blink_off blink_on reverse_video_oo ff dim_off dim_on ).map{|x| x.to_sym}128,1 67%
132
+ 129 129,0-1 68%
133
+ 130  def initialize130,1 68%
134
+ 131  @screen = Scriptty::ScreenBuffer.new131,1 69%132  end
135
+ 133 132,1 70%133,0-1 70%
136
+ 134 134,0-1 70%135  def handle(name, input)
137
+ 136  if respond_to?("handle_#{name}")135,1 72%136,1 72%
138
+ 137  send("handle_#{name}", input)137,1 72%138  else # DEBUG FIXME
139
+ 139  print "[#{name}]"138,1 73%139,1 73%
140
+ 140  end140,1 74%
141
+ 141  @count ||= 0141,1 75%
142
+ 142  @count += 1142,1 75%
143
+ 143  if @count % 10 == 0143,1 76%
144
+ 144  #dump144,1 76%
145
+ 145  #gets145,1 77%
146
+ 146  end146,1 78%
147
+ 147  end147,1 78%
148
+ 148 148,0-1 79%149  def dump # DEBUG FIXME
149
+ 150  print "\033c"149,1 80%150,1 80%
150
+ 151  @screen.instance_eval("@glyphs").instance_eval("@lines").each do |line|151,1 81%
151
+ 152  puts line152,1 81%
152
+ 153  end153,1 82%
153
+ 154  end154,1 83%
154
+ 155 155,0-1 83%
155
+ 156  def handle_literal(input)156,1 84%
156
+ 157  @screen.print_char(input)157,1 84%
157
+ 158  #dump158,1 85%
158
+ 159  end159,1 86%
159
+ 160 160,0-1 86%
160
+ 161  def handle_new_line(input)161,1 87%
161
+ 162  @screen.carriage_return162,1 88%
162
+ 163  @screen.cursor_down163,1 88%
163
+ 164  end164,1 89%
164
+ 165 165,0-1 89%
165
+ 166  def handle_carriage_return(input)166,1 90%
166
+ 167  @screen.carriage_return167,1 91%
167
+ 168  end168,1 91%
168
+ 169 169,0-1 92%
169
+ 170  def handle_erase_to_end_of_line(input)170,1 93%149  def dump # DEBUG FIXME
170
+ 150  print "\033c"
171
+ 151  @screen.instance_eval("@glyphs").instance_eval("@lines").each do |line|
172
+ 152  puts line
173
+ 153  end
174
+ 154  end
175
+ 155
176
+ 156  def handle_literal(input)
177
+ 157  @screen.print_char(input)
178
+ 158  #dump
179
+ 159  end
180
+ 160
181
+ 161  def handle_new_line(input)
182
+ 162  @screen.carriage_return
183
+ 163  @screen.cursor_down
184
+ 164  end
185
+ 165
186
+ 166  def handle_carriage_return(input)
187
+ 167  @screen.carriage_return
188
+ 168  end
189
+ 169
190
+ 170  def handle_erase_to_end_of_line(input)
191
+ mytest.rb [RO] 170,1 93%
192
+ 171  @screen.erase_to_end_of_line171,1 93%
193
+ 172  end172,1 94%
194
+ 173 173,0-1 94%
195
+ 174  def handle_write_window_address(input)174,1 95%
196
+ 175  175,1 96%
197
+ 176  end176,1 96%
198
+ 177 end177,1 97%
199
+ 178 178,0-1 98%
200
+ 179 t = Scriptty::Term::DG410.new(Target.new)179,1 98%
201
+ 180 #t.feed(File.read("lots_of_operations.bin"))180,1 99%
202
+ 181 t.feed(File.read("dg410only.bin"))181,1 Bot180,1 Bot181,1 Bot180,1 Bot179,1 Bot 1 #!/usr/bin/env jruby
203
+  2
204
+ 3 $LOAD_PATH.unshift "lib"
205
+  4
206
+ 5 #require 'scriptty/async_sockets'
207
+  6 require 'scriptty/dg410-transition-table'
208
+  7 require 'scriptty/screen_buffer'
209
+  8
210
+ 9 module Scriptty
211
+  10  module Term
212
+  11  class DG410
213
+  12
214
+ 13  class ProprietaryEscapeParser
215
+  14  def initialize(target)
216
+  15  @target = target
217
+  16  @state = :opcode
218
+  17  @opcode = ""
219
+  18  @n = nil
220
+  19  @payload = ""
221
+  20  end
222
+  21
223
+ 22  # <036> ~ <2-byte-opcode> <n> <n*bytes>
224
+ mytest.rb [RO] 1,1 Top2,0-1 Top3,1 Top 23  def feed_byte(input_byte)
225
+  24  case @state
226
+  25  when :opcode
227
+  26  @opcode << input_byte
228
+  27  if @opcode.length >= 2
229
+  28  @state = :n
230
+  29  end
231
+  30  when :n
232
+  31  @n = input_byte.unpack("C*")[0]
233
+  32  if @n > 0
234
+  33  @state = :payload14,9 6% 34  else
235
+  35  @state = :done
236
+  36  end
237
+  37  when :payload
238
+  38  @payload << input_byte
239
+  39  if @payload.length >= @n
240
+  40  @state = :done
241
+  41  end
242
+  42  else
243
+  43  raise "BUG"
244
+  44  end25,11 13% 45  if @state == :done
245
+  46  @target.handle(:proprietary_escape, "#{@opcode}#{[@n].pack("C*")) }#{@payload}")
246
+  47  return true
247
+  48  else
248
+  49  return false
249
+  50  end
250
+  51  end
251
+  52  end
252
+  53
253
+ 54  def initialize(target)36,13 20%:s
254
+  50 end51 end52 end5354 def initialize(target)55 @byte = 1 # DEBUG FIXME
255
+ mytest.rb [RO]36,13 20%37,13 20%38,13 20%39,13 20%40,13 20%41,13 20%42,13 20%43,13 20%44,13 20%45,13 20%46,13 20% @opcode}#{[@n].pack("C*")}#{@payload}")mytest.rb [RO]46,90 20%)46,89 20%{@payload}")46,88 20%{@payload}")46,87 20%46,86 20%46,85 20%46,84 20%46,83 20%46,82 20%46,81 20%46,80 20%{@payload}")46,79 20%{@payload}")46,78 20%{[}#{@payload}")46,77 20%{[()}#{@payload}")46,76 20%()46,75 20%46,74 20%46,73 20%46,72 20%()46,71 20%()46,70 20%46,69 20%46,68 20%46,67 20%46,66 20%[]46,65 20%[]46,64 20%46,63 20%[]46,62 20%{[]}#{@payload}")46,61 20%{[}#{@payload}")46,60 20%}#{[46,59 20%}#{[46,58 20%46,57 20%46,56 20%46,55 20%46,54 20%46,53 20%46,52 20% else @state = :done end en :payload @payload << input_byte if @payload.length >= @n @state = :done end se raise "BUG" d @state == :done@target.handle(:proprietary_escape, "#{@opcode}#{[@n].pack("C*")}#{@payload} return true se return false d itialize(target) e = 1 # DEBUG FIXME
256
+ mytest.rb [RO]46,51 20%{@opcode}#{[46,50 20%46,49 20%46,48 20%46,47 20%46,46 20%46,45 20%46,44 20%46,43 20%46,42 20%46,41 20%46,40 20%46,39 20%46,38 20%46,37 20%46,36 20%46,35 20%46,34 20%46,33 20%46,32 20%46,31 20%46,30 20%46,29 20%46,28 20%(46,27 20%(46,26 20%46,25 20%46,24 20%46,23 20%46,22 20%46,21 20%46,20 20%46,19 20%46,18 20%46,17 20%46,16 20%46,15 20%46,14 20%46,13 20%   else @state = :done   end  when :payload  @payload << input_byte  if @payload.length >= @n @state = :done   end   else  raise "BUG"   end if @state == :done  @target.handle(:proprietary_escape, "#{@opcode}#{[@n].pack("C*")  return true   else  return false   end end end  def initialize(target)  @byte = 1 # DEBUG FIXME
257
+ mytest.rb [RO]46,12 20%46,11 20%46,10 20%46,9 20%46,8 20%46,7 20%46,6 20%46,5 20%46,4 20%46,3 20%46,2 20%46,1 20%:q
258
+ dwaynelitzenberger$
259
+ iMac-002:~/components/scriptty/main
260
+ dwaynelitzenberger$ exit
261
+
262
+ Script done on Mon Mar 1 17:15:28 2010
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
4
+ require 'rubygems'
5
+ require 'scriptty/term/xterm'
6
+
7
+ t = ScripTTY::Term::XTerm.new
8
+ print "\ec" # reset
9
+ delay = ARGV[1] ? ARGV[1].to_f : 0.001
10
+ File.read(ARGV[0] || "captures/xterm-overlong-line-prompt.bin").split("").each { |byte|
11
+ t.feed_byte(byte)
12
+ print "\e[H" + t.text.join("\n") + "\n"
13
+ row, col = t.cursor_pos
14
+ print "\e[#{row+1};#{col+1}H"
15
+ $stdout.flush
16
+ if delay > 0
17
+ sleep delay
18
+ end
19
+ }