Skip to content

Instantly share code, notes, and snippets.

@no6v
Created December 7, 2011 03:45
Show Gist options
  • Save no6v/1441357 to your computer and use it in GitHub Desktop.
Save no6v/1441357 to your computer and use it in GitHub Desktop.
diff --git a/lib/earthquake/commands.rb b/lib/earthquake/commands.rb
index 6551bfc..033578b 100644
--- a/lib/earthquake/commands.rb
+++ b/lib/earthquake/commands.rb
@@ -232,12 +232,14 @@ Earthquake.init do
}
command %r!^:filter off$!, as: :filter do
+ highlights.delete(:filter_keyword)
config[:api] = default_stream
reconnect
end
command %r!^:filter keyword (.*)$!, as: :filter do |m|
keywords = Shellwords.split(m[1])
+ highlights[:filter_keyword] = keywords
config[:api] = filter_stream.merge(filters: keywords)
reconnect
end
diff --git a/lib/earthquake/output.rb b/lib/earthquake/output.rb
index 7bfc0a5..4e72b58 100644
--- a/lib/earthquake/output.rb
+++ b/lib/earthquake/output.rb
@@ -11,6 +11,10 @@ module Earthquake
output_filters << block
end
+ def highlights
+ @highlights ||= {}
+ end
+
def outputs
@outputs ||= []
end
@@ -107,11 +111,9 @@ module Earthquake
text = text.coloring(/(^#[^\s]+)|(\s+#[^\s]+)/) { |i| color_of(i) }
text = text.coloring(URI.regexp(["http", "https"]), :url)
- if item["_highlights"]
- item["_highlights"].each do |h|
- color = config[:color][:highlight].nil? ? color_of(h).to_i + 10 : :highlight
- text = text.coloring(/#{h}/i, color)
- end
+ highlights.flat_map(&:last).concat(item["_highlights"] || []).each do |h|
+ color = config[:color][:highlight].nil? ? color_of(h).to_i + 10 : :highlight
+ text = text.coloring(/#{h}/i, color)
end
mark = item["_mark"] || ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment