jugyo-termtter 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +19 -9
- data/README.rdoc +4 -0
- data/lib/filter/en2ja.rb +9 -0
- data/lib/filter/english.rb +8 -0
- data/lib/filter/expand-tinyurl.rb +15 -0
- data/lib/filter/reverse.rb +11 -0
- data/lib/filter/yhara.rb +20 -0
- data/lib/filter.rb +28 -0
- data/lib/plugin/english.rb +39 -42
- data/lib/plugin/favorite.rb +5 -1
- data/lib/plugin/fib.rb +4 -0
- data/lib/plugin/filter.rb +66 -0
- data/lib/plugin/growl.rb +2 -1
- data/lib/plugin/keyword.rb +16 -0
- data/lib/plugin/log.rb +1 -1
- data/lib/plugin/notify-send.rb +0 -1
- data/lib/plugin/shell.rb +5 -0
- data/lib/plugin/standard_plugins.rb +14 -2
- data/lib/plugin/stdout.rb +14 -4
- data/lib/plugin/translation.rb +26 -0
- data/lib/termtter.rb +43 -8
- metadata +20 -10
data/Manifest.txt
CHANGED
@@ -6,18 +6,28 @@ Rakefile
|
|
6
6
|
run_termtter.rb
|
7
7
|
bin/termtter
|
8
8
|
lib/termtter.rb
|
9
|
-
lib/
|
10
|
-
lib/plugin/notify-send.rb
|
11
|
-
lib/plugin/standard_plugins.rb
|
12
|
-
lib/plugin/uri-open.rb
|
13
|
-
lib/plugin/growl.rb
|
14
|
-
lib/plugin/say.rb
|
9
|
+
lib/filter.rb
|
15
10
|
lib/plugin/english.rb
|
16
|
-
lib/plugin/
|
17
|
-
lib/plugin/log.rb
|
11
|
+
lib/plugin/erb.rb
|
18
12
|
lib/plugin/favorite.rb
|
13
|
+
lib/plugin/fib.rb
|
14
|
+
lib/plugin/filter.rb
|
15
|
+
lib/plugin/growl.rb
|
16
|
+
lib/plugin/keyword.rb
|
17
|
+
lib/plugin/log.rb
|
18
|
+
lib/plugin/notify-send.rb
|
19
19
|
lib/plugin/plugin.rb
|
20
|
-
lib/plugin/
|
20
|
+
lib/plugin/say.rb
|
21
|
+
lib/plugin/shell.rb
|
22
|
+
lib/plugin/standard_plugins.rb
|
23
|
+
lib/plugin/stdout.rb
|
24
|
+
lib/plugin/translation.rb
|
25
|
+
lib/plugin/uri-open.rb
|
26
|
+
lib/filter/english.rb
|
27
|
+
lib/filter/reverse.rb
|
28
|
+
lib/filter/yhara.rb
|
29
|
+
lib/filter/expand-tinyurl.rb
|
30
|
+
lib/filter/en2ja.rb
|
21
31
|
test/test_termtter.rb
|
22
32
|
test/friends_timeline.json
|
23
33
|
test/search.json
|
data/README.rdoc
CHANGED
data/lib/filter/en2ja.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Termtter::Client
|
2
|
+
add_filter do |statuses|
|
3
|
+
statuses.each do |s|
|
4
|
+
s.text.gsub!(%r'(http://tinyurl\.com(/[\w/]+))') do |m|
|
5
|
+
expand_tinyurl($2) || $1
|
6
|
+
end
|
7
|
+
end
|
8
|
+
statuses
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def expand_tinyurl(path)
|
13
|
+
res = Net::HTTP.new('tinyurl.com').head(path)
|
14
|
+
res['Location']
|
15
|
+
end
|
data/lib/filter/yhara.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Termtter
|
4
|
+
|
5
|
+
class Status
|
6
|
+
def yharian?
|
7
|
+
self.text =~ /^(?:\s|(y\s)|(?:hara\s))+\s*(?:y|(?:hara))(?:\?|!|\.)?\s*$/
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Client
|
12
|
+
add_filter do |statuses|
|
13
|
+
statuses.select {|s| s.yharian? }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# filter-yhara.rb
|
19
|
+
# select Yharian post only
|
20
|
+
|
data/lib/filter.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Termtter
|
2
|
+
module Client
|
3
|
+
@@filters = []
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def add_filter(&filter)
|
7
|
+
@@filters << filter
|
8
|
+
end
|
9
|
+
|
10
|
+
def clear_filters
|
11
|
+
@@filters.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
# memo: each filter must return Array of Status
|
15
|
+
def apply_filters(statuses)
|
16
|
+
filtered = statuses
|
17
|
+
@@filters.each do |f|
|
18
|
+
filtered = f.call(filtered)
|
19
|
+
end
|
20
|
+
filtered
|
21
|
+
rescue => e
|
22
|
+
puts "Error: #{e}"
|
23
|
+
puts e.backtrace.join("\n")
|
24
|
+
statuses
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/plugin/english.rb
CHANGED
@@ -1,60 +1,57 @@
|
|
1
1
|
require 'erb'
|
2
2
|
|
3
|
-
Termtter
|
3
|
+
module Termtter
|
4
|
+
Client.clear_hooks # FIXME: not to clear all but to clear just stdout.rb
|
4
5
|
|
5
|
-
configatron.set_default(
|
6
|
-
|
7
|
-
|
6
|
+
configatron.set_default(
|
7
|
+
:timeline_format,
|
8
|
+
'<%= color(time, 90) %> <%= color(status, status_color) %> <%= color(id, 90) %>')
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
10
|
+
def color(str, num)
|
11
|
+
"\e[#{num}m#{str}\e[0m"
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
# FIXME: The code below is a copy from stdout.rb so it's not DRY. DRY it.
|
15
|
+
|
16
|
+
Client.add_hook do |statuses, event|
|
17
|
+
colors = %w(0 31 32 33 34 35 36 91 92 93 94 95 96)
|
18
|
+
|
19
|
+
case event
|
20
|
+
when :update_friends_timeline, :list_friends_timeline, :list_user_timeline, :show, :replies
|
21
|
+
unless statuses.empty?
|
22
|
+
statuses.reverse! if event == :update_friends_timeline
|
23
|
+
statuses.each do |s|
|
24
|
+
text = s.text.gsub("\n", '')
|
25
|
+
next unless Status.english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
|
26
|
+
status_color = colors[s.user_screen_name.hash % colors.size]
|
27
|
+
status = "#{s.user_screen_name}: #{text}"
|
28
|
+
if s.in_reply_to_status_id
|
29
|
+
status += " (reply to #{s.in_reply_to_status_id})"
|
30
|
+
end
|
17
31
|
|
18
|
-
|
32
|
+
time_format = case event
|
33
|
+
when :update_friends_timeline, :list_friends_timeline
|
34
|
+
'%H:%M:%S'
|
35
|
+
else
|
36
|
+
'%m-%d %H:%M'
|
37
|
+
end
|
38
|
+
time = "(#{s.created_at.strftime(time_format)})"
|
19
39
|
|
20
|
-
|
21
|
-
colors = %w(0 31 32 33 34 35 36 91 92 93 94 95 96)
|
40
|
+
id = s.id
|
22
41
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
42
|
+
puts ERB.new(configatron.timeline_format).result(binding)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
when :search
|
27
46
|
statuses.each do |s|
|
28
47
|
text = s.text.gsub("\n", '')
|
29
|
-
next unless english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
|
30
48
|
status_color = colors[s.user_screen_name.hash % colors.size]
|
31
|
-
status = "#{s.user_screen_name}: #{text}"
|
32
|
-
if s.in_reply_to_status_id
|
33
|
-
status += " (reply to #{s.in_reply_to_status_id})"
|
34
|
-
end
|
35
|
-
|
36
|
-
time_format = case event
|
37
|
-
when :update_friends_timeline, :list_friends_timeline
|
38
|
-
'%H:%M:%S'
|
39
|
-
else
|
40
|
-
'%m-%d %H:%M'
|
41
|
-
end
|
42
|
-
time = "(#{s.created_at.strftime(time_format)})"
|
43
49
|
|
50
|
+
status = "#{s.user_screen_name}: #{text}"
|
51
|
+
time = "(#{s.created_at.strftime('%m-%d %H:%M')})"
|
44
52
|
id = s.id
|
45
|
-
|
46
53
|
puts ERB.new(configatron.timeline_format).result(binding)
|
47
54
|
end
|
48
55
|
end
|
49
|
-
when :search
|
50
|
-
statuses.each do |s|
|
51
|
-
text = s.text.gsub("\n", '')
|
52
|
-
status_color = colors[s.user_screen_name.hash % colors.size]
|
53
|
-
|
54
|
-
status = "#{s.user_screen_name}: #{text}"
|
55
|
-
time = "(#{s.created_at.strftime('%m-%d %H:%M')})"
|
56
|
-
id = s.id
|
57
|
-
puts ERB.new(configatron.timeline_format).result(binding)
|
58
|
-
end
|
59
56
|
end
|
60
57
|
end
|
data/lib/plugin/favorite.rb
CHANGED
@@ -12,7 +12,7 @@ module Termtter::Client
|
|
12
12
|
end
|
13
13
|
|
14
14
|
if public_storage[:log]
|
15
|
-
add_help 'favorite,fav /
|
15
|
+
add_help 'favorite,fav /WORD', 'Favorite a status by searching'
|
16
16
|
|
17
17
|
add_command %r'^(?:favorite|fav)\s+/(.+)$' do |m,t|
|
18
18
|
pat = Regexp.new(m[1])
|
@@ -30,6 +30,10 @@ module Termtter::Client
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
add_completion do |input|
|
35
|
+
%w(favorite).grep(/^#{Regexp.quote input}/)
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
module Termtter
|
data/lib/plugin/fib.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
module Termtter::Client
|
3
|
+
|
4
|
+
public_storage[:filters] = []
|
5
|
+
|
6
|
+
add_help 'filter FILE', 'Apply a filter'
|
7
|
+
add_command /^filter\s+(.*)/ do |m, t|
|
8
|
+
begin
|
9
|
+
result = filter m[1].strip
|
10
|
+
rescue LoadError
|
11
|
+
result = false
|
12
|
+
else
|
13
|
+
public_storage[:filters] << m[1].strip
|
14
|
+
ensure
|
15
|
+
puts "=> #{result.inspect}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
add_help 'unfilter', 'Clear all filters'
|
20
|
+
add_command /^unfilter\s*$/ do |m, t|
|
21
|
+
clear_filters
|
22
|
+
public_storage[:filters].clear
|
23
|
+
puts '=> filter cleared'
|
24
|
+
end
|
25
|
+
|
26
|
+
add_help 'filters', 'Show list of applied filters'
|
27
|
+
add_command /^filters\s*$/ do |m, t|
|
28
|
+
unless public_storage[:filters].empty?
|
29
|
+
puts public_storage[:filters].join(', ')
|
30
|
+
else
|
31
|
+
puts 'no filter was applied'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find_filter_candidates(a, b, filters)
|
36
|
+
if a.empty?
|
37
|
+
filters.to_a
|
38
|
+
else
|
39
|
+
filters.grep(/^#{Regexp.quote a}/i)
|
40
|
+
end.
|
41
|
+
map {|u| b % u }
|
42
|
+
end
|
43
|
+
|
44
|
+
filters = Dir["#{File.dirname(__FILE__)}/../filter/*.rb"].map do |f|
|
45
|
+
f.match(%r|([^/]+).rb$|)[1]
|
46
|
+
end
|
47
|
+
add_completion do |input|
|
48
|
+
if input =~ /^(filter)\s+(.*)/
|
49
|
+
find_filter_candidates $2, "#{$1} %s", filters
|
50
|
+
else
|
51
|
+
%w[ filter filters unfilter ].grep(/^#{Regexp.quote input}/)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# filter.rb
|
57
|
+
# a dynamic filter loader
|
58
|
+
# example
|
59
|
+
# > list
|
60
|
+
# (15:49:00) termtter: こんにちは
|
61
|
+
# (15:48:02) termtter: hello
|
62
|
+
# > filter english
|
63
|
+
# => true
|
64
|
+
# > list
|
65
|
+
# (15:48:02) termtter: hello
|
66
|
+
|
data/lib/plugin/growl.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'tmpdir'
|
2
2
|
require 'open-uri'
|
3
3
|
require 'uri'
|
4
|
+
require 'fileutils'
|
4
5
|
|
5
6
|
configatron.plugins.growl.set_default(:icon_cache_dir, "#{Dir.tmpdir}/termtter-icon-cache-dir")
|
6
|
-
|
7
|
+
FileUtils.mkdir_p(configatron.plugins.growl.icon_cache_dir) unless File.exist?(configatron.plugins.growl.icon_cache_dir)
|
7
8
|
|
8
9
|
def get_icon_path(s)
|
9
10
|
cache_file = "%s/%s%s" % [ configatron.plugins.growl.icon_cache_dir,
|
@@ -0,0 +1,16 @@
|
|
1
|
+
configatron.set_default('plugins.keyword.keywords', [])
|
2
|
+
|
3
|
+
module Termtter
|
4
|
+
class Status
|
5
|
+
def has_keyword?
|
6
|
+
configatron.plugins.keyword.keywords.find { |k| k === self.text }
|
7
|
+
end
|
8
|
+
alias :has_keyword :has_keyword?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# keyword.rb
|
13
|
+
# provides a keyword watching method
|
14
|
+
# example config
|
15
|
+
# configatron.timeline_format = '<%= color(time, 90) %> <%= color(status, s.has_keyword ? 4 : status_color) %> <%= color(id, 90) %>'
|
16
|
+
# configatron.plugins.keyword.keywords = [ /motemen/ ]
|
data/lib/plugin/log.rb
CHANGED
data/lib/plugin/notify-send.rb
CHANGED
@@ -5,7 +5,6 @@ Termtter::Client.add_hook do |statuses, event|
|
|
5
5
|
text = statuses.take(max).map {|s|
|
6
6
|
status_text = CGI.escapeHTML(s.text)
|
7
7
|
status_text.gsub!(%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},'<a href="\0">\0</a>')
|
8
|
-
status_text.gsub!("\n", '')
|
9
8
|
"<b>#{s.user_screen_name}:</b> <span font=\"9.0\">#{status_text}</span>"
|
10
9
|
}.join("\n")
|
11
10
|
|
data/lib/plugin/shell.rb
ADDED
@@ -40,13 +40,13 @@ module Termtter::Client
|
|
40
40
|
resume
|
41
41
|
end
|
42
42
|
|
43
|
-
add_command /^exit\s*$/ do |m, t|
|
43
|
+
add_command /^(exit|e)\s*$/ do |m, t|
|
44
44
|
exit
|
45
45
|
end
|
46
46
|
|
47
47
|
add_command /^help\s*$/ do |m, t|
|
48
48
|
puts <<-EOS
|
49
|
-
exit
|
49
|
+
exit,e Exit
|
50
50
|
help Print this help message
|
51
51
|
list,l List the posts in your friends timeline
|
52
52
|
list,l USERNAME List the posts in the the given user's timeline
|
@@ -69,6 +69,18 @@ show ID Show a single status
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
add_command /^!(!)?\s*(.*)$/ do |m, t|
|
73
|
+
begin
|
74
|
+
result = `#{m[2]}` unless m[2].empty?
|
75
|
+
unless m[1].nil? || result.empty?
|
76
|
+
t.update_status(result.gsub("\n", " "))
|
77
|
+
end
|
78
|
+
puts "=> #{result}"
|
79
|
+
rescue => e
|
80
|
+
puts e
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
72
84
|
def self.formatted_help
|
73
85
|
width = @@helps.map {|n, d| n.size }.max
|
74
86
|
space = 3
|
data/lib/plugin/stdout.rb
CHANGED
@@ -4,8 +4,18 @@ configatron.set_default(
|
|
4
4
|
:timeline_format,
|
5
5
|
'<%= color(time, 90) %> <%= color(status, status_color) %> <%= color(id, 90) %>')
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
|
8
|
+
require 'kconv'
|
9
|
+
def color(str, num)
|
10
|
+
str.to_s.tosjis
|
11
|
+
end
|
12
|
+
def puts(str)
|
13
|
+
STDOUT.puts(str.tosjis)
|
14
|
+
end
|
15
|
+
else
|
16
|
+
def color(str, num)
|
17
|
+
"\e[#{num}m#{str}\e[0m"
|
18
|
+
end
|
9
19
|
end
|
10
20
|
|
11
21
|
Termtter::Client.add_hook do |statuses, event|
|
@@ -16,7 +26,7 @@ Termtter::Client.add_hook do |statuses, event|
|
|
16
26
|
unless statuses.empty?
|
17
27
|
statuses.reverse! if event == :update_friends_timeline
|
18
28
|
statuses.each do |s|
|
19
|
-
text = s.text
|
29
|
+
text = s.text
|
20
30
|
status_color = colors[s.user_screen_name.hash % colors.size]
|
21
31
|
status = "#{s.user_screen_name}: #{text}"
|
22
32
|
if s.in_reply_to_status_id
|
@@ -38,7 +48,7 @@ Termtter::Client.add_hook do |statuses, event|
|
|
38
48
|
end
|
39
49
|
when :search
|
40
50
|
statuses.each do |s|
|
41
|
-
text = s.text
|
51
|
+
text = s.text
|
42
52
|
status_color = colors[s.user_screen_name.hash % colors.size]
|
43
53
|
|
44
54
|
status = "#{s.user_screen_name}: #{text}"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'kconv'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
def translate(text, langpair)
|
7
|
+
req = Net::HTTP::Post.new('/translate_t')
|
8
|
+
req.add_field('Content-Type', 'application/x-www-form-urlencoded')
|
9
|
+
req.add_field('User-Agent', 'Mozilla/5.0')
|
10
|
+
Net::HTTP.version_1_2 # Proxy に対応してない
|
11
|
+
Net::HTTP.start('translate.google.co.jp', 80) {|http|
|
12
|
+
response = http.request(req, "langpair=#{langpair}&text=#{URI.escape(text)}")
|
13
|
+
doc = Nokogiri::HTML.parse(response.body, nil, 'utf-8')
|
14
|
+
return doc.css('#result_box').text
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
Termtter::Client.add_command /^(en2ja|ja2en)\s+(.*)$/ do |m, t|
|
19
|
+
langpair = m[1].gsub('2', '|')
|
20
|
+
puts "translating..."
|
21
|
+
puts "=> #{translate(m[2], langpair)}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# This plugin does not work yet.
|
25
|
+
# requirements
|
26
|
+
# nokogiri (sudo gem install nokogiri)
|
data/lib/termtter.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
1
4
|
require 'rubygems'
|
2
5
|
require 'json'
|
3
6
|
require 'open-uri'
|
@@ -6,6 +9,7 @@ require 'readline'
|
|
6
9
|
require 'enumerator'
|
7
10
|
require 'parsedate'
|
8
11
|
require 'configatron'
|
12
|
+
require 'filter'
|
9
13
|
|
10
14
|
if RUBY_VERSION < '1.8.7'
|
11
15
|
class Array
|
@@ -13,8 +17,16 @@ if RUBY_VERSION < '1.8.7'
|
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
|
21
|
+
require 'kconv'
|
22
|
+
module Readline
|
23
|
+
alias :old_readline :readline
|
24
|
+
def readline(*a)
|
25
|
+
old_readline(*a).toutf8
|
26
|
+
end
|
27
|
+
module_function :old_readline, :readline
|
28
|
+
end
|
29
|
+
end
|
18
30
|
|
19
31
|
configatron.set_default(:update_interval, 300)
|
20
32
|
configatron.set_default(:prompt, '> ')
|
@@ -23,6 +35,10 @@ def plugin(s)
|
|
23
35
|
require "plugin/#{s}"
|
24
36
|
end
|
25
37
|
|
38
|
+
def filter(s)
|
39
|
+
load "filter/#{s}.rb"
|
40
|
+
end
|
41
|
+
|
26
42
|
# FIXME: delete this method after the major version up
|
27
43
|
alias original_require require
|
28
44
|
def require(s)
|
@@ -35,7 +51,7 @@ def require(s)
|
|
35
51
|
end
|
36
52
|
|
37
53
|
module Termtter
|
38
|
-
VERSION = '0.
|
54
|
+
VERSION = '0.7.0'
|
39
55
|
APP_NAME = 'termtter'
|
40
56
|
|
41
57
|
class Twitter
|
@@ -50,6 +66,7 @@ module Termtter
|
|
50
66
|
uri = '/statuses/update.xml'
|
51
67
|
http.request(post_request(uri), "status=#{CGI.escape(status)}&source=#{APP_NAME}")
|
52
68
|
end
|
69
|
+
status
|
53
70
|
end
|
54
71
|
|
55
72
|
def get_friends_timeline(since_id = nil)
|
@@ -72,7 +89,7 @@ module Termtter
|
|
72
89
|
return results.map do |s|
|
73
90
|
status = Status.new
|
74
91
|
status.id = s['id']
|
75
|
-
status.text = CGI.unescapeHTML(s['text'])
|
92
|
+
status.text = CGI.unescapeHTML(s['text']).gsub(/(\n|\r)/, '')
|
76
93
|
status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
|
77
94
|
status.user_screen_name = s['from_user']
|
78
95
|
status
|
@@ -99,7 +116,7 @@ module Termtter
|
|
99
116
|
%w(id name screen_name url profile_image_url).each do |key|
|
100
117
|
status.__send__("user_#{key}=".to_sym, s["user"][key])
|
101
118
|
end
|
102
|
-
status.text = CGI.unescapeHTML(status.text)
|
119
|
+
status.text = CGI.unescapeHTML(status.text).gsub(/(\n|\r)/, '')
|
103
120
|
status
|
104
121
|
end
|
105
122
|
end
|
@@ -174,6 +191,7 @@ module Termtter
|
|
174
191
|
end
|
175
192
|
|
176
193
|
def call_hooks(statuses, event, tw)
|
194
|
+
statuses = apply_filters(statuses)
|
177
195
|
@@hooks.each do |h|
|
178
196
|
begin
|
179
197
|
h.call(statuses.dup, event, tw)
|
@@ -247,6 +265,11 @@ module Termtter
|
|
247
265
|
|
248
266
|
until initialized; end
|
249
267
|
|
268
|
+
vi_or_emacs = configatron.editing_mode
|
269
|
+
unless vi_or_emacs.empty?
|
270
|
+
Readline.__send__("#{vi_or_emacs}_editing_mode")
|
271
|
+
end
|
272
|
+
|
250
273
|
@@input_thread = Thread.new do
|
251
274
|
while buf = Readline.readline(configatron.prompt, true)
|
252
275
|
begin
|
@@ -261,8 +284,11 @@ module Termtter
|
|
261
284
|
end
|
262
285
|
end
|
263
286
|
|
264
|
-
|
265
|
-
|
287
|
+
begin
|
288
|
+
stty_save = `stty -g`.chomp
|
289
|
+
trap("INT") { system "stty", stty_save; exit }
|
290
|
+
rescue Errno::ENOENT
|
291
|
+
end
|
266
292
|
|
267
293
|
@@input_thread.join
|
268
294
|
end
|
@@ -280,6 +306,15 @@ module Termtter
|
|
280
306
|
).each do |attr|
|
281
307
|
attr_accessor attr.to_sym
|
282
308
|
end
|
283
|
-
end
|
284
309
|
|
310
|
+
def english?
|
311
|
+
self.class.english?(self.text)
|
312
|
+
end
|
313
|
+
|
314
|
+
# english? :: String -> Boolean
|
315
|
+
def self.english?(message)
|
316
|
+
/[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
|
317
|
+
end
|
318
|
+
end
|
285
319
|
end
|
320
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jugyo-termtter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -61,18 +61,28 @@ files:
|
|
61
61
|
- run_termtter.rb
|
62
62
|
- bin/termtter
|
63
63
|
- lib/termtter.rb
|
64
|
-
- lib/
|
65
|
-
- lib/plugin/notify-send.rb
|
66
|
-
- lib/plugin/standard_plugins.rb
|
67
|
-
- lib/plugin/uri-open.rb
|
68
|
-
- lib/plugin/growl.rb
|
69
|
-
- lib/plugin/say.rb
|
64
|
+
- lib/filter.rb
|
70
65
|
- lib/plugin/english.rb
|
71
|
-
- lib/plugin/
|
72
|
-
- lib/plugin/log.rb
|
66
|
+
- lib/plugin/erb.rb
|
73
67
|
- lib/plugin/favorite.rb
|
68
|
+
- lib/plugin/fib.rb
|
69
|
+
- lib/plugin/filter.rb
|
70
|
+
- lib/plugin/growl.rb
|
71
|
+
- lib/plugin/keyword.rb
|
72
|
+
- lib/plugin/log.rb
|
73
|
+
- lib/plugin/notify-send.rb
|
74
74
|
- lib/plugin/plugin.rb
|
75
|
-
- lib/plugin/
|
75
|
+
- lib/plugin/say.rb
|
76
|
+
- lib/plugin/shell.rb
|
77
|
+
- lib/plugin/standard_plugins.rb
|
78
|
+
- lib/plugin/stdout.rb
|
79
|
+
- lib/plugin/translation.rb
|
80
|
+
- lib/plugin/uri-open.rb
|
81
|
+
- lib/filter/english.rb
|
82
|
+
- lib/filter/reverse.rb
|
83
|
+
- lib/filter/yhara.rb
|
84
|
+
- lib/filter/expand-tinyurl.rb
|
85
|
+
- lib/filter/en2ja.rb
|
76
86
|
- test/test_termtter.rb
|
77
87
|
- test/friends_timeline.json
|
78
88
|
- test/search.json
|