skygrepe 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/skygrepe +69 -6
- data/lib/skygrepe.rb +49 -10
- data/lib/skygrepe/version.rb +1 -1
- data/skygrepe.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3b185ee9a928eedca50a9d038e6ef68b117f88b
|
4
|
+
data.tar.gz: a53de235129d68a799e7335141e68d77f0113a7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c1301b6a227e1c8506e1004f29b611b4392526cda6a3e764c98eeff6ae78e35c4ac607c0b193b19f9f31968cbe616497c3421ab1ff5b1927793c4a3bae6db3c
|
7
|
+
data.tar.gz: b868bead7ea3bab9a66e6192acd4644199a1983c6721c0e2b9938d5d793c7bcd0be80af63c092670af8a146d3e699507ebf09f7ce46eff67edd30ad1b7424def
|
data/bin/skygrepe
CHANGED
@@ -39,6 +39,17 @@ end
|
|
39
39
|
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
|
40
40
|
require 'skygrepe'
|
41
41
|
|
42
|
+
require "highline/system_extensions"
|
43
|
+
|
44
|
+
def get_char_without_enter
|
45
|
+
HighLine::SystemExtensions.raw_no_echo_mode
|
46
|
+
begin
|
47
|
+
HighLine::SystemExtensions.get_character
|
48
|
+
ensure
|
49
|
+
HighLine::SystemExtensions.restore_mode
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
42
53
|
c =Skygrepe::Context.new(ARGV.first, config)
|
43
54
|
while !c.quit?
|
44
55
|
rows = c.run
|
@@ -46,12 +57,64 @@ while !c.quit?
|
|
46
57
|
puts line.join("|")
|
47
58
|
end
|
48
59
|
break if c.count <= c.limit
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
60
|
+
|
61
|
+
while true
|
62
|
+
print("command (h)elp: ")
|
63
|
+
|
64
|
+
if cmd = get_char_without_enter # $stdin.getc
|
65
|
+
if cmd == "\r".ord
|
66
|
+
print "\r \n"
|
67
|
+
next
|
68
|
+
end
|
69
|
+
cmd = cmd.chr
|
70
|
+
print("\r")
|
71
|
+
case cmd
|
72
|
+
when /\Ah/ then
|
73
|
+
puts "(N)ext page or <SPACE>: next page of list"
|
74
|
+
puts "(P)rev page: previous page of list"
|
75
|
+
puts "(s)how: specify message id"
|
76
|
+
puts "(d)etail: show message"
|
77
|
+
puts "(n)ext: show next message"
|
78
|
+
puts "(p)rev: show previous message"
|
79
|
+
puts "(q)uit: quit"
|
80
|
+
when " " then c.next_page; break
|
81
|
+
when /\AN/ then c.next_page; break
|
82
|
+
when /\AP/ then c.prev_page; break
|
83
|
+
when /\Aq/ then c.quit; break
|
84
|
+
when /\As/ then
|
85
|
+
print(" " * 20)
|
86
|
+
print("\r")
|
87
|
+
print("type message id: ")
|
88
|
+
id = $stdin.gets
|
89
|
+
d = c.detail(id)
|
90
|
+
unless d
|
91
|
+
puts "no data found for #{id.inspect}"
|
92
|
+
break
|
93
|
+
end
|
94
|
+
puts d.join("|")
|
95
|
+
when /\Ad/ then
|
96
|
+
d = c.detail(c.current_id)
|
97
|
+
unless d
|
98
|
+
puts "No data"
|
99
|
+
break
|
100
|
+
end
|
101
|
+
puts d.join("|")
|
102
|
+
when /\An/ then
|
103
|
+
d = c.next_detail
|
104
|
+
unless d
|
105
|
+
puts "No data"
|
106
|
+
break
|
107
|
+
end
|
108
|
+
puts d.join("|")
|
109
|
+
when /\Ap/ then
|
110
|
+
d = c.prev_detail
|
111
|
+
unless d
|
112
|
+
puts "No data"
|
113
|
+
break
|
114
|
+
end
|
115
|
+
puts d.join("|")
|
116
|
+
end
|
55
117
|
end
|
56
118
|
end
|
119
|
+
|
57
120
|
end
|
data/lib/skygrepe.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
require "skygrepe/version"
|
2
2
|
require "sqlite3"
|
3
|
+
require 'cgi/util'
|
3
4
|
|
4
5
|
require "time"
|
5
6
|
|
6
7
|
module Skygrepe
|
7
8
|
|
8
9
|
class Context
|
9
|
-
attr_reader :count, :limit
|
10
|
+
attr_reader :count, :limit, :current_id
|
10
11
|
|
11
12
|
def initialize(keyword, config)
|
12
13
|
raise ArgumentError, "keyword is empty" if keyword.nil? || keyword.empty?
|
14
|
+
@keyword = keyword
|
13
15
|
@config = config
|
14
|
-
@condition = Condition.new(keyword)
|
16
|
+
@condition = Condition.new(@keyword)
|
15
17
|
@offset = 0
|
16
18
|
@limit = 30
|
17
19
|
@quit = false
|
20
|
+
@current_id = nil
|
18
21
|
end
|
19
22
|
|
20
23
|
def quit?
|
@@ -25,23 +28,48 @@ module Skygrepe
|
|
25
28
|
@db ||= SQLite3::Database.new(@config["main_db_path"])
|
26
29
|
end
|
27
30
|
|
31
|
+
def formatter
|
32
|
+
@formatter ||= Formatter.new(@keyword, {"time_format" => @config["time_format"]})
|
33
|
+
end
|
34
|
+
|
28
35
|
def run
|
29
36
|
@count ||= db.execute(@condition.count_sql).flatten.first.to_i
|
30
|
-
formatter = Formatter.new({"time_format" => @config["time_format"]})
|
31
37
|
sql = @condition.grep_sql(@limit, @offset)
|
32
|
-
rows = db.execute(sql).map{|row| formatter.
|
38
|
+
rows = db.execute(sql).map{|row| formatter.list(row) }
|
39
|
+
unless rows.empty?
|
40
|
+
@current_id = rows.first.first.to_i
|
41
|
+
end
|
33
42
|
if @count <= @limit
|
34
43
|
@quit = true
|
35
44
|
end
|
36
45
|
rows
|
37
46
|
end
|
38
47
|
|
39
|
-
def
|
48
|
+
def next_page(page = 1)
|
40
49
|
@offset += (@limit * page)
|
41
50
|
end
|
42
51
|
|
43
|
-
def
|
44
|
-
self.
|
52
|
+
def prev_page(page = 1)
|
53
|
+
self.next_page( -1 * page)
|
54
|
+
end
|
55
|
+
|
56
|
+
def detail(id)
|
57
|
+
sql = "SELECT m.id, m.timestamp, c.displayname, m.author, m.body_xml FROM Messages as m inner join Conversations as c on m.convo_id = c.id"
|
58
|
+
sql << " WHERE m.id = #{id}"
|
59
|
+
if d = db.execute(sql).first
|
60
|
+
@current_id = d.first.to_i
|
61
|
+
formatter.detail(d)
|
62
|
+
else
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def next_detail(d = 1)
|
68
|
+
detail(@current_id + d)
|
69
|
+
end
|
70
|
+
|
71
|
+
def prev_detail(d = 1)
|
72
|
+
self.next_detail( -1 * d)
|
45
73
|
end
|
46
74
|
|
47
75
|
def quit
|
@@ -71,14 +99,25 @@ module Skygrepe
|
|
71
99
|
end
|
72
100
|
|
73
101
|
class Formatter
|
74
|
-
def initialize(config)
|
102
|
+
def initialize(keyword, config)
|
103
|
+
@keyword = keyword
|
75
104
|
@time_format = config["time_format"] || "%Y-%m-%d %H:%M"
|
76
105
|
end
|
77
106
|
|
78
|
-
def
|
107
|
+
def list(row)
|
79
108
|
row[1] = Time.at(row[1]).strftime(@time_format)
|
80
|
-
row[4] = (row[4] || '').gsub(/[\n\r]/m, '')
|
109
|
+
row[4] = format_message(row[4] || '').gsub(/[\n\r]/m, '')
|
81
110
|
row
|
82
111
|
end
|
112
|
+
|
113
|
+
def detail(row)
|
114
|
+
row[1] = Time.at(row[1]).strftime(@time_format)
|
115
|
+
row[4] = format_message(row[4] || '')
|
116
|
+
row
|
117
|
+
end
|
118
|
+
|
119
|
+
def format_message(msg)
|
120
|
+
CGI.unescape_html(msg || '').gsub(/(#{Regexp.escape(@keyword)})/i){ "\e[32m#{$1}\e[0m" }
|
121
|
+
end
|
83
122
|
end
|
84
123
|
end
|
data/lib/skygrepe/version.rb
CHANGED
data/skygrepe.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skygrepe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akima
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: highline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|