term-vt102 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,48 @@
1
+ # Make sure the VT102 module can handle ANSI colour, underline, bold, etc.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestColour < TestBase
12
+ def test_original
13
+ # (F,B,b,f,s,u,F,r)
14
+ assert_screen [
15
+ 7, 4, "\e[m0\e[1m1\e[2m2\e[4m3\e[5m4\e[7m5\e[m6\r\n",
16
+ "0123456", [ [7,0,0,0,0,0,0,0],
17
+ [7,0,1,0,0,0,0,0],
18
+ [7,0,0,1,0,0,0,0],
19
+ [7,0,0,1,0,1,0,0],
20
+ [7,0,0,1,0,1,1,0],
21
+ [7,0,0,1,0,1,1,1],
22
+ [7,0,0,0,0,0,0,0] ]
23
+ ]
24
+
25
+ assert_screen [
26
+ 7, 4, "\e[41;35m0\e[1m1\e[2m2\e[4m3\e[5m4\e[7m5\e[m6\r\n",
27
+ "0123456", [ [5,1,0,0,0,0,0,0],
28
+ [5,1,1,0,0,0,0,0],
29
+ [5,1,0,1,0,0,0,0],
30
+ [5,1,0,1,0,1,0,0],
31
+ [5,1,0,1,0,1,1,0],
32
+ [5,1,0,1,0,1,1,1],
33
+ [7,0,0,0,0,0,0,0] ]
34
+ ]
35
+
36
+ assert_screen [
37
+ 8, 4, "\e[33;42m0\e[1m1\e[21m2\e[2m3\e[22m4\e[38m5\e[39m6\e[49m7\r\n",
38
+ "01234567",[ [3,2,0,0,0,0,0,0],
39
+ [3,2,1,0,0,0,0,0],
40
+ [3,2,0,0,0,0,0,0],
41
+ [3,2,0,1,0,0,0,0],
42
+ [3,2,0,0,0,0,0,0],
43
+ [7,2,0,0,0,1,0,0],
44
+ [7,2,0,0,0,0,0,0],
45
+ [7,0,0,0,0,0,0,0] ],
46
+ ]
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ # Make sure the VT102 module's option settings work.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestOptions < TestBase
12
+ def test_00_options
13
+ assert_screens [
14
+ [ { 'LFTOCRLF' => 1 }, 10, 5, "line 1\n line 2\n line 3\nline 4",
15
+ "line 1" + ("\0" * 4),
16
+ " line 2" + ("\0" * 2),
17
+ " line 3" + ("\0" * 2),
18
+ "line 4" + ("\0" * 4),
19
+ ],
20
+ [ { 'LINEWRAP' => 1 }, 10, 5, "abcdefghijklmnopqrstuvwxyz",
21
+ "abcdefghij",
22
+ "klmnopqrst",
23
+ "uvwxyz" + ("\0" * 4),
24
+ ],
25
+ ]
26
+ end
27
+ end
@@ -0,0 +1,57 @@
1
+ # Make sure the VT102 module's callbacks.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestCallback < TestBase
12
+ def setup
13
+ @vt = Term::VT102.new(cols: 80, rows: 25)
14
+ @testarg1 = @testarg2 = @testpriv = 0
15
+ end
16
+
17
+ def testcallback
18
+ -> (tty, callname, arg1, arg2, priv) do
19
+ @testarg1, @testarg2, @testpriv = arg1, arg2, priv
20
+ end
21
+ end
22
+
23
+ def test_00_rowchange_runs
24
+ @vt.callback_call('ROWCHANGE', 0, 0)
25
+ end
26
+
27
+ def test_01_rowchange_sets_private_data
28
+ @vt.callback_set('ROWCHANGE', testcallback, 123)
29
+ @vt.callback_call('ROWCHANGE', 0, 0)
30
+ assert_equal 123, @testpriv
31
+ end
32
+
33
+ def test_02_string_callback_reports_esc
34
+ @vt.callback_set('STRING', testcallback, 2)
35
+ @vt.process("\033_Test String\033\\test")
36
+
37
+ assert_equal 'APC', @testarg1
38
+ assert_equal 'Test String', @testarg2
39
+ assert_equal 2, @testpriv
40
+ end
41
+
42
+ def test_03_xicon
43
+ @vt.callback_set('XICONNAME', testcallback, 3)
44
+ @vt.process("\033]1;Test Icon Name\033\\test")
45
+
46
+ assert_equal 'Test Icon Name', @testarg1
47
+ assert_equal 3, @testpriv
48
+ end
49
+
50
+ def test_04_xwintitle
51
+ @vt.callback_set('XWINTITLE', testcallback, 4)
52
+ @vt.process("\033]2;Test Title\033\\test")
53
+
54
+ assert_equal 'Test Title', @testarg1
55
+ assert_equal 4, @testpriv
56
+ end
57
+ end
@@ -0,0 +1,34 @@
1
+ # Test DECALN.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestDecaln < TestBase
12
+ def test_00_decaln
13
+ # (F,B,b,f,s,u,F,r)
14
+ assert_screens [
15
+ [ 5, 3, "b\e[41;33mlah\nblah\r\nblah\e#8test",
16
+ "testE", [ [3,1,0,0,0,0,0,0],
17
+ [3,1,0,0,0,0,0,0],
18
+ [3,1,0,0,0,0,0,0],
19
+ [3,1,0,0,0,0,0,0],
20
+ [7,0,0,0,0,0,0,0] ],
21
+ "EEEEE", [ [7,0,0,0,0,0,0,0],
22
+ [7,0,0,0,0,0,0,0],
23
+ [7,0,0,0,0,0,0,0],
24
+ [7,0,0,0,0,0,0,0],
25
+ [7,0,0,0,0,0,0,0] ],
26
+ "EEEEE", [ [7,0,0,0,0,0,0,0],
27
+ [7,0,0,0,0,0,0,0],
28
+ [7,0,0,0,0,0,0,0],
29
+ [7,0,0,0,0,0,0,0],
30
+ [7,0,0,0,0,0,0,0] ],
31
+ ]
32
+ ]
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # Test DECSC and DECRC.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestDecscrc < TestBase
12
+ def test_00_decsc_decrc
13
+ # (F,B,b,f,s,u,F,r)
14
+ assert_screens [
15
+ [ 5, 3, "\e[41;33mtest\e7\e[2H\e[42;34mgrok\e7\e[m\e[3Hfoo\e82\e81",
16
+ "test1", [ [3,1,0,0,0,0,0,0],
17
+ [3,1,0,0,0,0,0,0],
18
+ [3,1,0,0,0,0,0,0],
19
+ [3,1,0,0,0,0,0,0],
20
+ [3,1,0,0,0,0,0,0] ],
21
+ "grok2", [ [4,2,0,0,0,0,0,0],
22
+ [4,2,0,0,0,0,0,0],
23
+ [4,2,0,0,0,0,0,0],
24
+ [4,2,0,0,0,0,0,0],
25
+ [4,2,0,0,0,0,0,0] ],
26
+ "foo\0\0", [ [7,0,0,0,0,0,0,0],
27
+ [7,0,0,0,0,0,0,0],
28
+ [7,0,0,0,0,0,0,0],
29
+ [7,0,0,0,0,0,0,0],
30
+ [7,0,0,0,0,0,0,0] ],
31
+ ]
32
+ ]
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # Test CUPSV and CUPRS.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestCupsvrs < TestBase
12
+ def test_00_cupsv_cuprs
13
+ # (F,B,b,f,s,u,F,r)
14
+ assert_screens [
15
+ [ 5, 3, "\e[41;33mtest\e[s\e[2H\e[42;34mgrok\e[s\e[m\e[3Hfoo\e[u2\e[u1",
16
+ "test1", [ [3,1,0,0,0,0,0,0],
17
+ [3,1,0,0,0,0,0,0],
18
+ [3,1,0,0,0,0,0,0],
19
+ [3,1,0,0,0,0,0,0],
20
+ [7,0,0,0,0,0,0,0] ],
21
+ "grok2", [ [4,2,0,0,0,0,0,0],
22
+ [4,2,0,0,0,0,0,0],
23
+ [4,2,0,0,0,0,0,0],
24
+ [4,2,0,0,0,0,0,0],
25
+ [7,0,0,0,0,0,0,0] ],
26
+ "foo\0\0", [ [7,0,0,0,0,0,0,0],
27
+ [7,0,0,0,0,0,0,0],
28
+ [7,0,0,0,0,0,0,0],
29
+ [7,0,0,0,0,0,0,0],
30
+ [7,0,0,0,0,0,0,0] ],
31
+ ]
32
+ ]
33
+ end
34
+ end
@@ -0,0 +1,47 @@
1
+ # Test XOFF and XON.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestXonxoff < TestBase
12
+ def test_00_xon_xoff
13
+ # (F,B,b,f,s,u,F,r)
14
+ assert_screens [
15
+ [ { 'IGNOREXOFF' => 0 },
16
+ 6, 2, "foo\023bar\e[1m\021baz",
17
+ "foobaz", [ [7,0,0,0,0,0,0,0],
18
+ [7,0,0,0,0,0,0,0],
19
+ [7,0,0,0,0,0,0,0],
20
+ [7,0,0,0,0,0,0,0],
21
+ [7,0,0,0,0,0,0,0],
22
+ [7,0,0,0,0,0,0,0] ],
23
+ "\0\0\0\0\0\0",
24
+ [ [7,0,0,0,0,0,0,0],
25
+ [7,0,0,0,0,0,0,0],
26
+ [7,0,0,0,0,0,0,0],
27
+ [7,0,0,0,0,0,0,0],
28
+ [7,0,0,0,0,0,0,0],
29
+ [7,0,0,0,0,0,0,0] ],
30
+ ],
31
+ [ { 'IGNOREXOFF' => 1 },
32
+ 9, 1, "foo\023bar\e[1m\021baz",
33
+ "foobarbaz",
34
+ [ [7,0,0,0,0,0,0,0],
35
+ [7,0,0,0,0,0,0,0],
36
+ [7,0,0,0,0,0,0,0],
37
+ [7,0,0,0,0,0,0,0],
38
+ [7,0,0,0,0,0,0,0],
39
+ [7,0,0,0,0,0,0,0],
40
+ [7,0,1,0,0,0,0,0],
41
+ [7,0,1,0,0,0,0,0],
42
+ [7,0,1,0,0,0,0,0] ],
43
+ ]
44
+ ]
45
+ end
46
+ end
47
+
@@ -0,0 +1,32 @@
1
+ # Make sure the VT102 module can handle tabs and tab stops.
2
+ #
3
+ # Copyright (C) Mike Owens
4
+ # Copyright (C) Andrew Wood
5
+ # NO WARRANTY - see LICENSE.txt
6
+ #
7
+
8
+ require 'test_helper'
9
+ require 'term/vt102'
10
+
11
+ class TestTabstop < TestBase
12
+ def test_00_tabstops
13
+ tabs = "a\tb\tc\td\te\tf\tg\th\ti\tj\tk"
14
+ assert_screen [
15
+ 80, 9,
16
+ "Line 1\r" + tabs + "\r\nLine 2\e[3g\r\nLine 3\r" + tabs + "\r\n" +
17
+ "Line 4\e[3g\e[9G\eHt\e[17G\eHt\e[25G\eHt\e[33G\eHt\e[41G\eHt\e[49G\eHt\e[57G\eHt\e[65G\eHt\e[73G\eHt\r\n" +
18
+ "Line 5\r" + tabs + "\r\n" +
19
+ "Line 6\e[17G\e[gT\r" + tabs + "\r\n" +
20
+ "Line 7\e[3g\e[5G\eHt\e[10G\eHt\e[15G\eHt\e[20G\eHt\r\n" +
21
+ "Line 8\r" + tabs + "\r\n",
22
+ "aine 1\0\0b\0\0\0\0\0\0\0c\0\0\0\0\0\0\0d\0\0\0\0\0\0\0e\0\0\0\0\0\0\0f\0\0\0\0\0\0\0g\0\0\0\0\0\0\0h\0\0\0\0\0\0\0i\0\0\0\0\0\0\0j\0\0\0\0\0\0k",
23
+ "Line 2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
24
+ "aine 3\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0k",
25
+ "Line 4\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0t\0\0\0\0\0\0\0",
26
+ "aine 5\0\0b\0\0\0\0\0\0\0c\0\0\0\0\0\0\0d\0\0\0\0\0\0\0e\0\0\0\0\0\0\0f\0\0\0\0\0\0\0g\0\0\0\0\0\0\0h\0\0\0\0\0\0\0i\0\0\0\0\0\0\0j\0\0\0\0\0\0k",
27
+ "aine 6\0\0b\0\0\0\0\0\0\0T\0\0\0\0\0\0\0c\0\0\0\0\0\0\0d\0\0\0\0\0\0\0e\0\0\0\0\0\0\0f\0\0\0\0\0\0\0g\0\0\0\0\0\0\0h\0\0\0\0\0\0\0i\0\0\0\0\0\0k",
28
+ "Linet7\0\0\0t\0\0\0\0t\0\0\0\0t\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
29
+ "aineb8\0\0\0c\0\0\0\0d\0\0\0\0e\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0k",
30
+ ]
31
+ end
32
+ end
@@ -0,0 +1,92 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'minitest/autorun'
4
+ require 'term/vt102'
5
+
6
+ class TestBase < Minitest::Test
7
+ # These aren't actually order dependent, but it's nice to see them in
8
+ # the same order as the Perl original, for comparison's sake.
9
+ i_suck_and_my_tests_are_order_dependent!
10
+
11
+ def show_text(text)
12
+ return '' if text.nil?
13
+
14
+ text.gsub!(/[^\040-\176]/) do |one|
15
+ sprintf('\\%o', one.ord)
16
+ end
17
+
18
+ text
19
+ end
20
+
21
+ def show_attr(vt, attr)
22
+ fg, bg, bo, fa, st, ul, bl, rv = vt.attr_unpack(attr)
23
+ str = "#{fg}-#{bg}"
24
+
25
+ str += 'b' if bo != 0
26
+ str += 'f' if fa != 0
27
+ str += 's' if st != 0
28
+ str += 'u' if ul != 0
29
+ str += 'F' if bl != 0
30
+ str += 'r' if rv != 0
31
+
32
+ return str + '-' + sprintf('%04X', attr.unpack('S').first)
33
+ end
34
+
35
+ def assert_screens(screens)
36
+ screens.each do |screen|
37
+ assert_screen(screen)
38
+ end
39
+ end
40
+
41
+ def assert_screen(screen)
42
+ settings = nil
43
+
44
+ cols, rows, text, *output = screen
45
+ settings = nil
46
+ if cols.is_a?(Enumerable)
47
+ settings, cols, rows, text, *output = screen
48
+ end
49
+
50
+ vt = Term::VT102.new(cols: cols, rows: rows)
51
+ assert_equal [cols, rows], vt.size
52
+
53
+ if settings
54
+ settings.each do |k, v|
55
+ refute_nil vt.option_set(k, v), "failed to set option #{k}=#{v}"
56
+ end
57
+ end
58
+
59
+ vt.process(text)
60
+
61
+ row = 0
62
+
63
+ alineref = nil
64
+ while output.size - 1 > 0
65
+ line = output.shift
66
+ if output.first.is_a?(Array)
67
+ alineref = output.shift
68
+ aline = ''
69
+ alineref.each do |l|
70
+ aline += vt.attr_pack(*l)
71
+ end
72
+ else
73
+ alineref = nil
74
+ end
75
+
76
+ row += 1
77
+ assert_equal line, vt.row_text(row), "row #{row} incorrect"
78
+
79
+ next if alineref.nil?
80
+
81
+ galine = vt.row_attr(row)
82
+ (0...cols).each do |col|
83
+ expected = aline[2 * col, 2]
84
+ actual = galine[2 * col, 2]
85
+
86
+ assert_equal expected, actual,
87
+ "row #{row}; attributes #{show_attr(vt, expected)} vs " +
88
+ "#{show_attr(vt, actual)}"
89
+ end
90
+ end
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: term-vt102
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Owens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.2'
55
+ description:
56
+ email:
57
+ - mike@filespanker.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CREDITS.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - examples/tmux_ghost.rb
70
+ - lib/term/vt102.rb
71
+ - lib/term/vt102/version.rb
72
+ - term-vt102.gemspec
73
+ - test/test_01_load.rb
74
+ - test/test_02_setsize.rb
75
+ - test/test_03_text.rb
76
+ - test/test_04_cursor.rb
77
+ - test/test_05_scrolling.rb
78
+ - test/test_06_insdel.rb
79
+ - test/test_07_colour.rb
80
+ - test/test_08_options.rb
81
+ - test/test_09_callback.rb
82
+ - test/test_10_decaln.rb
83
+ - test/test_11_decscrc.rb
84
+ - test/test_12_cupsvrs.rb
85
+ - test/test_13_xonxoff.rb
86
+ - test/test_14_tabstop.rb
87
+ - test/test_helper.rb
88
+ homepage: https://github.com/mieko/term-vt102
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.0.rc.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: VT102 terminal implementation
112
+ test_files:
113
+ - test/test_01_load.rb
114
+ - test/test_02_setsize.rb
115
+ - test/test_03_text.rb
116
+ - test/test_04_cursor.rb
117
+ - test/test_05_scrolling.rb
118
+ - test/test_06_insdel.rb
119
+ - test/test_07_colour.rb
120
+ - test/test_08_options.rb
121
+ - test/test_09_callback.rb
122
+ - test/test_10_decaln.rb
123
+ - test/test_11_decscrc.rb
124
+ - test/test_12_cupsvrs.rb
125
+ - test/test_13_xonxoff.rb
126
+ - test/test_14_tabstop.rb
127
+ - test/test_helper.rb