tagen 0.1.0
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.
- data/.gitignore +2 -0
- data/.yardopts +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +24 -0
- data/README.md +60 -0
- data/Rakefile +9 -0
- data/docs/Architecture.md +17 -0
- data/docs/CoreExtensions.md +56 -0
- data/docs/ExtraExtensions.md +20 -0
- data/lib/tagen/audioinfo.rb +21 -0
- data/lib/tagen/cairo.rb +809 -0
- data/lib/tagen/core.rb +34 -0
- data/lib/tagen/core/array.rb +41 -0
- data/lib/tagen/core/array/extract_options.rb +40 -0
- data/lib/tagen/core/hash.rb +17 -0
- data/lib/tagen/core/io.rb +29 -0
- data/lib/tagen/core/kernel.rb +73 -0
- data/lib/tagen/core/marshal.rb +34 -0
- data/lib/tagen/core/module.rb +25 -0
- data/lib/tagen/core/numeric.rb +10 -0
- data/lib/tagen/core/object.rb +21 -0
- data/lib/tagen/core/pa.rb +187 -0
- data/lib/tagen/core/pa/cmd.rb +374 -0
- data/lib/tagen/core/pa/dir.rb +144 -0
- data/lib/tagen/core/pa/path.rb +190 -0
- data/lib/tagen/core/pa/state.rb +56 -0
- data/lib/tagen/core/process.rb +11 -0
- data/lib/tagen/core/re.rb +8 -0
- data/lib/tagen/core/string.rb +43 -0
- data/lib/tagen/core/string/pyformat.rb +322 -0
- data/lib/tagen/core/time.rb +8 -0
- data/lib/tagen/gdk_pixbuf2.rb +26 -0
- data/lib/tagen/gtk2.rb +122 -0
- data/lib/tagen/magick.rb +23 -0
- data/lib/tagen/ncurses.rb +245 -0
- data/lib/tagen/net/http.rb +34 -0
- data/lib/tagen/pathname.rb +8 -0
- data/lib/tagen/poppler.rb +47 -0
- data/lib/tagen/socket.rb +20 -0
- data/lib/tagen/tree.rb +75 -0
- data/lib/tagen/vim.rb +19 -0
- data/lib/tagen/xmpp4r.rb +1 -0
- data/lib/tagen/xmpp4r/roster.rb +20 -0
- data/spec/cairo_spec.rb +137 -0
- data/spec/core/pa/cmd_spec.rb +251 -0
- data/spec/core/pa/dir_spec.rb +59 -0
- data/spec/core/string/pyformat_spec.rb +86 -0
- data/spec/spec_helper.rb +0 -0
- data/tagen.gemspec +20 -0
- data/version.rb +7 -0
- metadata +117 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
module Gdk
|
2
|
+
class Pixbuf
|
3
|
+
# get width, height
|
4
|
+
#
|
5
|
+
# @return [Array] [width, height]
|
6
|
+
def wh; [width.to_f, height.to_f] end
|
7
|
+
|
8
|
+
# get width
|
9
|
+
#
|
10
|
+
# @return [Float] width
|
11
|
+
def w; wh[0] end
|
12
|
+
|
13
|
+
# get height
|
14
|
+
#
|
15
|
+
# @return [Float] height
|
16
|
+
def h; wh[1] end
|
17
|
+
|
18
|
+
# set width, height
|
19
|
+
#
|
20
|
+
# @param [Array] wh [width, height]
|
21
|
+
def wh=(wh) width=wh[0]; height=wh[1] end
|
22
|
+
|
23
|
+
alias w= width=
|
24
|
+
alias h= height=
|
25
|
+
end
|
26
|
+
end
|
data/lib/tagen/gtk2.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require "cairo"
|
2
|
+
require_relative "cairo"
|
3
|
+
require "gtkhtml2"
|
4
|
+
|
5
|
+
module Gtk
|
6
|
+
|
7
|
+
class Window
|
8
|
+
# alias from set_default_size
|
9
|
+
def default_size=(wh)
|
10
|
+
set_default_size(*wh)
|
11
|
+
end
|
12
|
+
end # class Window
|
13
|
+
|
14
|
+
class ListStore
|
15
|
+
alias append_ append
|
16
|
+
# @example
|
17
|
+
# data=[
|
18
|
+
# [1, 2],
|
19
|
+
# [3, 4]
|
20
|
+
# ]
|
21
|
+
# liststore.append(data)
|
22
|
+
def append rows
|
23
|
+
rows.each do |row|
|
24
|
+
iter = append_
|
25
|
+
row.each do |col, col_i|
|
26
|
+
iter[col_i] = col
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end # class ListStore
|
31
|
+
|
32
|
+
=begin
|
33
|
+
Addition Methods list
|
34
|
+
---------------------
|
35
|
+
* \#add _alias from add\_widget_
|
36
|
+
=end
|
37
|
+
class SizeGroup
|
38
|
+
alias initialize_ initialize
|
39
|
+
# add mode=HORIZONTAL as default option
|
40
|
+
def _initialize(mode=HORIZONTAL)
|
41
|
+
initialize_(mode)
|
42
|
+
end
|
43
|
+
alias add add_widget
|
44
|
+
end # class SizeGroup
|
45
|
+
|
46
|
+
class PrintOperation
|
47
|
+
alias initialize_ initialize
|
48
|
+
# add @ispreview instance variable
|
49
|
+
def initialize
|
50
|
+
initialize_
|
51
|
+
|
52
|
+
@ispreview = false
|
53
|
+
signal_connect("ready") do |previewop, ctx|
|
54
|
+
@ispreview = true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def preview?; @ispreview end
|
59
|
+
|
60
|
+
alias run_ run
|
61
|
+
def run(action=:print_dialog, parent=nil, &blk)
|
62
|
+
action = PrintOperation.const_get("ACTION_#{action}".upcase)
|
63
|
+
if blk
|
64
|
+
run_(action, parent){|result|
|
65
|
+
blk.call self,result.nick.gsub(/-/, "_").to_sym
|
66
|
+
}
|
67
|
+
else
|
68
|
+
run_(action, parent)
|
69
|
+
end
|
70
|
+
end # def run
|
71
|
+
|
72
|
+
alias status_ status
|
73
|
+
# return symbol.
|
74
|
+
def status
|
75
|
+
status_.nick.gsub(/-/,"_").to_sym
|
76
|
+
end # def status
|
77
|
+
|
78
|
+
end # class PrintOperation
|
79
|
+
|
80
|
+
class Entry
|
81
|
+
alias text_ text
|
82
|
+
|
83
|
+
# default encoding is ASCII-8BIT, some error occurs.
|
84
|
+
# change to text.force_encoding("UTF-8")
|
85
|
+
def text
|
86
|
+
text_.force_encoding "UTF-8"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end # module Gtk
|
91
|
+
|
92
|
+
module Gdk
|
93
|
+
|
94
|
+
class EventKey
|
95
|
+
# return {Gdk::Key} instance
|
96
|
+
def key
|
97
|
+
Key.new keyval
|
98
|
+
end
|
99
|
+
|
100
|
+
end # class EventKey
|
101
|
+
|
102
|
+
class Key
|
103
|
+
attr_reader :code, :name
|
104
|
+
def initialize keyval
|
105
|
+
@code = keyval
|
106
|
+
@name = Keyval.to_name(keyval).downcase.to_sym
|
107
|
+
end
|
108
|
+
|
109
|
+
def ==(key)
|
110
|
+
case key
|
111
|
+
when Integer
|
112
|
+
@code == key
|
113
|
+
when String,Symbol
|
114
|
+
@name == key.to_sym
|
115
|
+
end
|
116
|
+
end # def ==
|
117
|
+
|
118
|
+
def inspect; @name end
|
119
|
+
|
120
|
+
end # class Key
|
121
|
+
end # module Gdk
|
122
|
+
|
data/lib/tagen/magick.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
=begin
|
2
|
+
* **gem**: rmagic
|
3
|
+
=end
|
4
|
+
module Magick
|
5
|
+
|
6
|
+
=begin
|
7
|
+
Method list
|
8
|
+
-----------
|
9
|
+
* \#width _alias from columns_
|
10
|
+
* \#height _alias from rows_
|
11
|
+
=end
|
12
|
+
class Image
|
13
|
+
|
14
|
+
alias width columns
|
15
|
+
alias height rows
|
16
|
+
|
17
|
+
# get width height
|
18
|
+
#
|
19
|
+
# @return [Array] [width, height]
|
20
|
+
def wh; [columns, rows] end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Ncurses
|
4
|
+
@stdscr @curscr @newscr
|
5
|
+
@windows_hash
|
6
|
+
.
|
7
|
+
move(y,x) #stdscr
|
8
|
+
wmove(win, y,x)
|
9
|
+
|
10
|
+
== extensions
|
11
|
+
|
12
|
+
class MEVENT; end
|
13
|
+
|
14
|
+
class SCREEN; end
|
15
|
+
|
16
|
+
module Panel
|
17
|
+
class PANEL; end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Form
|
21
|
+
class FORM; end
|
22
|
+
class FIELD; end
|
23
|
+
class FIELDTYPE; end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Menu
|
27
|
+
class MENU; end
|
28
|
+
class ITEM; end
|
29
|
+
end
|
30
|
+
|
31
|
+
=end
|
32
|
+
|
33
|
+
=begin
|
34
|
+
* **Install**: gem(rbcurse)
|
35
|
+
=end
|
36
|
+
module Ncurses
|
37
|
+
|
38
|
+
# a convient function.
|
39
|
+
#
|
40
|
+
# setup initscr cbreak nonl noecho
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# new do |stdsrc|
|
44
|
+
# ..
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
def self.new &blk
|
48
|
+
begin
|
49
|
+
initscr
|
50
|
+
cbreak
|
51
|
+
nonl
|
52
|
+
noecho
|
53
|
+
|
54
|
+
stdscr.intrflush(false)
|
55
|
+
stdscr.keypad(true)
|
56
|
+
|
57
|
+
blk.call stdscr if blk
|
58
|
+
ensure
|
59
|
+
self.end if blk
|
60
|
+
end
|
61
|
+
stdscr
|
62
|
+
end
|
63
|
+
|
64
|
+
# end ncurses
|
65
|
+
#
|
66
|
+
# call echo nocbreak nl endwin
|
67
|
+
#
|
68
|
+
# @see self.new
|
69
|
+
def self.end
|
70
|
+
echo
|
71
|
+
nocbreak
|
72
|
+
nl
|
73
|
+
endwin
|
74
|
+
end
|
75
|
+
|
76
|
+
end # module Ncurses
|
77
|
+
|
78
|
+
module Ncurses # Key
|
79
|
+
class Key
|
80
|
+
include Comparable
|
81
|
+
@@keys = {}
|
82
|
+
keys = String.letters.to_a + String.digits.to_a + \
|
83
|
+
%w(` ~ ! @ # $ % ^ & * ( ) - _ = + \ | [ ] { } : " ' ; < . > / ? ,)
|
84
|
+
keys.each do |v|
|
85
|
+
@@keys[v] = v.ascii
|
86
|
+
end
|
87
|
+
@@codes = @@keys.invert
|
88
|
+
|
89
|
+
attr_reader :key, :code
|
90
|
+
|
91
|
+
def initialize(arg)
|
92
|
+
# arg: int or str
|
93
|
+
if arg.class == Fixnum
|
94
|
+
@code = arg
|
95
|
+
@key = @@codes[arg]
|
96
|
+
elsif arg.class == String
|
97
|
+
@key = arg
|
98
|
+
@code = @@keys[arg]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def keys; @@keys end
|
103
|
+
def codes; @@codes end
|
104
|
+
|
105
|
+
def <=>(arg)
|
106
|
+
if arg.class == self.class
|
107
|
+
code <=> arg.code
|
108
|
+
elsif arg.class == Fixnum
|
109
|
+
code <=> arg
|
110
|
+
elsif arg.class == String
|
111
|
+
code <=> @@keys[arg]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_s; "#{@key}: #{@code}" end
|
116
|
+
|
117
|
+
end # class Key
|
118
|
+
end
|
119
|
+
|
120
|
+
module Ncurses # WINDOW
|
121
|
+
class WINDOW
|
122
|
+
def initialize
|
123
|
+
@stdscr = Ncurses.stdscr
|
124
|
+
@curscr = Ncurses.curscr
|
125
|
+
end
|
126
|
+
|
127
|
+
# xy mvxy wh ..
|
128
|
+
def xy
|
129
|
+
y,x=[],[]
|
130
|
+
Ncurses.getyx(self,y,x)
|
131
|
+
[x[0], y[0]]
|
132
|
+
end
|
133
|
+
def x; xy[0] end
|
134
|
+
def y; xy[1] end
|
135
|
+
|
136
|
+
def save; @save_xy = xy end
|
137
|
+
def restore; xy *@save_xy end
|
138
|
+
|
139
|
+
def mvxy x,y, &blk
|
140
|
+
x,y = convert_xy(x,y)
|
141
|
+
x_, y_ = self.xy
|
142
|
+
Ncurses.move(y,x)
|
143
|
+
if blk
|
144
|
+
blk.call
|
145
|
+
Ncurses.move(y_, x_)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def mvx x, &blk; mvxy(x, self.y) end
|
150
|
+
def mvy y, &blk; mvxy(self.x, y) end
|
151
|
+
|
152
|
+
def rmvxy x,y, &blk; mvxy(x.to_s, y.to_s, &blk) end
|
153
|
+
def rmvx x, &blk; mvx(x.to_s, &blk) end
|
154
|
+
def rmvy y, &blk; mvy(y.to_s, &blk) end
|
155
|
+
|
156
|
+
def wh
|
157
|
+
y,x=[],[]
|
158
|
+
Ncurses.getmaxyx(self,y,x)
|
159
|
+
[x, y]
|
160
|
+
end
|
161
|
+
def w; wh[0] end
|
162
|
+
def h; wh[1] end
|
163
|
+
|
164
|
+
def beginxy
|
165
|
+
y,x=[],[]
|
166
|
+
Ncurses.getbegyx(self,y,x)
|
167
|
+
[x,y]
|
168
|
+
end
|
169
|
+
def beginx; beginxy[0] end
|
170
|
+
def beginy; beginxy[1] end
|
171
|
+
|
172
|
+
def convert_xy x=nil,y=nil
|
173
|
+
x = self.x+x.to_i if x and String===x
|
174
|
+
y = self.y+y.to_i if y and String===y
|
175
|
+
|
176
|
+
if x and y
|
177
|
+
[x,y]
|
178
|
+
elsif x
|
179
|
+
x
|
180
|
+
elsif y
|
181
|
+
y
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# getc
|
186
|
+
# ctrl_a "\C-a"
|
187
|
+
# alt_a "\ea"
|
188
|
+
# ctrl_alt_a "\e\C-a"
|
189
|
+
# KEYS #{{{2
|
190
|
+
keys = {}
|
191
|
+
Ncurses.constants.grep(/^KEY_/).each do |const|
|
192
|
+
value = Ncurses.get_const const
|
193
|
+
key = const[/^KEY_(.*)/, 1]
|
194
|
+
keys[value] = key.downcase.to_sym
|
195
|
+
end
|
196
|
+
keys += {
|
197
|
+
127 => :backspace,
|
198
|
+
[27, 127] => :alt_backspace,
|
199
|
+
|
200
|
+
289 => :ctrl_f1, # :f25
|
201
|
+
290 => :ctrl_f2,
|
202
|
+
291 => :ctrl_f3,
|
203
|
+
292 => :ctrl_f4,
|
204
|
+
293 => :ctrl_f5,
|
205
|
+
294 => :ctrl_f6,
|
206
|
+
295 => :ctrl_f7,
|
207
|
+
296 => :ctrl_f8,
|
208
|
+
297 => :ctrl_f9,
|
209
|
+
298 => :ctrl_f1,
|
210
|
+
299 => :ctrl_f11,
|
211
|
+
300 => :ctrl_f12,
|
212
|
+
|
213
|
+
313 => :alt_f1,
|
214
|
+
314 => :alt_f2,
|
215
|
+
315 => :alt_f3,
|
216
|
+
316 => :alt_f4,
|
217
|
+
317 => :alt_f5,
|
218
|
+
318 => :alt_f6,
|
219
|
+
319 => :alt_f7,
|
220
|
+
320 => :alt_f8,
|
221
|
+
321 => :alt_f9,
|
222
|
+
322 => :alt_f10,
|
223
|
+
323 => :alt_f11,
|
224
|
+
324 => :alt_f12,
|
225
|
+
}
|
226
|
+
KEYS = keys
|
227
|
+
|
228
|
+
def getc
|
229
|
+
key = getch
|
230
|
+
if key==27
|
231
|
+
c = getch
|
232
|
+
(value=KEYS[[27, c]]) ? value : "\e"+c.chr
|
233
|
+
elsif value=KEYS[key]
|
234
|
+
value
|
235
|
+
else
|
236
|
+
# a "\C-a"
|
237
|
+
key.chr
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def necho(*args); Ncurses.addstr(args.gach{|v|v.to_s}.join(" ")) end
|
242
|
+
def echo *args; necho *args, "\n" end
|
243
|
+
|
244
|
+
end # class WINDOW
|
245
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Net
|
2
|
+
class HTTP
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# support params
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# get1("http://www.google.com/search", "&q=foo")
|
9
|
+
# get1("http://www.google.com/search", {"q" => "foo"} )
|
10
|
+
#
|
11
|
+
# @param [String Hash] params Hash by URI.encoding_www_form
|
12
|
+
def get1 path, params, initheader={}, &blk
|
13
|
+
path = path + "?" + (String===params ? params : URI.encode_www_form(params))
|
14
|
+
req = Get.new(path, initheader)
|
15
|
+
request req, &blk
|
16
|
+
end
|
17
|
+
|
18
|
+
# support params
|
19
|
+
#
|
20
|
+
# @see get1
|
21
|
+
def post1 path, params, initheader={}, &blk
|
22
|
+
req = Post.new(path, initheader)
|
23
|
+
if String===params
|
24
|
+
req.body = params
|
25
|
+
req.content_type = 'application/x-www-form-urlencoded'
|
26
|
+
else
|
27
|
+
req.set_form_data(params)
|
28
|
+
end
|
29
|
+
request req, &blk
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|