helpline 0.1.15 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/00README +8 -1
- data/Makefile +8 -46
- data/Makefile.electron +43 -0
- data/exe/helpline +29 -261
- data/lib/helpline/generate.rb +77 -0
- data/lib/helpline/helpline.rb +8 -0
- data/lib/helpline/run.rb +97 -0
- data/lib/helpline/update.rb +114 -0
- data/lib/helpline/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2ec697caa86da979b533f2002d7fa313b1fec88eb31e8f89a8b3176e09cccb5
|
4
|
+
data.tar.gz: 74d191374b68cda1545ac70f1e4ca4abea2fd0a867cb66c72fc66d29c8fab7e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd4ff55951f5f64ffec395028f4069c74c3251409850d3e7200738bb03a461b2677eef60b1e17f385cf3a3f7511b00405636466e1e759d622dcd4bfeefcb8eab
|
7
|
+
data.tar.gz: 3801b7240aea007585935c50bcc3c74b6fd06410a4801a0f909b9852a301c4ced1e963ef0957e60e56f82420d4601620f8a96cd235ed6c4c1a82ccc942bbfea7
|
data/00README
CHANGED
data/Makefile
CHANGED
@@ -1,54 +1,16 @@
|
|
1
|
-
.PHONY:
|
2
|
-
|
3
|
-
run: browserify
|
4
|
-
npm start .
|
5
|
-
|
6
|
-
browserify:
|
7
|
-
browserify helpline.js -o helpline_browserify.js
|
8
|
-
|
9
|
-
build-mac: install browserify
|
10
|
-
npm run build
|
11
|
-
cp -r build/mac/HelpLine.app /Applications
|
12
|
-
upload:
|
13
|
-
scp build/HelpLine-0.0.1.dmg pitecan.com:/www/www.pitecan.com/tmp/HelpLine.dmg
|
14
|
-
|
15
|
-
build-chromebook: browserify install
|
16
|
-
npm run build
|
17
|
-
|
18
|
-
#dmg: build-mac
|
19
|
-
# -/bin/rm -f HelpLine.dmg
|
20
|
-
# hdiutil create -srcfolder build/mac/HelpLine.app -volname HelpLine HelpLine.dmg
|
21
|
-
|
22
|
-
#install: npm browserify cursorpos electron
|
23
|
-
install:
|
24
|
-
npm install
|
25
|
-
|
26
|
-
electron:
|
27
|
-
npm install electron
|
28
|
-
|
1
|
+
.PHONY: test
|
29
2
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
update: data.js glossary.js
|
33
|
-
data.js:
|
34
|
-
ruby getdata.rb > data.js
|
35
|
-
glossary.js:
|
36
|
-
ruby getglossary.rb > glossary.js
|
37
|
-
|
38
|
-
clean:
|
39
|
-
-/bin/rm -r -f node_modules
|
40
|
-
-/bin/rm -r -f build
|
41
|
-
-/bin/rm -f HelpLine.dmg
|
42
|
-
|
43
|
-
all: update build-mac
|
44
|
-
|
45
|
-
|
46
|
-
#
|
47
|
-
# gem
|
3
|
+
# Gem版
|
48
4
|
#
|
49
5
|
release:
|
50
6
|
rake release
|
51
7
|
|
8
|
+
update:
|
9
|
+
helpline --update
|
10
|
+
|
11
|
+
update-local:
|
12
|
+
helpline --update ~/ScrapboxData/HelpLine.json ~/ScrapboxData/masui-helpline.json
|
13
|
+
|
52
14
|
#
|
53
15
|
# テスト
|
54
16
|
#
|
data/Makefile.electron
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
.PHONY: data.js glossary.js test
|
2
|
+
|
3
|
+
run: browserify
|
4
|
+
npm start .
|
5
|
+
|
6
|
+
browserify:
|
7
|
+
browserify helpline.js -o helpline_browserify.js
|
8
|
+
|
9
|
+
build-mac: install browserify
|
10
|
+
npm run build
|
11
|
+
cp -r build/mac/HelpLine.app /Applications
|
12
|
+
upload:
|
13
|
+
scp build/HelpLine-0.0.1.dmg pitecan.com:/www/www.pitecan.com/tmp/HelpLine.dmg
|
14
|
+
|
15
|
+
build-chromebook: browserify install
|
16
|
+
npm run build
|
17
|
+
|
18
|
+
#dmg: build-mac
|
19
|
+
# -/bin/rm -f HelpLine.dmg
|
20
|
+
# hdiutil create -srcfolder build/mac/HelpLine.app -volname HelpLine HelpLine.dmg
|
21
|
+
|
22
|
+
#install: npm browserify cursorpos electron
|
23
|
+
install:
|
24
|
+
npm install
|
25
|
+
|
26
|
+
electron:
|
27
|
+
npm install electron
|
28
|
+
|
29
|
+
#
|
30
|
+
# Scrapboxからデータ更新
|
31
|
+
#
|
32
|
+
update: data.js glossary.js
|
33
|
+
data.js:
|
34
|
+
ruby getdata.rb > data.js
|
35
|
+
glossary.js:
|
36
|
+
ruby getglossary.rb > glossary.js
|
37
|
+
|
38
|
+
clean:
|
39
|
+
-/bin/rm -r -f node_modules
|
40
|
+
-/bin/rm -r -f build
|
41
|
+
-/bin/rm -f HelpLine.dmg
|
42
|
+
|
43
|
+
all: update build-mac
|
data/exe/helpline
CHANGED
@@ -1,275 +1,43 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- ruby -*-
|
3
|
+
#
|
4
|
+
# HelpLineのメインプログラム
|
5
|
+
#
|
3
6
|
|
4
|
-
require 'json'
|
5
7
|
require 'optparse'
|
6
8
|
|
7
|
-
|
8
|
-
require '
|
9
|
+
$:.unshift "lib"
|
10
|
+
require 'helpline/helpline'
|
11
|
+
require 'helpline/update'
|
12
|
+
require 'helpline/generate'
|
13
|
+
require 'helpline/run'
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
# アップデート
|
16
|
+
# % helpline -u
|
17
|
+
# データを指定してアップデート
|
18
|
+
# % helpline -u HelpLine /Users/masui/ScrapboxData/masui-HelpLine.json
|
19
|
+
# テスト
|
20
|
+
# % helpline -t args
|
21
|
+
#
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
class HelpLine
|
16
|
-
LINES = 12
|
17
|
-
|
18
|
-
def datafile
|
19
|
-
File.expand_path("~/.helpline.json")
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@pagedata = {}
|
24
|
-
@project = Scrapbox::Project.new("HelpLine")
|
25
|
-
end
|
26
|
-
|
27
|
-
def getdata
|
28
|
-
#
|
29
|
-
# ページデータ取得
|
30
|
-
#
|
31
|
-
puts "-----------------ページデータを取得"
|
32
|
-
@project.pages.each { |title,page|
|
33
|
-
puts "...#{title}"
|
34
|
-
@pagedata[title] = page.text.split(/\n/)
|
35
|
-
}
|
36
|
-
|
37
|
-
dumpdata = {}
|
38
|
-
dumpdata['codes'] = []
|
39
|
-
dumpdata['defs'] = []
|
40
|
-
dumpdata['pages'] = []
|
41
|
-
|
42
|
-
#
|
43
|
-
# 関数/定数を評価"
|
44
|
-
#
|
45
|
-
puts "-----------------関数/定数を取得"
|
46
|
-
@pagedata.each { |title,pagedata|
|
47
|
-
puts "...#{title}"
|
48
|
-
pagedata. each { |line|
|
49
|
-
if line =~ /code:(.*\.rb)$/ then
|
50
|
-
src = $1
|
51
|
-
puts "=========== #{src}"
|
52
|
-
page = Scrapbox::Page.new(@project,title)
|
53
|
-
dumpdata['codes'] << page.code(src)
|
54
|
-
end
|
55
|
-
}
|
56
|
-
}
|
57
|
-
puts "-----------------HelpLineデータを検出"
|
58
|
-
@pagedata.each { |title,pagedata|
|
59
|
-
puts "...#{title}"
|
60
|
-
dumpdata['pages'] << title
|
61
|
-
processing_defs = false
|
62
|
-
codeindent = nil
|
63
|
-
pagedata.each { |line|
|
64
|
-
if !codeindent
|
65
|
-
if line =~ /^(\s*)code:/
|
66
|
-
codeindent = $1.length
|
67
|
-
next
|
68
|
-
end
|
69
|
-
else
|
70
|
-
line =~ /^(\s*)/
|
71
|
-
if line.length < codeindent
|
72
|
-
codeindent = nil
|
73
|
-
else
|
74
|
-
next
|
75
|
-
end
|
76
|
-
end
|
77
|
-
if line =~ /^\s*[\$\%]/
|
78
|
-
puts line
|
79
|
-
if line =~ /^\%/ && !processing_defs
|
80
|
-
puts "'$'で始まる用例定義なしでコマンドを定義しようとしています"
|
81
|
-
exit
|
82
|
-
end
|
83
|
-
dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
|
84
|
-
processing_defs = true
|
85
|
-
else
|
86
|
-
processing_defs = false
|
87
|
-
end
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
File.open(datafile,"w"){ |f|
|
92
|
-
f.puts dumpdata.to_json
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
def disp(list,sel)
|
97
|
-
Curses.move(0,0)
|
98
|
-
lines = list.length
|
99
|
-
lines = LINES if lines > LINES
|
100
|
-
(0...lines).each { |i|
|
101
|
-
Curses.move(i*2,0)
|
102
|
-
s = "#{list[i][0]}"
|
103
|
-
if i == sel
|
104
|
-
Curses.print_inverse s
|
105
|
-
else
|
106
|
-
Curses.print_bold s
|
107
|
-
end
|
108
|
-
Curses.move(i*2+1,0)
|
109
|
-
Curses.print " % " + list[i][1]
|
110
|
-
}
|
111
|
-
Curses.move(sel*2,0)
|
112
|
-
# Curses.down
|
113
|
-
# Curses.tol
|
114
|
-
end
|
115
|
-
|
116
|
-
def helpline(options)
|
117
|
-
data = JSON.parse(File.read(datafile))
|
118
|
-
unless data['pages'] # データ型式変換があったので
|
119
|
-
getdata
|
120
|
-
data = JSON.parse(File.read(datafile))
|
121
|
-
end
|
122
|
-
|
123
|
-
#
|
124
|
-
# 関数定義などをeval
|
125
|
-
#
|
126
|
-
data['codes'].each { |code|
|
127
|
-
eval code
|
128
|
-
}
|
129
|
-
|
130
|
-
g = ExpandRuby::Generator.new # re_expandのジェネレータ
|
131
|
-
|
132
|
-
#
|
133
|
-
# HelpLineエントリ
|
134
|
-
#
|
135
|
-
|
136
|
-
# File.open("/tmp/defs","w"){ |f| # ログを残す場合
|
137
|
-
|
138
|
-
entries = []
|
139
|
-
data['defs'].each { |line|
|
140
|
-
if line =~ /^\s*\$\s*(.*)$/ # $....
|
141
|
-
entries << $1
|
142
|
-
elsif line =~ /^\s*\%\s*(.*)$/ # %....
|
143
|
-
cmd = $1
|
144
|
-
entries.each { |l|
|
145
|
-
desc = eval('"' + l + '"')
|
146
|
-
# f.puts "desc #{desc}"
|
147
|
-
g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
|
148
|
-
}
|
149
|
-
entries = []
|
150
|
-
end
|
151
|
-
}
|
152
|
-
# }
|
153
|
-
|
154
|
-
res = g.generate " #{ARGV.join(' ').sub(/\[/,'').sub(/\]/,'')} "
|
155
|
-
|
156
|
-
File.open("/tmp/helpline.cmd","w"){ |f|
|
157
|
-
f.puts ARGV.join(' ')
|
158
|
-
}
|
159
|
-
|
160
|
-
if res[0].length == 0
|
161
|
-
puts "ヘルプがみつかりません"
|
162
|
-
exit
|
163
|
-
end
|
164
|
-
|
165
|
-
git_repository = File.exist?(".git")
|
166
|
-
listed = {}
|
167
|
-
list = res[0].find_all { |a| # 0 ambig
|
168
|
-
# a = ["現在の状況を表示する {56}", "git status {56}"], etc.
|
169
|
-
if a[0] =~ /voidvoidvoid/
|
170
|
-
false
|
171
|
-
elsif a[0] =~ /^git:/ && !git_repository
|
172
|
-
false
|
173
|
-
else
|
174
|
-
if listed[a[1]]
|
175
|
-
false
|
176
|
-
else
|
177
|
-
listed[a[1]] = true
|
178
|
-
end
|
179
|
-
end
|
180
|
-
}
|
181
|
-
|
182
|
-
if options['t'] then
|
183
|
-
puts list
|
184
|
-
exit
|
185
|
-
end
|
186
|
-
|
187
|
-
#
|
188
|
-
# HelpLineメニュー表示し、カーソル移動で選択
|
189
|
-
#
|
190
|
-
help_number = {}
|
191
|
-
list.each_with_index { |entry,ind|
|
192
|
-
entry[0].sub!(/\s*{(\d*)}$/,'')
|
193
|
-
entry[1].sub!(/\s*{(\d*)}$/,'')
|
194
|
-
help_number[entry[0]] = $1.to_i
|
195
|
-
}
|
196
|
-
|
197
|
-
sel = 0
|
198
|
-
disp(list,sel)
|
199
|
-
|
200
|
-
lines = list.length
|
201
|
-
lines = LINES if lines > LINES
|
202
|
-
|
203
|
-
inputchars = ''
|
204
|
-
while true
|
205
|
-
c = STDIN.getch
|
206
|
-
inputchars += c
|
207
|
-
|
208
|
-
if inputchars == "\e"
|
209
|
-
# process ESC
|
210
|
-
elsif inputchars[0] == "\e" && inputchars.length == 2
|
211
|
-
# 何もしない
|
212
|
-
elsif inputchars == "\x06" || inputchars == "\e[C" || inputchars == "\eOC"
|
213
|
-
# Curses.right
|
214
|
-
inputchars = ''
|
215
|
-
elsif inputchars == "\x02" || inputchars == "\e[D" || inputchars == "\eOD"
|
216
|
-
# Curses.left
|
217
|
-
inputchars = ''
|
218
|
-
elsif inputchars == "\x0e" || inputchars == "\e[B" || inputchars == "\eOB"
|
219
|
-
Curses.down
|
220
|
-
sel = (sel + 1) if sel < lines-1
|
221
|
-
inputchars = ''
|
222
|
-
elsif inputchars == "\x10" || inputchars == "\e[A" || inputchars == "\eOA"
|
223
|
-
Curses.up
|
224
|
-
sel = sel - 1 if sel > 0
|
225
|
-
inputchars = ''
|
226
|
-
else
|
227
|
-
inputchars = ''
|
228
|
-
end
|
229
|
-
STDIN.flush
|
230
|
-
disp(list,sel)
|
231
|
-
|
232
|
-
exit if c== 'q' || c == "\x03"
|
233
|
-
|
234
|
-
if c == "\r" || c == "\n"
|
235
|
-
break
|
236
|
-
end
|
237
|
-
end
|
23
|
+
helpline = HelpLine.new
|
238
24
|
|
239
|
-
|
240
|
-
cmd = list[sel][1]
|
25
|
+
options = ARGV.getopts('utds:','update','test','source:','debug')
|
241
26
|
|
242
|
-
|
243
|
-
Curses.tol
|
27
|
+
debug = options['d'] || options['debug']
|
244
28
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
File.open("/tmp/helpline.cmd","w"){ |f|
|
251
|
-
f.puts cmd
|
252
|
-
}
|
253
|
-
end
|
29
|
+
# データ更新
|
30
|
+
if options['u'] || options['update'] # ~/.helpline.json更新
|
31
|
+
sources = (ARGV.length > 0 ? ARGV : ['HelpLine'])
|
32
|
+
helpline.update sources
|
33
|
+
exit
|
254
34
|
end
|
255
35
|
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
|
260
|
-
# end
|
261
|
-
|
262
|
-
options = ARGV.getopts('ut')
|
263
|
-
|
264
|
-
helpline = HelpLine.new
|
265
|
-
|
266
|
-
if !File.exist?(helpline.datafile) && !options['u']
|
267
|
-
puts "#{helpline.datafile}を作成します..."
|
268
|
-
helpline.getdata
|
36
|
+
# テスト
|
37
|
+
if options['t'] || options['test'] # テスト
|
38
|
+
puts helpline.generate " #{ARGV.join(' ')} ", debug
|
39
|
+
exit
|
269
40
|
end
|
270
41
|
|
271
|
-
|
272
|
-
|
273
|
-
else
|
274
|
-
helpline.helpline(options)
|
275
|
-
end
|
42
|
+
query = " #{ARGV.join(' ').sub(/\[/,'').sub(/\]/,'')} "
|
43
|
+
helpline.run query, debug
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#
|
3
|
+
# * datafileを読み、引数とマッチするものをリストする
|
4
|
+
# 引数はARGVに入っている
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'json'
|
8
|
+
require 're_expand'
|
9
|
+
|
10
|
+
class HelpLine
|
11
|
+
def generate(query,debug=nil)
|
12
|
+
data = JSON.parse(File.read(datafile))
|
13
|
+
|
14
|
+
#
|
15
|
+
# 関数定義などをeval
|
16
|
+
#
|
17
|
+
data['codes'].each { |code|
|
18
|
+
eval code
|
19
|
+
}
|
20
|
+
|
21
|
+
g = ExpandRuby::Generator.new # re_expandのジェネレータ
|
22
|
+
|
23
|
+
#
|
24
|
+
# HelpLineエントリ
|
25
|
+
#
|
26
|
+
|
27
|
+
logfile = (debug ? "/tmp/helpline-defs" : "/dev/null")
|
28
|
+
File.open(logfile,"w"){ |f| # ログを残す場合
|
29
|
+
entries = []
|
30
|
+
data['defs'].each { |line|
|
31
|
+
if line =~ /^[\$\?]\s*(.*)$/ # $....
|
32
|
+
entries << $1
|
33
|
+
elsif line =~ /^\%\s*(.*)$/ # %....
|
34
|
+
cmd = $1
|
35
|
+
entries.each { |l|
|
36
|
+
desc = eval('"' + l + '"')
|
37
|
+
f.puts "desc: #{desc}"
|
38
|
+
g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
|
39
|
+
# puts "g.add(\"#{desc.force_encoding('utf-8')}\",\"#{cmd.force_encoding('utf-8')}\")"
|
40
|
+
}
|
41
|
+
f.puts "cmd: #{cmd}"
|
42
|
+
entries = []
|
43
|
+
end
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
res = g.generate query
|
48
|
+
|
49
|
+
File.open("/tmp/helpline.cmd","w"){ |f|
|
50
|
+
f.puts ARGV.join(' ')
|
51
|
+
}
|
52
|
+
|
53
|
+
if res[0].length == 0
|
54
|
+
puts "ヘルプがみつかりません"
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
git_repository = File.exist?(".git")
|
59
|
+
listed = {}
|
60
|
+
list = res[0].find_all { |a| # 0 ambig
|
61
|
+
# a = ["現在の状況を表示する {56}", "git status {56}"], etc.
|
62
|
+
if a[0] =~ /voidvoidvoid/
|
63
|
+
false
|
64
|
+
elsif a[0] =~ /^git:/ && !git_repository
|
65
|
+
false
|
66
|
+
else
|
67
|
+
if listed[a[1]]
|
68
|
+
false
|
69
|
+
else
|
70
|
+
listed[a[1]] = true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
}
|
74
|
+
|
75
|
+
list
|
76
|
+
end
|
77
|
+
end
|
data/lib/helpline/run.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#
|
3
|
+
# * HelpLineのメインルーチン
|
4
|
+
# * datafileを読み、引数とマッチするものをリストする
|
5
|
+
# 引数はARGVに入っている
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'io/console'
|
9
|
+
require 'helpline/curses'
|
10
|
+
|
11
|
+
class HelpLine
|
12
|
+
LINES = 12
|
13
|
+
|
14
|
+
def disp(list,sel)
|
15
|
+
Curses.move(0,0)
|
16
|
+
lines = list.length
|
17
|
+
lines = LINES if lines > LINES
|
18
|
+
(0...lines).each { |i|
|
19
|
+
Curses.move(i*2,0)
|
20
|
+
s = "#{list[i][0]}"
|
21
|
+
if i == sel
|
22
|
+
Curses.print_inverse s
|
23
|
+
else
|
24
|
+
Curses.print_bold s
|
25
|
+
end
|
26
|
+
Curses.move(i*2+1,0)
|
27
|
+
Curses.print " % " + list[i][1]
|
28
|
+
}
|
29
|
+
Curses.move(sel*2,0)
|
30
|
+
end
|
31
|
+
|
32
|
+
def run(query,debug=nil)
|
33
|
+
puts
|
34
|
+
|
35
|
+
list = generate(query,debug)
|
36
|
+
#
|
37
|
+
# HelpLineメニュー表示し、カーソル移動で選択
|
38
|
+
#
|
39
|
+
help_number = {}
|
40
|
+
list.each_with_index { |entry,ind|
|
41
|
+
entry[0].sub!(/\s*{(\d*)}$/,'')
|
42
|
+
entry[1].sub!(/\s*{(\d*)}$/,'')
|
43
|
+
help_number[entry[0]] = $1.to_i
|
44
|
+
}
|
45
|
+
|
46
|
+
sel = 0
|
47
|
+
disp(list,sel)
|
48
|
+
|
49
|
+
lines = list.length
|
50
|
+
lines = LINES if lines > LINES
|
51
|
+
|
52
|
+
inputchars = ''
|
53
|
+
while true
|
54
|
+
c = STDIN.getch
|
55
|
+
inputchars += c
|
56
|
+
|
57
|
+
if inputchars == "\e"
|
58
|
+
# process ESC
|
59
|
+
elsif inputchars[0] == "\e" && inputchars.length == 2
|
60
|
+
# 何もしない
|
61
|
+
elsif inputchars == "\x0e" || inputchars == "\e[B" || inputchars == "\eOB"
|
62
|
+
Curses.down
|
63
|
+
sel = (sel + 1) if sel < lines-1
|
64
|
+
inputchars = ''
|
65
|
+
elsif inputchars == "\x10" || inputchars == "\e[A" || inputchars == "\eOA"
|
66
|
+
Curses.up
|
67
|
+
sel = sel - 1 if sel > 0
|
68
|
+
inputchars = ''
|
69
|
+
else
|
70
|
+
inputchars = ''
|
71
|
+
end
|
72
|
+
STDIN.flush
|
73
|
+
disp(list,sel)
|
74
|
+
|
75
|
+
exit if c== 'q' || c == "\x03"
|
76
|
+
|
77
|
+
if c == "\r" || c == "\n"
|
78
|
+
break
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc = list[sel.to_i][0]
|
83
|
+
cmd = list[sel][1]
|
84
|
+
|
85
|
+
Curses.move(lines*2,0)
|
86
|
+
Curses.tol
|
87
|
+
|
88
|
+
#Curses.move(0,0)
|
89
|
+
##Curses.down
|
90
|
+
|
91
|
+
# Curses.print_inverse("「#{desc}」を実行")
|
92
|
+
# puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
|
93
|
+
File.open("/tmp/helpline.cmd","w"){ |f|
|
94
|
+
f.puts cmd
|
95
|
+
}
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#
|
3
|
+
# HelpLineデータを読み込んでdatafileにセーブする
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
require 'scrapbox'
|
8
|
+
|
9
|
+
class HelpLine
|
10
|
+
def update(sources) # sources = ['HelpLine', '~/ScrapboxData/masui.json', ...]
|
11
|
+
dumpdata = {}
|
12
|
+
dumpdata['codes'] = []
|
13
|
+
dumpdata['defs'] = []
|
14
|
+
dumpdata['pages'] = []
|
15
|
+
|
16
|
+
sources.each { |source|
|
17
|
+
pagedata = {}
|
18
|
+
projectname = ''
|
19
|
+
if File.exist?(source)
|
20
|
+
puts "-----------------ページデータをJSONデータ(#{source})から取得"
|
21
|
+
data = JSON.parse(File.read(source))
|
22
|
+
projectname = data['name']
|
23
|
+
data['pages'].each { |page|
|
24
|
+
title = page['title']
|
25
|
+
puts "...#{title}"
|
26
|
+
pagedata[title] = page['lines']
|
27
|
+
}
|
28
|
+
elsif source =~ /^[a-zA-Z\-]+$/ # たぶんHelpLineプロジェクト
|
29
|
+
puts "-----------------ページデータをScrapbox(#{source})から取得"
|
30
|
+
projectname = source
|
31
|
+
project = Scrapbox::Project.new(source)
|
32
|
+
project.pages.each { |title,page|
|
33
|
+
puts "...#{title}"
|
34
|
+
pagedata[title] = page.text.split(/\n/)
|
35
|
+
}
|
36
|
+
else
|
37
|
+
next
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# 関数/定数を評価"
|
42
|
+
#
|
43
|
+
puts "-----------------関数/定数を取得"
|
44
|
+
src = nil
|
45
|
+
code = []
|
46
|
+
pagedata.each { |title,lines|
|
47
|
+
# puts "...#{title}"
|
48
|
+
lines.each { |line|
|
49
|
+
if src && line =~ /^\s+/ then
|
50
|
+
code << line
|
51
|
+
elsif line =~ /^code:(.*\.rb)$/ then
|
52
|
+
if code.length > 0
|
53
|
+
puts "...#{title}"
|
54
|
+
puts code[0]
|
55
|
+
dumpdata['codes'] << code.join("\n")
|
56
|
+
end
|
57
|
+
src = $1
|
58
|
+
code = []
|
59
|
+
elsif src then
|
60
|
+
puts "...#{title}"
|
61
|
+
puts code[0]
|
62
|
+
dumpdata['codes'] << code.join("\n")
|
63
|
+
src = nil
|
64
|
+
code = []
|
65
|
+
else
|
66
|
+
end
|
67
|
+
}
|
68
|
+
if code.length > 0
|
69
|
+
puts "...#{title}"
|
70
|
+
puts code[0]
|
71
|
+
dumpdata['codes'] << code.join("\n")
|
72
|
+
src = nil
|
73
|
+
code = []
|
74
|
+
end
|
75
|
+
}
|
76
|
+
puts "-----------------HelpLineデータを検出"
|
77
|
+
pagedata.each { |title,data|
|
78
|
+
# puts "...#{title}"
|
79
|
+
dumpdata['pages'] << title
|
80
|
+
processing_defs = false
|
81
|
+
cmd_defined = false
|
82
|
+
data.each { |line|
|
83
|
+
if line =~ /^[\$\?]/
|
84
|
+
dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
|
85
|
+
cmd_defined = false
|
86
|
+
processing_defs = true
|
87
|
+
elsif line =~ /^\%/
|
88
|
+
if !processing_defs
|
89
|
+
puts "'$'で始まる用例定義なしでコマンドを定義しようとしています (#{title})"
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
|
93
|
+
cmd_defined = true
|
94
|
+
processing_defs = false
|
95
|
+
elsif processing_defs && !cmd_defined
|
96
|
+
dumpdata['defs'] << "% open 'https://Scrapbox.io/#{projectname}/#{title}' {#{dumpdata['pages'].length-1}}"
|
97
|
+
cmd_defined = false
|
98
|
+
processing_defs = false
|
99
|
+
else
|
100
|
+
cmd_defined = false
|
101
|
+
processing_defs = false
|
102
|
+
end
|
103
|
+
}
|
104
|
+
if processing_defs && !cmd_defined
|
105
|
+
dumpdata['defs'] << "% open 'https://Scrapbox.io/#{projectname}/#{title}' {#{dumpdata['pages'].length-1}}"
|
106
|
+
end
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
File.open(datafile,"w"){ |f|
|
111
|
+
f.puts dumpdata.to_json
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
data/lib/helpline/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helpline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshiyuki Masui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- HelpLine.json
|
95
95
|
- LICENSE.txt
|
96
96
|
- Makefile
|
97
|
+
- Makefile.electron
|
97
98
|
- README.md
|
98
99
|
- Rakefile
|
99
100
|
- _config.yml
|
@@ -110,6 +111,10 @@ files:
|
|
110
111
|
- keydef.zsh
|
111
112
|
- lib/helpline.rb
|
112
113
|
- lib/helpline/curses.rb
|
114
|
+
- lib/helpline/generate.rb
|
115
|
+
- lib/helpline/helpline.rb
|
116
|
+
- lib/helpline/run.rb
|
117
|
+
- lib/helpline/update.rb
|
113
118
|
- lib/helpline/version.rb
|
114
119
|
- main.js
|
115
120
|
- package.json
|