landescape 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22dbf4f4d4ebb551c726f65d7894706fd8e8cb7c
4
- data.tar.gz: 5fad1bddcbfb7860b9eff86c48808e99fa934d7b
3
+ metadata.gz: 9274da0802ff844f74114a7c4e13866b0517808f
4
+ data.tar.gz: a6fa4e42047ae8e019177914a517c622401a24c8
5
5
  SHA512:
6
- metadata.gz: cc43b68028b01c3d3229b75008430cc0d8ef2ed2e6733212bdbe31266214fe029d331142b6ab2f96b435cb2e1e9c22402bcdb18d3fe9921d80e71cd4bb51f54a
7
- data.tar.gz: 2c498dc00f67c24cd5c92a8f722e6c6bacb0dd11d9b7f0da8c6b2a9387fc0b99e13be151b4635522e7fad85515be195a72af122205c7c01847ca112667db25c5
6
+ metadata.gz: f1658939a683ca03d4008e5b1ee3237ebdb24189081e1ac6711d3d54965e02db3bc2aeeea221442583813e2729fe606e2b2d7908042da9b978aab3d41016d6cc
7
+ data.tar.gz: 43085e61f8399bccb9891994fbea7903ad7cdb51442b20372fa85ce3bb11919f8e8b97bf1ec6e36756c2e96343aa683e62271d034b82c891e2747c1790abafca
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - '1.9.3'
3
+ - '2.0.0'
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Landescape
2
2
 
3
+ [![Build Status](https://travis-ci.org/hibariya/landescape.png?branch=master)](https://travis-ci.org/hibariya/landescape)
4
+
3
5
  Landscape is a library for handling escape sequence.
4
6
 
5
7
  ## Is It Good?
@@ -22,7 +22,7 @@ module Landescape
22
22
  begin
23
23
  statements.shift(@options[:non_block])
24
24
  rescue ThreadError
25
- Thread.kill
25
+ Thread.exit
26
26
  end
27
27
 
28
28
  if self.class.method_defined?(name)
@@ -30,11 +30,9 @@ module Landescape
30
30
  return exit_attribute_mode if modes.empty?
31
31
 
32
32
  modes.each do |mode|
33
- if attr = GRAPHICS_MODES[mode]
34
- window.attron attr
35
- else
36
- exit_attribute_mode
37
- end
33
+ next unless attr = GRAPHICS_MODES[mode]
34
+
35
+ window.attron attr
38
36
  end
39
37
  end
40
38
 
@@ -49,7 +49,7 @@ module Landescape
49
49
  def escape(token)
50
50
  token << read_char
51
51
 
52
- case token.chars.last
52
+ case token[-1]
53
53
  when /\[/
54
54
  escape_code token
55
55
  when /[()]/
@@ -68,7 +68,7 @@ module Landescape
68
68
  def escape_code(token)
69
69
  token << read_char
70
70
 
71
- case token.chars.last
71
+ case token[-1]
72
72
  when /[\d?;<=>]/
73
73
  escape_code token
74
74
  when /[a-zA-Z]/
@@ -81,7 +81,7 @@ module Landescape
81
81
  def escape_code_parens(token)
82
82
  token << read_char
83
83
 
84
- case token.chars.last
84
+ case token[-1]
85
85
  when /[\da-zA-Z]/
86
86
  token
87
87
  else
@@ -92,7 +92,7 @@ module Landescape
92
92
  def escape_code_sharp(token)
93
93
  token << read_char
94
94
 
95
- case token.chars.last
95
+ case token[-1]
96
96
  when /\d/
97
97
  token
98
98
  else
@@ -103,7 +103,7 @@ module Landescape
103
103
  def escape_code_slash(token)
104
104
  token << read_char
105
105
 
106
- case token.chars.last
106
+ case token[-1]
107
107
  when /[a-zA-Z]/
108
108
  token
109
109
  else
@@ -112,7 +112,7 @@ module Landescape
112
112
  end
113
113
 
114
114
  def fallback(token)
115
- token.chars
115
+ token.chars.to_a
116
116
  end
117
117
 
118
118
  def read_char
@@ -1,3 +1,3 @@
1
1
  module Landescape
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,4 +1,112 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Landescape::Evaluator do
3
+ describe Landescape::Curses do
4
+ def evaluate(tokens, window)
5
+ evaluator = Landescape::Curses.start(array_to_result(tokens), window, non_block: true)
6
+ eval_thread = evaluator.instance_variable_get(:@eval_thread)
7
+ eval_thread.join if eval_thread.alive?
8
+ end
9
+
10
+ let(:window) { double(:window) }
11
+
12
+ before do
13
+ window.stub(:maxy) { 20 }
14
+ end
15
+
16
+ describe '#print' do
17
+ it do
18
+ window.should receive(:addstr).with 'H'
19
+ window.should receive :refresh
20
+
21
+ evaluate [[:print, 'H']], window
22
+ end
23
+ end
24
+
25
+ describe '#set_attributes' do
26
+ context 'supported attribute' do
27
+ it do
28
+ window.should receive(:attron).with ::Curses::A_BLINK
29
+
30
+ evaluate [[:set_attributes, 5]], window
31
+ end
32
+ end
33
+
34
+ context 'not supported attribute' do
35
+ it do
36
+ window.should_not receive :attron
37
+ window.should_not receive :attroff
38
+
39
+ evaluate [[:set_attributes, 33]], window
40
+ end
41
+ end
42
+
43
+ context 'empty arguments' do
44
+ it do
45
+ window.should receive :attroff
46
+
47
+ evaluate [[:set_attributes]], window
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#exit_attribute_mode' do
53
+ it do
54
+ window.should receive :attroff
55
+
56
+ evaluate [[:exit_attribute_mode]], window
57
+ end
58
+ end
59
+
60
+ describe '#change_scroll_region' do
61
+ it do
62
+ window.should receive(:setscrreg).with 5, 10
63
+
64
+ evaluate [[:change_scroll_region, 5, 10]], window
65
+ end
66
+ end
67
+
68
+ describe '#scroll_reverse' do
69
+ it do
70
+ window.should receive(:scrl).with -1
71
+
72
+ evaluate [[:scroll_reverse]], window
73
+ end
74
+ end
75
+
76
+ describe '#scroll_forward' do
77
+ it do
78
+ window.should receive(:scrl).with 1
79
+
80
+ evaluate [[:scroll_forward]], window
81
+ end
82
+ end
83
+
84
+ describe '#cursor_address' do
85
+ context 'not on bottom' do
86
+ before do
87
+ window.stub(:cury) { 1 }
88
+ window.stub(:maxy) { 21 }
89
+ end
90
+
91
+ it do
92
+ window.should receive(:setpos).with 4, 2
93
+
94
+ evaluate [[:cursor_address, 4, 2]], window
95
+ end
96
+ end
97
+
98
+ context 'on bottom' do
99
+ before do
100
+ window.stub(:cury) { 20 }
101
+ window.stub(:maxy) { 21 }
102
+ end
103
+
104
+ it do
105
+ window.should receive(:scrl).with 1
106
+ window.should receive(:setpos).with 23, 2
107
+
108
+ evaluate [[:cursor_address, 23, 2]], window
109
+ end
110
+ end
111
+ end
4
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: landescape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hibariya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-02 00:00:00.000000000 Z
11
+ date: 2013-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
63
  - .rspec
64
+ - .travis.yml
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
100
  version: '0'
100
101
  requirements: []
101
102
  rubyforge_project:
102
- rubygems_version: 2.1.10
103
+ rubygems_version: 2.0.3
103
104
  signing_key:
104
105
  specification_version: 4
105
106
  summary: Handle escape sequence