kang 0.1.0alpha.2 → 0.1.0alpha.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjdhMTUzMzVlOTVkYTdlYTkyOWZmNmNhYzZiYThjOWM0ZGVjZDk0MQ==
5
+ data.tar.gz: !binary |-
6
+ Y2Y2Y2YyNTc4ODhhZmEwNmQzM2NiOWQzYWFlZDg1NWNiYzVmOWMxNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MzgzYWU3NTBmYTFhMzU3Yjk5ODFjMWViMmU4NDQ5MWNhYTAxMGRiNDBlMDVm
10
+ MzVlM2Q5NDE5ZTJiZWNmYzEzNDc2MjRkYTRhNTNiNDkxN2JjYTEzOTVkNjlk
11
+ YWI4OGE2NzVkNDQ1OThmOWUwMDQ0OTMxZjAyMDFkOTQ3YmRhYjk=
12
+ data.tar.gz: !binary |-
13
+ ZjZkZTQ5OTI5Yjk4Njc4NDY1NTIzZTViNTA1MTAxNzZlY2JkMjU3MDY5N2Mw
14
+ NmFhNTFmYWViNTBmNWFmZWQyYjE5YWNlMjRkMzliNTNhMzMxZTI5OTg4MTA5
15
+ YjQ0ZWRjYmMwNDczMGZiNTQ4MWE5ZTFkNmRiNDEwMjJhODRkMmU=
data/bin/kang CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
3
  # Created on 2009-1-7.
4
- # Copyright (c) 2012. All rights reserved.
4
+ # Copyright (c) 2013. All rights reserved.
5
5
 
6
6
  require File.expand_path(File.dirname(__FILE__) + "/../lib/kang")
7
7
  require 'kang/cli'
data/lib/kang/cli.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # cli.rb - Main executable for GUI interface
3
3
  #
4
4
  # ====================================================================
5
- # Copyright (c) 2012 Tony Doan <tdoan@tdoan.com>. All rights reserved.
5
+ # Copyright (c) 2013 Tony Doan <tdoan@tdoan.com>. All rights reserved.
6
6
  #
7
7
  # This software is licensed as described in the file COPYING, which
8
8
  # you should have received as part of this distribution. The terms
@@ -0,0 +1,67 @@
1
+ class Colors
2
+ def initialize(initial_size=nil, options={})
3
+ valid_options = [:saturation,:value,:starting_hue,:range]
4
+ default_options = {saturation:0.3, value:0.8, :starting_hue=>rand, :range=>256}
5
+ options.keys.each do |k|
6
+ raise ArgumentError, "Unknown option: #{k}" unless valid_options.include? k
7
+ end
8
+ default_options.merge!(options)
9
+ [:saturation, :value, :starting_hue].each do |k|
10
+ raise ArgumentError, "The option \"#{k.to_s}\" must be between 0 and 1" if((default_options[k] > 1) or (default_options[k] < 0))
11
+ end
12
+ @golden_ratio_conjugate = 0.618033988749895
13
+ @h = default_options[:starting_hue]
14
+ @saturation = default_options[:saturation]
15
+ @value = default_options[:value]
16
+ @colors = []
17
+ @range = default_options[:range]
18
+ unless initial_size.nil?
19
+ initial_size.times do
20
+ self.next
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.to_hex(rgb)
26
+ rgb.collect{|n| n.to_s(16).upcase}.join
27
+ end
28
+
29
+ def hsv_to_rgb(h, s, v)
30
+ h_i = (h*6).to_i
31
+ f = h*6 - h_i
32
+ p = v * (1 - s)
33
+ q = v * (1 - f*s)
34
+ t = v * (1 - (1 - f) * s)
35
+ r, g, b = v, t, p if h_i==0
36
+ r, g, b = q, v, p if h_i==1
37
+ r, g, b = p, v, t if h_i==2
38
+ r, g, b = p, q, v if h_i==3
39
+ r, g, b = t, p, v if h_i==4
40
+ r, g, b = v, p, q if h_i==5
41
+ [(r*@range).to_i, (g*@range).to_i, (b*@range).to_i]
42
+ end
43
+
44
+ def each(&block)
45
+ @colors.each(&block)
46
+ end
47
+
48
+ def [](i)
49
+ if @colors.size-1 < i
50
+ diff = i - @colors.size + 1
51
+ puts "growing #{diff}"
52
+ (diff).times do
53
+ puts "."
54
+ self.next
55
+ end
56
+ end
57
+ @colors[i]
58
+ end
59
+
60
+ def next
61
+ @h += @golden_ratio_conjugate
62
+ @h %= 1
63
+ c = hsv_to_rgb(@h, @saturation, @value)
64
+ @colors << c
65
+ c
66
+ end
67
+ end
@@ -2,7 +2,7 @@
2
2
  # controller.rb - Main executable for GUI interface
3
3
  #
4
4
  # ====================================================================
5
- # Copyright (c) 2012 Tony Doan <tdoan@tdoan.com>. All rights reserved.
5
+ # Copyright (c) 2013 Tony Doan <tdoan@tdoan.com>. All rights reserved.
6
6
  #
7
7
  # This software is licensed as described in the file COPYING, which
8
8
  # you should have received as part of this distribution. The terms
data/lib/kang/data.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # data.rb - Main executable for GUI interface
3
3
  #
4
4
  # ====================================================================
5
- # Copyright (c) 2012 Tony Doan <tdoan@tdoan.com>. All rights reserved.
5
+ # Copyright (c) 2013 Tony Doan <tdoan@tdoan.com>. All rights reserved.
6
6
  #
7
7
  # This software is licensed as described in the file COPYING, which
8
8
  # you should have received as part of this distribution. The terms
@@ -86,17 +86,17 @@ module Kang
86
86
  @match ? true : false
87
87
  end
88
88
 
89
- def match_begin
89
+ def match_begin(group=0)
90
90
  if @match
91
- @match.begin(0)
91
+ @match.begin(group)
92
92
  else
93
93
  nil
94
94
  end
95
95
  end
96
96
 
97
- def match_end
97
+ def match_end(group=0)
98
98
  if @match
99
- @match.end(0)
99
+ @match.end(group)
100
100
  else
101
101
  nil
102
102
  end
@@ -2,7 +2,7 @@
2
2
  # offset_data.rb - Main executable for GUI interface
3
3
  #
4
4
  # ====================================================================
5
- # Copyright (c) 2012 Tony Doan <tdoan@tdoan.com>. All rights reserved.
5
+ # Copyright (c) 2013 Tony Doan <tdoan@tdoan.com>. All rights reserved.
6
6
  #
7
7
  # This software is licensed as described in the file COPYING, which
8
8
  # you should have received as part of this distribution. The terms
@@ -20,11 +20,19 @@ module Kang
20
20
  end
21
21
 
22
22
  def begin(i)
23
- @match_data.begin(i) + @offset
23
+ if @match_data.begin(i)
24
+ @match_data.begin(i) + @offset
25
+ else
26
+ @offset
27
+ end
24
28
  end
25
29
 
26
30
  def end(i)
27
- @match_data.end(i) + @offset
31
+ if @match_data.end(i)
32
+ @match_data.end(i) + @offset
33
+ else
34
+ @offset
35
+ end
28
36
  end
29
37
 
30
38
  def length
data/lib/kang/tags.rb ADDED
@@ -0,0 +1,29 @@
1
+ module Kang
2
+ class Tags
3
+ def initialize(view)
4
+ @view=view
5
+ @colors = Colors.new(5,range: 65545)
6
+ @tags = {}
7
+ end
8
+
9
+ def[](i)
10
+ tag = nil
11
+ begin
12
+ tag_name = "color#{i}"
13
+ tag = @tags.fetch(tag_name)
14
+ rescue KeyError
15
+ c = @colors[i]
16
+ puts c.inspect
17
+ color = Gdk::Color.new(*c)
18
+ puts color.to_s
19
+ tag = Gtk::TextTag.new(tag_name)
20
+ tag.foreground='black'
21
+ tag.background_gdk=color
22
+ @tags[tag_name] = tag
23
+ @view.buffer.tag_table.add(tag)
24
+ end
25
+ #@view.buffer.create_tag("colors",{ "foreground" => "green", "background" => "gray" })
26
+ tag
27
+ end
28
+ end
29
+ end
data/lib/kang/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # version.rb - Main executable for GUI interface
3
3
  #
4
4
  # ====================================================================
5
- # Copyright (c) 2012 Tony Doan <tdoan@tdoan.com>. All rights reserved.
5
+ # Copyright (c) 2013 Tony Doan <tdoan@tdoan.com>. All rights reserved.
6
6
  #
7
7
  # This software is licensed as described in the file COPYING, which
8
8
  # you should have received as part of this distribution. The terms
@@ -13,5 +13,5 @@
13
13
  #
14
14
 
15
15
  module Kang
16
- VERSION = "0.1.0alpha.2"
16
+ VERSION = "0.1.0alpha.3"
17
17
  end
data/lib/kang/view.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # view.rb - Main executable for GUI interface
3
3
  #
4
4
  # ====================================================================
5
- # Copyright (c) 2012 Tony Doan <tdoan@tdoan.com>. All rights reserved.
5
+ # Copyright (c) 2013 Tony Doan <tdoan@tdoan.com>. All rights reserved.
6
6
  #
7
7
  # This software is licensed as described in the file COPYING, which
8
8
  # you should have received as part of this distribution. The terms
@@ -42,8 +42,7 @@ module Kang
42
42
 
43
43
  @matchview = Gtk::TextView.new
44
44
  @matchview.buffer.text = match_text
45
-
46
- @matchview.buffer.create_tag("colors",{ "foreground" => "green", "background" => "gray" })
45
+ @tags = Tags.new(@matchview)
47
46
 
48
47
  wintop.add(@regview)
49
48
  wintop.set_size_request(400,100)
@@ -52,8 +51,12 @@ module Kang
52
51
 
53
52
  @list_store = Gtk::ListStore.new(String, String)
54
53
  treeview = Gtk::TreeView.new(@list_store)
55
- column0 = Gtk::TreeViewColumn.new("Match",Gtk::CellRendererText.new, {:text => 0})
56
- column1 = Gtk::TreeViewColumn.new("Match",Gtk::CellRendererText.new, {:text => 1})
54
+ renderer = Gtk::CellRendererText.new
55
+ column0 = Gtk::TreeViewColumn.new("#",renderer, {:text => 0})
56
+ column1 = Gtk::TreeViewColumn.new("Match",renderer, {:text => 1})
57
+ column1.set_cell_data_func(renderer) do |tvc,cell,model,iter|
58
+ cell.background_gdk = @tags[iter.path.to_str.to_i].background_gdk
59
+ end
57
60
  treeview.append_column(column0)
58
61
  treeview.append_column(column1)
59
62
  treeview.selection.mode = Gtk::SELECTION_NONE
@@ -104,12 +107,22 @@ module Kang
104
107
  private
105
108
  def update_tag
106
109
  remove_tag
107
- if @data.regex_valid?
108
- tag_begin = @data.match_begin
109
- tag_end = @data.match_end
110
+ if @data.match_group_count
111
+ @data.match_group_count.times do |i|
112
+ paint_tag(i)
113
+ end
114
+ else
115
+ paint_tag
116
+ end
117
+ end
118
+
119
+ def paint_tag(group=0)
120
+ if @data.regex_valid? and @data.match? and @data.match_begin(group)
121
+ tag_begin = @data.match_begin(group)
122
+ tag_end = @data.match_end(group)
110
123
  b = @matchview.buffer.get_iter_at_offset(tag_begin)
111
124
  e = @matchview.buffer.get_iter_at_offset(tag_end)
112
- @matchview.buffer.apply_tag("colors",b,e)
125
+ @matchview.buffer.apply_tag(@tags[group],b,e)
113
126
  end
114
127
  end
115
128
 
@@ -143,7 +156,7 @@ module Kang
143
156
  buffer = @matchview.buffer
144
157
  bstart = buffer.get_iter_at_offset(0)
145
158
  bend = buffer.get_iter_at_offset(buffer.text.size)
146
- @matchview.buffer.remove_tag("colors",bstart,bend)
159
+ @matchview.buffer.remove_all_tags(bstart,bend)
147
160
  end
148
161
 
149
162
  def update_spin_count
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) 2012 Tony Doan <tdoan@tdoan.com>. All rights reserved.
7
+ # Copyright (c) 2013 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
@@ -18,6 +18,8 @@ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname
18
18
  require "kang/controller"
19
19
  require "kang/view"
20
20
  require "kang/data"
21
+ require "kang/colors"
22
+ require "kang/tags"
21
23
  require "rubygems"
22
24
  begin
23
25
  require 'gtk2'
metadata CHANGED
@@ -1,32 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0alpha.2
5
- prerelease: 5
4
+ version: 0.1.0alpha.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tony Doan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-10 00:00:00.000000000 Z
11
+ date: 2013-04-26 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: glib2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: atk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.5
14
41
  - !ruby/object:Gem::Dependency
15
42
  name: gtk2
16
43
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
44
  requirements:
19
- - - ! '>='
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: pango
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.5
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: cairo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.12.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.12.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: gdk_pixbuf2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
20
88
  - !ruby/object:Gem::Version
21
- version: '0'
89
+ version: 1.2.5
22
90
  type: :runtime
23
91
  prerelease: false
24
92
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
93
  requirements:
27
- - - ! '>='
94
+ - - ~>
28
95
  - !ruby/object:Gem::Version
29
- version: '0'
96
+ version: 1.2.5
30
97
  description: The Ruby Regex Debugger. Put your regex in the top pane, and your match
31
98
  text in the bottom pane. Kang will highlight the match text that matches and show
32
99
  you any match groups you have created down the right hand side.
@@ -38,9 +105,11 @@ extra_rdoc_files: []
38
105
  files:
39
106
  - lib/kang.rb
40
107
  - lib/kang/cli.rb
108
+ - lib/kang/colors.rb
41
109
  - lib/kang/controller.rb
42
110
  - lib/kang/data.rb
43
111
  - lib/kang/offset_data.rb
112
+ - lib/kang/tags.rb
44
113
  - lib/kang/version.rb
45
114
  - lib/kang/view.rb
46
115
  - COPYING
@@ -48,26 +117,25 @@ files:
48
117
  - bin/kang
49
118
  homepage: http://github.com/tdoan/kang
50
119
  licenses: []
120
+ metadata: {}
51
121
  post_install_message:
52
122
  rdoc_options: []
53
123
  require_paths:
54
124
  - lib
55
125
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
126
  requirements:
58
127
  - - ! '>='
59
128
  - !ruby/object:Gem::Version
60
129
  version: '0'
61
130
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
131
  requirements:
64
132
  - - ! '>'
65
133
  - !ruby/object:Gem::Version
66
134
  version: 1.3.1
67
135
  requirements: []
68
136
  rubyforge_project:
69
- rubygems_version: 1.8.25
137
+ rubygems_version: 2.0.3
70
138
  signing_key:
71
- specification_version: 3
139
+ specification_version: 4
72
140
  summary: A visual regex debugger
73
141
  test_files: []