vedeu 0.0.2 → 0.0.3

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: e7dc331e1fb585d179a308db5dd6a215b137ab61
4
- data.tar.gz: a380806ad198b429f83e5934143f8b45a6d6957e
3
+ metadata.gz: e7b69828438f5c4c2e1f77d6e896bbbfd457b274
4
+ data.tar.gz: ee12ce2adccea5c742fa57481244ddcbe5361c51
5
5
  SHA512:
6
- metadata.gz: 18dfcd631845fdb9338c68402dff180d11aad2eae555ba4f6b1c2621738f9651785810a9995f87f23584b847f64a240e6aa09cb40e0fc88123e9b045e579c1a1
7
- data.tar.gz: d92cf80a6c1ee4170b6b2428251e5aa21101480caf8a571b384a91252bf87f7ed06a3fc19f3dd847171806b55b94c6f248d0e9c0d2a1160c788e94733b89c6f4
6
+ metadata.gz: b295f951023c13aac3d7a15982c8f9537d9bf44b8e3431b7019950baac7d90ec78f94efcac5549933d7e749b7ff2da2532079727bf5cf70c58281e5ac537c2ee
7
+ data.tar.gz: 81a59ef69bdb6bea4e16d05b4beaa8f5723de52e651454ea54b22bfeea517c30553b92d4ff79a9b04b657e8acd478f66ab0df3deae6ac77fdf53d6e6920df05f
@@ -1,6 +1,8 @@
1
+ require 'io/console'
1
2
  require "vedeu/version"
2
3
  require 'vedeu/buffer'
4
+ require 'vedeu/colour'
5
+ require 'vedeu/terminal'
3
6
 
4
7
  module Vedeu
5
- # Your code goes here...
6
8
  end
@@ -2,6 +2,8 @@ module Vedeu
2
2
  class OutOfRangeError < StandardError; end
3
3
 
4
4
  class Buffer
5
+ include Enumerable
6
+
5
7
  attr_accessor :buffer
6
8
 
7
9
  def initialize(options = {})
@@ -9,16 +11,13 @@ module Vedeu
9
11
  @buffer = Array.new(height) { Array.new(width) { ' ' } }
10
12
  end
11
13
 
12
- def contents
13
- print "\n"
14
- buffer.map do |y|
15
- y.map do |x|
16
- print "'#{x}'"
17
- end
18
- print "\n"
19
- end
14
+ def each(&block)
15
+ buffer.each(&block)
16
+ end
20
17
 
21
- nil
18
+ def contents
19
+ puts
20
+ buffer.map { |y| y.map { |x| print "'#{x}'" }; puts }
22
21
  end
23
22
 
24
23
  def cell(y, x)
@@ -90,4 +89,18 @@ module Vedeu
90
89
  }
91
90
  end
92
91
  end
92
+
93
+ def self.test_Vedeu__Buffer(klass = Vedeu::Buffer)
94
+ buffer = klass.new(width: 5, height: 3)
95
+
96
+ buffer.set_row(0, 'field')
97
+ buffer.set_row(1, 'grows')
98
+ buffer.set_row(2, 'maize')
99
+
100
+ puts
101
+
102
+ buffer.map { |y| y.map { |x| print "#{x}" }; puts }
103
+
104
+ puts
105
+ end
93
106
  end
@@ -0,0 +1,98 @@
1
+ module Vedeu
2
+ class Colour
3
+ class << self
4
+ def set(pair = [])
5
+ new(pair).set
6
+ end
7
+ alias_method :reset, :set
8
+ end
9
+
10
+ def initialize(pair = [])
11
+ @pair = pair
12
+ end
13
+
14
+ def set
15
+ return reset if pair.empty?
16
+
17
+ [esc, foreground_code, ';', background_code, 'm'].join
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :pair
23
+
24
+ def foreground_code
25
+ foreground_codes[foreground] || foreground_codes[:default]
26
+ end
27
+
28
+ def background_code
29
+ background_codes[background] || background_codes[:default]
30
+ end
31
+
32
+ def foreground_codes
33
+ {
34
+ black: 30,
35
+ red: 31,
36
+ green: 32,
37
+ yellow: 33,
38
+ blue: 34,
39
+ magenta: 35,
40
+ cyan: 36,
41
+ white: 37,
42
+ default: 39,
43
+ }
44
+ end
45
+
46
+ def background_codes
47
+ {
48
+ black: 40,
49
+ red: 41,
50
+ green: 42,
51
+ yellow: 43,
52
+ blue: 44,
53
+ magenta: 45,
54
+ cyan: 46,
55
+ white: 47,
56
+ default: 49,
57
+ }
58
+ end
59
+
60
+ def foreground
61
+ pair[0]
62
+ end
63
+
64
+ def background
65
+ pair[1]
66
+ end
67
+
68
+ def reset
69
+ [esc, '0m'].join
70
+ end
71
+
72
+ def esc
73
+ [27.chr, '['].join
74
+ end
75
+ end
76
+
77
+ def self.test_Vedue__Colour(klass = Vedeu::Colour)
78
+ codes = [
79
+ :black,
80
+ :red,
81
+ :green,
82
+ :yellow,
83
+ :blue,
84
+ :magenta,
85
+ :cyan,
86
+ :white,
87
+ :default
88
+ ]
89
+
90
+ codes.each do |fg|
91
+ codes.each do |bg|
92
+ print [klass.set([fg, bg]), '*', klass.reset].join
93
+ end
94
+ puts
95
+ end
96
+ puts
97
+ end
98
+ end
@@ -0,0 +1,25 @@
1
+ module Vedeu
2
+ class Terminal
3
+ def width
4
+ size[1]
5
+ end
6
+
7
+ def height
8
+ size[0]
9
+ end
10
+
11
+ private
12
+
13
+ def size
14
+ IO.console.winsize
15
+ end
16
+ end
17
+
18
+ def self.test_Vedue__Terminal(klass = Vedeu::Terminal)
19
+ terminal = klass.new
20
+
21
+ puts "Width: #{terminal.width}"
22
+ puts "Height: #{terminal.height}"
23
+ puts
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,57 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Colour do
5
+ let(:klass) { Colour }
6
+ let(:instance) { klass.new }
7
+ let(:pair) { [] }
8
+
9
+ it 'returns an instance of self' do
10
+ instance.must_be_instance_of(Vedeu::Colour)
11
+ end
12
+
13
+ describe '.set' do
14
+ subject { klass.set(pair) }
15
+
16
+ context 'when both the foreground and background is specified' do
17
+ let(:pair) { [:red, :yellow] }
18
+
19
+ it 'returns the code for red on yellow' do
20
+ subject.must_equal("\e[31;43m")
21
+ end
22
+ end
23
+
24
+ context 'when a foreground is specified' do
25
+ let(:pair) { [:blue] }
26
+
27
+ it 'returns the code for blue on default' do
28
+ subject.must_equal("\e[34;49m")
29
+ end
30
+ end
31
+
32
+ context 'when a background is specified' do
33
+ let(:pair) { [nil, :cyan] }
34
+
35
+ it 'returns the code for default with cyan background' do
36
+ subject.must_equal("\e[39;46m")
37
+ end
38
+ end
39
+
40
+ context 'when an invalid foreground/background is specified' do
41
+ let(:pair) { [:melon, :raspberry] }
42
+
43
+ it 'returns the default code' do
44
+ subject.must_equal("\e[39;49m")
45
+ end
46
+ end
47
+
48
+ context 'when no foreground/background is specified' do
49
+ let(:pair) { [] }
50
+
51
+ it 'returns the reset code' do
52
+ subject.must_equal("\e[0m")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,30 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Terminal do
5
+ let(:klass) { Terminal }
6
+ let(:instance) { klass.new }
7
+ let(:console) { stub }
8
+
9
+ before do
10
+ IO.stubs(:console).returns(console)
11
+ console.stubs(:winsize).returns([25, 80])
12
+ end
13
+
14
+ it 'returns an instance of self' do
15
+ instance.must_be_instance_of(Vedeu::Terminal)
16
+ end
17
+
18
+ describe '#width' do
19
+ it 'returns the width of the terminal' do
20
+ instance.width.must_equal(80)
21
+ end
22
+ end
23
+
24
+ describe '#height' do
25
+ it 'returns the height of the terminal' do
26
+ instance.height.must_equal(25)
27
+ end
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -238,8 +238,12 @@ files:
238
238
  - features/.gitkeep
239
239
  - lib/vedeu.rb
240
240
  - lib/vedeu/buffer.rb
241
+ - lib/vedeu/colour.rb
242
+ - lib/vedeu/terminal.rb
241
243
  - lib/vedeu/version.rb
242
244
  - test/lib/vedeu/buffer_test.rb
245
+ - test/lib/vedeu/colour_test.rb
246
+ - test/lib/vedeu/terminal_test.rb
243
247
  - test/test_helper.rb
244
248
  - vedeu.gemspec
245
249
  homepage: http://www.gavinlaking.name/
@@ -269,5 +273,7 @@ summary: A terminal case of wonderland.
269
273
  test_files:
270
274
  - features/.gitkeep
271
275
  - test/lib/vedeu/buffer_test.rb
276
+ - test/lib/vedeu/colour_test.rb
277
+ - test/lib/vedeu/terminal_test.rb
272
278
  - test/test_helper.rb
273
279
  has_rdoc: