term_canvas 0.2.1 → 0.2.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
  SHA256:
3
- metadata.gz: f8c54728d7f876d1aa82e8ddbc48eabc7d33476a1f39bbdd79babb261617a84b
4
- data.tar.gz: 263a5abc39bd39609fd8a9f99e8c595121600c567c6412c48f8fdf5d00d573d8
3
+ metadata.gz: 9c4251fea2c58b06ee6abcd500cc3989b9b69b0b9b3f9f61d487606069395896
4
+ data.tar.gz: 2e5f06c64d6d194c91ee33946c41d0f8fc624e46e8cdd942b691d96250ed5b2c
5
5
  SHA512:
6
- metadata.gz: 7b57a29c28a218ebf190e25a1bcc85153c049cd99f90edf66baaed71ae7c7d6f45aa3b1af853fc975a4ccb970acda54634e25a48ce1704dc0ea1d782936f3e9b
7
- data.tar.gz: 1de968194c022af1929025af01ad851b344b8efe71731bad67da7ea794f516c4b952a8f674047c570da898f04e41fdd7a2892134fdfe0613598e26599ee447c2
6
+ metadata.gz: 0d3b6d8b5a5f85c74c538328390c84cbb79d2de7c37fde7b5f7d03a95e4cdd10226e0d4a7499d45acaba7131afafc34f21f5cb43cdc098249ee778dee0191f7a
7
+ data.tar.gz: 576234dab5b4cca43477efe33db2462ac5b49340310d3a9723f5248a1418ff8edbd4ecf23ad05912657ec924957454a3b5c654254ce6a070a6a33838f43f26f4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- term_canvas (0.2.1)
4
+ term_canvas (0.2.2)
5
5
  curses
6
6
 
7
7
  GEM
data/_examples/test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'term_canvas'
2
2
 
3
- field = TermCanvas.new(x: 0, y: 0, w: 50, h: 30)
3
+ field = TermCanvas::Canvas.new(x: 0, y: 0, w: 50, h: 30)
4
4
 
5
5
  text_pos = {y: 0, x: 0}
6
6
  loop do
@@ -20,12 +20,12 @@ loop do
20
20
 
21
21
  field.clear
22
22
  field.rect(
23
- Rect.new(
23
+ TermCanvas::Rect.new(
24
24
  x: 0, y: 0, width: 10, height: 10, background_color: {r: 200, b: 200, g: 800}
25
25
  )
26
26
  )
27
27
  field.text(
28
- Text.new(
28
+ TermCanvas::Text.new(
29
29
  x: text_pos[:x], y: text_pos[:y], body: "test",
30
30
  background_color: {r: 800, g: 800, b: 800}, foreground_color: {r: 200, g: 200, b: 200}
31
31
  )
data/lib/term_canvas.rb CHANGED
@@ -3,87 +3,88 @@ require 'term_canvas/base_screen'
3
3
  require 'term_canvas/object'
4
4
  require 'term_canvas/text'
5
5
  require 'term_canvas/rect'
6
- class TermCanvas
7
- attr_accessor :width, :height
8
- # Create a convenient window.
9
- # @param x [Integer] Horizontal position of the window. From left to right.
10
- # @param y [Integer] Vertical position of the window. From top to bottom.
11
- # @param w [Integer] Width of the window.
12
- # @param h [Integer] Height of the window.
13
- def initialize(x:, y:, w:, h:)
14
- TermCanvas::BaseScreen.instance
15
- @win = Curses::Window.new(h, w, y, x)
16
- @x = x
17
- @y = y
18
- @width = w
19
- @height = h
20
- @objects = []
21
- @object_index = 0
6
+
7
+ module TermCanvas
8
+ # Get key input.
9
+ # @return [String] Inputted key.
10
+ # @return [nil]
11
+ def self.gets
12
+ Curses.getch
22
13
  end
23
14
 
24
- class << self
25
- # Get key input.
26
- # @return [String] Inputted key.
27
- # @return [nil]
28
- def gets
29
- Curses.getch
30
- end
15
+ # Close.
16
+ def self.close
17
+ Curses.close_screen
18
+ end
31
19
 
32
- # Close.
33
- def close
34
- Curses.close_screen
20
+ class Canvas
21
+ attr_accessor :width, :height
22
+ # Create a convenient window.
23
+ # @param x [Integer] Horizontal position of the window. From left to right.
24
+ # @param y [Integer] Vertical position of the window. From top to bottom.
25
+ # @param w [Integer] Width of the window.
26
+ # @param h [Integer] Height of the window.
27
+ def initialize(x:, y:, w:, h:)
28
+ TermCanvas::BaseScreen.instance
29
+ @win = Curses::Window.new(h, w, y, x)
30
+ @x = x
31
+ @y = y
32
+ @width = w
33
+ @height = h
34
+ @objects = []
35
+ @object_index = 0
35
36
  end
36
- end
37
37
 
38
- # Clear objects and remove from the window.
39
- def clear
40
- @win.clear
41
- @objects = []
42
- @object_index = 0
43
- end
38
+ # Clear objects and remove from the window.
39
+ def clear
40
+ @win.clear
41
+ @objects = []
42
+ @object_index = 0
43
+ end
44
44
 
45
- # @return [Integer] Horizontal center of the window.
46
- def centerx
47
- @win.width / 2 + @win.width % 2
48
- end
45
+ # @return [Integer] Horizontal center of the window.
46
+ def centerx
47
+ @win.width / 2 + @win.width % 2
48
+ end
49
49
 
50
- # @return [Integer] Vertical center of the window.
51
- def centery
52
- @win.height / 2 + @win.height % 2
53
- end
50
+ # @return [Integer] Vertical center of the window.
51
+ def centery
52
+ @win.height / 2 + @win.height % 2
53
+ end
54
54
 
55
- # Add text object to the window but not display.
56
- # @param object [Text] Text instance
57
- def text(object)
58
- raise 'The argument must be Text' if !(TermCanvas::Text === object)
59
- object.set_index(@object_index)
60
- @objects << object
61
- @object_index += 1
62
- end
55
+ # Add text object to the window but not display.
56
+ # @param object [Text] Text instance
57
+ def text(object)
58
+ raise 'The argument must be Text' if !(TermCanvas::Text === object)
59
+ object.set_index(@object_index)
60
+ @objects << object
61
+ @object_index += 1
62
+ end
63
63
 
64
- # Add rect object to the window but not display.
65
- def rect(object)
66
- raise 'The argument must be Rect' if !(TermCanvas::Rect === object)
67
- object.set_index(@object_index)
68
- @objects << object
69
- @object_index += 1
70
- end
64
+ # Add rect object to the window but not display.
65
+ def rect(object)
66
+ raise 'The argument must be Rect' if !(TermCanvas::Rect === object)
67
+ object.set_index(@object_index)
68
+ @objects << object
69
+ @object_index += 1
70
+ end
71
71
 
72
- # Display objects that are added into this instance.
73
- def update
74
- draw
75
- @win.refresh
76
- end
72
+ # Display objects that are added into this instance.
73
+ def update
74
+ draw
75
+ @win.refresh
76
+ end
77
77
 
78
- def close
79
- @win.close
80
- end
78
+ def close
79
+ @win.close
80
+ end
81
81
 
82
- private
82
+ private
83
83
 
84
- def draw
85
- @objects.each do |object|
86
- object.draw(@win)
84
+ def draw
85
+ @objects.each do |object|
86
+ object.draw(@win)
87
+ end
87
88
  end
88
- end
89
+ end
89
90
  end
@@ -1,3 +1,3 @@
1
1
  module TermCanvas
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: term_canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kthatoto