earthquake 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/earthquake.gemspec +1 -1
- data/lib/earthquake/ext.rb +8 -0
- data/lib/earthquake/output.rb +5 -17
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.8
|
data/earthquake.gemspec
CHANGED
data/lib/earthquake/ext.rb
CHANGED
@@ -43,6 +43,14 @@ class String
|
|
43
43
|
"\e[#{codes.join(';')}m#{self}\e[0m"
|
44
44
|
end
|
45
45
|
|
46
|
+
def coloring(pattern, color = nil, &block)
|
47
|
+
self.gsub(pattern) do |i|
|
48
|
+
applied_colors = self[0...$~.begin(0)].scan(/\e\[[\d;]+m/)
|
49
|
+
color ||= block.call(i)
|
50
|
+
"#{i.c(color)}#{applied_colors.join}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
46
54
|
def u
|
47
55
|
gsub(/&(lt|gt|amp|quot|apos);/) do |s|
|
48
56
|
case s
|
data/lib/earthquake/output.rb
CHANGED
@@ -92,26 +92,14 @@ module Earthquake
|
|
92
92
|
|
93
93
|
text = item["text"].u
|
94
94
|
text.gsub!(/\s+/, ' ') unless config[:raw_text]
|
95
|
-
text.
|
96
|
-
|
97
|
-
|
98
|
-
text.gsub!(/(?:^#([^\s]+))|(?:\s+#([^\s]+))/) do |i|
|
99
|
-
i.c(color_of($1 || $2))
|
100
|
-
end
|
101
|
-
text.gsub!(URI.regexp(["http", "https"])) do |i|
|
102
|
-
i.c(:url)
|
103
|
-
end
|
95
|
+
text = text.coloring(/@([0-9A-Za-z_]+)/) { |i| color_of(i) }
|
96
|
+
text = text.coloring(/(?:^#([^\s]+))|(?:\s+#([^\s]+))/) { |i| color_of(i) }
|
97
|
+
text = text.coloring(URI.regexp(["http", "https"]), :url)
|
104
98
|
|
105
99
|
if item["_highlights"]
|
106
100
|
item["_highlights"].each do |h|
|
107
|
-
|
108
|
-
|
109
|
-
else
|
110
|
-
c = :highlight
|
111
|
-
end
|
112
|
-
text = text.gsub(/#{h}/i) do |i|
|
113
|
-
i.c(c)
|
114
|
-
end
|
101
|
+
color = config[:color][:highlight].nil? ? color_of(h).to_i + 10 : :highlight
|
102
|
+
text = text.coloring(/#{h}/i, color)
|
115
103
|
end
|
116
104
|
end
|
117
105
|
|