kang 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/kang +1 -1
- data/lib/kang/cli.rb +1 -1
- data/lib/kang/version.rb +3 -0
- data/lib/kang.rb +190 -85
- metadata +29 -58
- data/History.txt +0 -4
- data/Manifest.txt +0 -9
- data/README.txt +0 -36
- data/Rakefile +0 -28
- data/test/test_helper.rb +0 -3
- data/test/test_kang.rb +0 -11
- data/test/test_kang_cli.rb +0 -14
data/bin/kang
CHANGED
data/lib/kang/cli.rb
CHANGED
data/lib/kang/version.rb
ADDED
data/lib/kang.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# kang.rb - Main executable for GUI interface
|
5
5
|
#
|
6
6
|
# ====================================================================
|
7
|
-
# Copyright (c)
|
7
|
+
# Copyright (c) 2011 Tony Doan <tdoan@tdoan.com>. All rights reserved.
|
8
8
|
#
|
9
9
|
# This software is licensed as described in the file COPYING, which
|
10
10
|
# you should have received as part of this distribution. The terms
|
@@ -14,102 +14,207 @@
|
|
14
14
|
# ====================================================================
|
15
15
|
#
|
16
16
|
$:.unshift(File.dirname(__FILE__)) unless
|
17
|
-
|
17
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
begin
|
20
|
+
require 'gtk2'
|
21
|
+
rescue LoadError => ex
|
22
|
+
$stderr.puts("This is a GUI application that requires the gtk2 gem be installed, which in turn requires that GTK2 be installed.")
|
23
|
+
exit(-1)
|
24
|
+
end
|
21
25
|
|
22
26
|
module Kang
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
27
|
+
class Data
|
28
|
+
def initialize
|
29
|
+
@re = nil
|
30
|
+
@match = nil
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
grid.add(lssizer,1,Wx::EXPAND)
|
60
|
-
supersizer.add(grid,1,Wx::EXPAND)
|
61
|
-
supersizer.add(@status)
|
62
|
-
self.set_sizer(supersizer)
|
63
|
-
evt_text(@text.get_id){|event| text_change(event)}
|
64
|
-
evt_text(@text2.get_id){|event| text_change(event)}
|
65
|
-
text_change(nil)
|
66
|
-
end
|
33
|
+
def update_match_string(match_string)
|
34
|
+
@match_string = match_string
|
35
|
+
update_match
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_match
|
39
|
+
if @re
|
40
|
+
@match = @re.match(@match_string)
|
41
|
+
else
|
42
|
+
@match = nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def match_group_count
|
47
|
+
if @match
|
48
|
+
@match.to_a.size-1
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_regexp(re_string)
|
55
|
+
begin
|
56
|
+
@re = Regexp.new(re_string)
|
57
|
+
rescue RegexpError
|
58
|
+
@re = nil
|
59
|
+
end
|
60
|
+
update_match
|
61
|
+
end
|
67
62
|
|
68
|
-
|
69
|
-
|
63
|
+
def regexp_valid?
|
64
|
+
@re.nil? ? false : true
|
65
|
+
end
|
66
|
+
|
67
|
+
def match?
|
68
|
+
@match ? true : false
|
69
|
+
end
|
70
|
+
|
71
|
+
def match_begin
|
72
|
+
if @match
|
73
|
+
@match.begin(0)
|
74
|
+
else
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def match_end
|
80
|
+
if @match
|
81
|
+
@match.end(0)
|
82
|
+
else
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def matches
|
88
|
+
if @match and (@match.length > 1)
|
89
|
+
@match[1..-1]
|
90
|
+
else
|
91
|
+
[]
|
92
|
+
end
|
93
|
+
end
|
70
94
|
end
|
71
95
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
@
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
+
class Controller
|
97
|
+
def initialize
|
98
|
+
@view = View.new(self)
|
99
|
+
@data = Data.new
|
100
|
+
@view.start
|
101
|
+
end
|
102
|
+
|
103
|
+
def key_up_match(view,event,match_string)
|
104
|
+
@view.update_status("")
|
105
|
+
@data.update_match_string(match_string)
|
106
|
+
key_up
|
107
|
+
end
|
108
|
+
|
109
|
+
def key_up_reg(view,event,text)
|
110
|
+
@view.update_status("")
|
111
|
+
@data.update_regexp(text)
|
112
|
+
key_up
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
def key_up
|
117
|
+
unless @data.regexp_valid?
|
118
|
+
@view.remove_tag
|
119
|
+
@view.update_status("Invalid Regexp")
|
96
120
|
else
|
97
|
-
|
98
|
-
@
|
99
|
-
@
|
121
|
+
count = @data.match_group_count ? @data.match_group_count : "no"
|
122
|
+
@view.update_status("Matched with #{@data.match_group_count} grouping(s)")
|
123
|
+
if @data.match?
|
124
|
+
@view.update_tag(@data.match_begin,@data.match_end)
|
125
|
+
else
|
126
|
+
@view.remove_tag
|
127
|
+
@view.update_status("no match")
|
128
|
+
end
|
100
129
|
end
|
101
|
-
|
102
|
-
ret = @text2.set_style(0,size,@normal)
|
103
|
-
@text2.append_text("")
|
130
|
+
@view.update_match_groups(@data.matches)
|
104
131
|
end
|
105
|
-
@text2.set_insertion_point(ip)
|
106
132
|
end
|
107
|
-
end
|
108
133
|
|
109
|
-
class
|
134
|
+
class View
|
135
|
+
def initialize(controller)
|
136
|
+
@controller = controller
|
137
|
+
@window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
|
138
|
+
@window.set_title "Kang"
|
139
|
+
@window.border_width = 10
|
140
|
+
@window.set_size_request(600, 400)
|
141
|
+
@window.signal_connect('delete_event') { Gtk.main_quit }
|
142
|
+
|
143
|
+
wintop = Gtk::ScrolledWindow.new
|
144
|
+
wintop.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS)
|
145
|
+
|
146
|
+
winbottom = Gtk::ScrolledWindow.new
|
147
|
+
winbottom.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS)
|
148
|
+
|
149
|
+
@statusbar = Gtk::Statusbar.new
|
150
|
+
@statusbar.push(0,"")
|
151
|
+
|
152
|
+
@regview = Gtk::TextView.new
|
153
|
+
@regview.buffer.text = "RegExp here"
|
154
|
+
|
155
|
+
@matchview = Gtk::TextView.new
|
156
|
+
@matchview.buffer.text = "Match Text Here"
|
157
|
+
|
158
|
+
@matchview.buffer.create_tag("colors",{ "foreground" => "green", "background" => "#000000" })
|
159
|
+
|
160
|
+
wintop.add(@regview)
|
161
|
+
winbottom.add(@matchview)
|
110
162
|
|
111
|
-
|
112
|
-
|
163
|
+
@list_store = Gtk::ListStore.new(Integer, String)
|
164
|
+
treeview = Gtk::TreeView.new(@list_store)
|
165
|
+
column0 = Gtk::TreeViewColumn.new("#",Gtk::CellRendererText.new, {:text => 0})
|
166
|
+
column1 = Gtk::TreeViewColumn.new("Match",Gtk::CellRendererText.new, {:text => 1})
|
167
|
+
treeview.append_column(column0)
|
168
|
+
treeview.append_column(column1)
|
169
|
+
treeview.selection.mode = Gtk::SELECTION_NONE
|
170
|
+
|
171
|
+
vpaned = Gtk::VPaned.new
|
172
|
+
vpaned.add1(wintop)
|
173
|
+
vpaned.add2(winbottom)
|
174
|
+
vpaned.set_size_request(400,400)
|
175
|
+
hpaned = Gtk::HPaned.new
|
176
|
+
hpaned.add1(vpaned)
|
177
|
+
hpaned.add2(treeview)
|
178
|
+
vbox = Gtk::VBox.new(false,0)
|
179
|
+
vbox.pack_start(hpaned,true,true,0)
|
180
|
+
vbox.pack_start(@statusbar,false,false,0)
|
181
|
+
@window.add(vbox)
|
182
|
+
|
183
|
+
@regview.signal_connect("key-release-event") {|view,event| @controller.key_up_reg(view,event,view.buffer.text)}
|
184
|
+
@matchview.signal_connect("key-release-event") {|view,event| @controller.key_up_match(view,event,view.buffer.text)}
|
185
|
+
end
|
186
|
+
|
187
|
+
def start
|
188
|
+
@window.show_all
|
189
|
+
begin
|
190
|
+
Gtk.main
|
191
|
+
rescue SystemExit, Interrupt
|
192
|
+
exit(0)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def update_tag(tag_begin,tag_end)
|
197
|
+
remove_tag
|
198
|
+
b = @matchview.buffer.get_iter_at_offset(tag_begin)
|
199
|
+
e = @matchview.buffer.get_iter_at_offset(tag_end)
|
200
|
+
@matchview.buffer.apply_tag("colors",b,e)
|
201
|
+
end
|
202
|
+
|
203
|
+
def update_status(message)
|
204
|
+
@statusbar.pop(0)
|
205
|
+
@statusbar.push(0,message)
|
206
|
+
end
|
207
|
+
|
208
|
+
def update_match_groups(groups)
|
209
|
+
@list_store.clear
|
210
|
+
groups.each_with_index{|item,i| iter = @list_store.append; iter[0]=i;iter[1]=item}
|
211
|
+
end
|
212
|
+
|
213
|
+
def remove_tag
|
214
|
+
buffer = @matchview.buffer
|
215
|
+
bstart = buffer.get_iter_at_offset(0)
|
216
|
+
bend = buffer.get_iter_at_offset(buffer.text.size)
|
217
|
+
@matchview.buffer.remove_tag("colors",bstart,bend)
|
218
|
+
end
|
113
219
|
end
|
114
220
|
end
|
115
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Tony Doan
|
@@ -9,88 +10,58 @@ autorequire:
|
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
13
|
+
date: 2011-06-21 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.9.8
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: newgem
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.2.3
|
34
|
-
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: hoe
|
37
|
-
type: :development
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
name: gtk2
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
40
20
|
requirements:
|
41
21
|
- - ">="
|
42
22
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: The Ruby Regex Debugger. Put your regex in the top pane, and your match text in the bottom pane. Kang will highlight the match text that matches and show you any match groups you have created down the right hand side.
|
27
|
+
email: tdoan@tdoan.com
|
48
28
|
executables:
|
49
29
|
- kang
|
50
30
|
extensions: []
|
51
31
|
|
52
|
-
extra_rdoc_files:
|
53
|
-
|
54
|
-
- Manifest.txt
|
55
|
-
- README.txt
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
56
34
|
files:
|
57
|
-
- History.txt
|
58
|
-
- Manifest.txt
|
59
|
-
- README.txt
|
60
|
-
- Rakefile
|
61
|
-
- bin/kang
|
62
35
|
- lib/kang.rb
|
63
36
|
- lib/kang/cli.rb
|
64
|
-
-
|
65
|
-
-
|
66
|
-
|
67
|
-
|
37
|
+
- lib/kang/version.rb
|
38
|
+
- bin/kang
|
39
|
+
homepage: http://github.com/tdoan/kang
|
40
|
+
licenses: []
|
41
|
+
|
68
42
|
post_install_message:
|
69
|
-
rdoc_options:
|
70
|
-
|
71
|
-
- README.txt
|
43
|
+
rdoc_options: []
|
44
|
+
|
72
45
|
require_paths:
|
73
46
|
- lib
|
74
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
75
49
|
requirements:
|
76
50
|
- - ">="
|
77
51
|
- !ruby/object:Gem::Version
|
78
52
|
version: "0"
|
79
|
-
version:
|
80
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
81
55
|
requirements:
|
82
56
|
- - ">="
|
83
57
|
- !ruby/object:Gem::Version
|
84
58
|
version: "0"
|
85
|
-
version:
|
86
59
|
requirements: []
|
87
60
|
|
88
|
-
rubyforge_project:
|
89
|
-
rubygems_version: 1.
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.5
|
90
63
|
signing_key:
|
91
|
-
specification_version:
|
92
|
-
summary:
|
93
|
-
test_files:
|
94
|
-
|
95
|
-
- test/test_kang.rb
|
96
|
-
- test/test_kang_cli.rb
|
64
|
+
specification_version: 3
|
65
|
+
summary: A visual regex debugger
|
66
|
+
test_files: []
|
67
|
+
|
data/History.txt
DELETED
data/Manifest.txt
DELETED
data/README.txt
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
= kang
|
2
|
-
|
3
|
-
* http://kang.rubyforge.org/
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
* KANG - The Ruby Regex Debugger
|
8
|
-
|
9
|
-
== FEATURES/PROBLEMS:
|
10
|
-
|
11
|
-
* This is a cross-platform GUI application. To run it you'll need Ruby (I've only tested with 1.8.7 so far) and the wxruby gem (I've only tested with 1.9.8).
|
12
|
-
|
13
|
-
== SYNOPSIS:
|
14
|
-
|
15
|
-
FIX (code sample of usage)
|
16
|
-
|
17
|
-
== REQUIREMENTS:
|
18
|
-
|
19
|
-
* ruby
|
20
|
-
* rubygems
|
21
|
-
* wxruby
|
22
|
-
|
23
|
-
== INSTALL:
|
24
|
-
|
25
|
-
* sudo gem install kang
|
26
|
-
|
27
|
-
== LICENSE:
|
28
|
-
|
29
|
-
====================================================================
|
30
|
-
Copyright (c) 2008 Tony Doan <tdoan@tdoan.com>. All rights reserved.
|
31
|
-
This software is licensed as described in the file COPYING, which
|
32
|
-
you should have received as part of this distribution. The terms
|
33
|
-
are also available at http://github.com/tdoan/kang/tree/master/COPYING.
|
34
|
-
If newer versions of this license are posted there, you may use a
|
35
|
-
newer version instead, at your option.
|
36
|
-
====================================================================
|
data/Rakefile
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
-
require File.dirname(__FILE__) + '/lib/kang'
|
3
|
-
|
4
|
-
# Generate all the Rake tasks
|
5
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
-
$hoe = Hoe.new('kang', Kang::VERSION) do |p|
|
7
|
-
p.developer('Tony Doan', 'tdoan@tdoan.com')
|
8
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
-
#p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
-
p.rubyforge_name = p.name # TODO this is default value
|
11
|
-
p.extra_deps = [
|
12
|
-
['wxruby','>= 1.9.8'],
|
13
|
-
]
|
14
|
-
p.extra_dev_deps = [
|
15
|
-
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
-
]
|
17
|
-
|
18
|
-
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
-
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
-
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
-
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
-
end
|
23
|
-
|
24
|
-
require 'newgem/tasks' # load /tasks/*.rake
|
25
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
-
|
27
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
-
# task :default => [:spec, :features]
|
data/test/test_helper.rb
DELETED
data/test/test_kang.rb
DELETED
data/test/test_kang_cli.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
-
require 'kang/cli'
|
3
|
-
|
4
|
-
class TestKangCli < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
Kang::CLI.execute(@stdout_io = StringIO.new, [])
|
7
|
-
@stdout_io.rewind
|
8
|
-
@stdout = @stdout_io.read
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_not_print_default_output
|
12
|
-
assert_no_match(/To update this executable/, @stdout)
|
13
|
-
end
|
14
|
-
end
|