cursesx 002 → 003

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
File without changes
@@ -5,9 +5,12 @@ module CursesX
5
5
  end
6
6
 
7
7
  module Curses
8
+ module_function
9
+
8
10
  alias :standout_orig :standout
9
11
  alias :standend_orig :standend
10
12
 
13
+ # Standout within the block.
11
14
  def standout
12
15
  if block_given?
13
16
  standout_orig
@@ -18,6 +21,7 @@ module Curses
18
21
  end
19
22
  end
20
23
 
24
+ # Standend within the block.
21
25
  def standend
22
26
  if block_given?
23
27
  standend_orig
@@ -31,39 +35,83 @@ module Curses
31
35
  alias :echo_orig :echo
32
36
  alias :noecho_orig :noecho
33
37
 
38
+ module_function :echo_orig, :noecho_orig
39
+
40
+ # Echo within the block.
34
41
  def echo
35
42
  if block_given?
36
43
  echo_orig
37
- yield
44
+ res = yield
38
45
  noecho_orig
46
+ return res
39
47
  else
40
48
  echo_orig
41
49
  end
42
50
  end
43
51
 
52
+ # Noecho within the block.
44
53
  def noecho
45
54
  if block_given?
46
55
  noecho_orig
47
- yield
56
+ res = yield
48
57
  echo_orig
58
+ return res
49
59
  else
50
60
  noecho_orig
51
61
  end
52
62
  end
53
63
 
64
+ def define_color(name, fg, bg)
65
+ @@color ||= Hash.new
66
+ val = @@color.values.sort.last || 0
67
+ @@color[name] = val + 1
68
+ fg = color_of(fg) if fg.kind_of?(Symbol)
69
+ bg = color_of(bg) if bg.kind_of?(Symbol)
70
+ init_pair(@@color[name], fg, bg)
71
+ end
72
+
73
+ def color(name)
74
+ color_pair(@@color[name])
75
+ end
76
+
77
+ # Symbol to color.
78
+ def color_of(name)
79
+ case name
80
+ when :black; COLOR_BLACK
81
+ when :red; COLOR_RED
82
+ when :green; COLOR_GREEN
83
+ when :yellow; COLOR_YELLOW
84
+ when :blue; COLOR_BLUE
85
+ when :magenta; COLOR_MAGENTA
86
+ when :cyan; COLOR_CYAN
87
+ when :white; COLOR_WHITE
88
+ else raise ArgumentError, name
89
+ end
90
+ end
91
+
92
+ private :color_of
93
+
54
94
  class Window
55
- attr_reader :children
95
+ attr_reader :__children__
96
+ attr_accessor :__parent__
97
+ alias :children :__children__
98
+ alias :parent :__parent__
99
+ alias :parent= :__parent__=
56
100
 
57
101
  alias :subwin_orig :subwin
58
- def subwin(height, width, y, x)
59
- @children ||= []
60
- @children << subwin_orig(height, width, y, x)
61
- return @children.last
102
+ def subwin(height, width, y, x, mod = nil)
103
+ @__children__ ||= []
104
+ win = subwin_orig(height, width, y, x)
105
+ win.parent = self
106
+ win.extend mod if mod
107
+ @__children__ << win
108
+ return win
62
109
  end
63
110
 
64
111
  alias :standout_orig :standout
65
112
  alias :standend_orig :standend
66
113
 
114
+ # Standout within the block.
67
115
  def standout
68
116
  if block_given?
69
117
  standout_orig
@@ -74,6 +122,7 @@ module Curses
74
122
  end
75
123
  end
76
124
 
125
+ # Standend within the block.
77
126
  def standend
78
127
  if block_given?
79
128
  standend_orig
@@ -83,5 +132,34 @@ module Curses
83
132
  standend_orig
84
133
  end
85
134
  end
135
+
136
+ # Echo within the block.
137
+ def echo
138
+ if block_given?
139
+ Curses.echo
140
+ res = yield
141
+ Curses.noecho
142
+ return res
143
+ else
144
+ Curses.echo
145
+ end
146
+ end
147
+
148
+ # Noecho within the block.
149
+ def noecho
150
+ if block_given?
151
+ Curses.noecho
152
+ res = yield
153
+ Curses.echo
154
+ return res
155
+ else
156
+ Curses.noecho
157
+ end
158
+ end
159
+
160
+ # Draw the window.
161
+ def draw; warning "Not implemented"; end
162
+
163
+ def color(name); Curses.color(name); end
86
164
  end
87
165
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cursesx
3
3
  version: !ruby/object:Gem::Version
4
- version: "002"
4
+ version: "003"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Yamaguchi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-16 00:00:00 +09:00
12
+ date: 2008-07-27 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,11 +22,9 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - .gemified
26
- - History.txt
27
- - License.txt
28
- - README.txt
29
- - Rakefile
25
+ - History.rdoc
26
+ - LICENSE
27
+ - README.rdoc
30
28
  - lib/cursesx.rb
31
29
  has_rdoc: true
32
30
  homepage: http://rubyforge.org/projects/cursesx/
@@ -50,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
48
  requirements: []
51
49
 
52
50
  rubyforge_project: cursesx
53
- rubygems_version: 1.1.1
51
+ rubygems_version: 1.2.0
54
52
  signing_key:
55
53
  specification_version: 2
56
54
  summary: cursesx is an useful extension of standard curses.rb.
data/.gemified DELETED
@@ -1,9 +0,0 @@
1
- ---
2
- :summary: cursesx is an useful extension of standard curses.rb.
3
- :email: keita.yamaguchi@gmail.com
4
- :name: cursesx
5
- :has_rdoc: true
6
- :homepage: http://rubyforge.org/projects/cursesx/
7
- :version: "002"
8
- :rubyforge_project: cursesx
9
- :author: Keita Yamaguchi
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
2
-
3
- require "rubygems"
4
- require "cursesx"
5
- require "rtask"
6
-
7
- RTask.new(:use => :all, :version => CursesX::VERSION)