term_canvas 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/_examples/test.rb +3 -3
- data/lib/term_canvas.rb +70 -69
- data/lib/term_canvas/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c4251fea2c58b06ee6abcd500cc3989b9b69b0b9b3f9f61d487606069395896
|
4
|
+
data.tar.gz: 2e5f06c64d6d194c91ee33946c41d0f8fc624e46e8cdd942b691d96250ed5b2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d3b6d8b5a5f85c74c538328390c84cbb79d2de7c37fde7b5f7d03a95e4cdd10226e0d4a7499d45acaba7131afafc34f21f5cb43cdc098249ee778dee0191f7a
|
7
|
+
data.tar.gz: 576234dab5b4cca43477efe33db2462ac5b49340310d3a9723f5248a1418ff8edbd4ecf23ad05912657ec924957454a3b5c654254ce6a070a6a33838f43f26f4
|
data/Gemfile.lock
CHANGED
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
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
# @
|
10
|
-
# @
|
11
|
-
|
12
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def gets
|
29
|
-
Curses.getch
|
30
|
-
end
|
15
|
+
# Close.
|
16
|
+
def self.close
|
17
|
+
Curses.close_screen
|
18
|
+
end
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
# @return [Integer] Horizontal center of the window.
|
46
|
+
def centerx
|
47
|
+
@win.width / 2 + @win.width % 2
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
# @return [Integer] Vertical center of the window.
|
51
|
+
def centery
|
52
|
+
@win.height / 2 + @win.height % 2
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
# Display objects that are added into this instance.
|
73
|
+
def update
|
74
|
+
draw
|
75
|
+
@win.refresh
|
76
|
+
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
def close
|
79
|
+
@win.close
|
80
|
+
end
|
81
81
|
|
82
|
-
|
82
|
+
private
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
def draw
|
85
|
+
@objects.each do |object|
|
86
|
+
object.draw(@win)
|
87
|
+
end
|
87
88
|
end
|
88
|
-
|
89
|
+
end
|
89
90
|
end
|
data/lib/term_canvas/version.rb
CHANGED