helpline 0.1.14 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Makefile CHANGED
@@ -1,53 +1,17 @@
1
- .PHONY: data.js glossary.js
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
1
  #
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
44
-
45
-
46
- #
47
- # gem
2
+ # Gem版
48
3
  #
49
4
  release:
50
5
  rake release
51
6
 
7
+ update:
8
+ helpline --update
52
9
 
10
+ update-local:
11
+ helpline --update --debug --source ~/ScrapboxData/HelpLine.json,~/ScrapboxData/masui-helpline.json
53
12
 
13
+ #
14
+ # テスト
15
+ #
16
+ test:
17
+ ruby test/test.rb
@@ -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
@@ -1,261 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- ruby -*-
3
3
 
4
- require 'json'
5
4
  require 'optparse'
6
5
 
7
- require 'scrapbox'
8
- require 're_expand'
6
+ $:.unshift "lib"
7
+ require 'helpline/helpline'
8
+ require 'helpline/update'
9
+ require 'helpline/generate'
10
+ require 'helpline/run'
9
11
 
10
- require 'io/console'
11
- require 'helpline/curses'
12
+ # アップデート
13
+ # % helpline -u
14
+ # データを指定してアップデート
15
+ # % helpline -u HelpLine /Users/masui/ScrapboxData/masui-HelpLine.json
16
+ # テスト
17
+ # % helpline -t args
18
+ #
12
19
 
13
- puts
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,0)
102
- s = "* #{list[i][0]}"
103
- if i == sel
104
- Curses.print_inverse s
105
- else
106
- Curses.print s
107
- end
108
- }
109
- Curses.move(sel,0)
110
- # Curses.down
111
- # Curses.tol
112
- end
113
-
114
- def helpline
115
- data = JSON.parse(File.read(datafile))
116
- unless data['pages'] # データ型式変換があったので
117
- getdata
118
- data = JSON.parse(File.read(datafile))
119
- end
120
-
121
- #
122
- # 関数定義などをeval
123
- #
124
- data['codes'].each { |code|
125
- eval code
126
- }
127
-
128
- g = ExpandRuby::Generator.new # re_expandのジェネレータ
129
-
130
- #
131
- # HelpLineエントリ
132
- #
133
- entries = []
134
- data['defs'].each { |line|
135
- if line =~ /^\s*\$\s*(.*)$/ # $....
136
- entries << $1
137
- elsif line =~ /^\s*\%\s*(.*)$/ # %....
138
- cmd = $1
139
- entries.each { |l|
140
- desc = eval('"' + l + '"')
141
- g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
142
- }
143
- entries = []
144
- end
145
- }
146
-
147
- res = g.generate " #{ARGV.join(' ').sub(/\[/,'').sub(/\]/,'')} "
148
-
149
- File.open("/tmp/helpline.cmd","w"){ |f|
150
- f.puts ARGV.join(' ')
151
- }
152
- if res[0].length == 0
153
- puts "ヘルプがみつかりません"
154
- exit
155
- end
156
-
157
- git_repository = File.exist?(".git")
158
- listed = {}
159
- list = res[0].find_all { |a| # 0 ambig
160
- # a = ["現在の状況を表示する {56}", "git status {56}"], etc.
161
- if a[0] =~ /voidvoidvoid/
162
- false
163
- elsif a[0] =~ /^git:/ && !git_repository
164
- false
165
- else
166
- if listed[a[1]]
167
- false
168
- else
169
- listed[a[1]] = true
170
- end
171
- end
172
- }
173
-
174
- #
175
- # HelpLineメニュー表示し、カーソル移動で選択
176
- #
177
- help_number = {}
178
- list.each_with_index { |entry,ind|
179
- entry[0].sub!(/\s*{(\d*)}$/,'')
180
- entry[1].sub!(/\s*{(\d*)}$/,'')
181
- help_number[entry[0]] = $1.to_i
182
- }
183
-
184
- sel = 0
185
- disp(list,sel)
186
-
187
- lines = list.length
188
- lines = LINES if lines > LINES
189
-
190
- inputchars = ''
191
- while true
192
- c = STDIN.getch
193
- inputchars += c
194
-
195
- if inputchars == "\e"
196
- # process ESC
197
- elsif inputchars[0] == "\e" && inputchars.length == 2
198
- # 何もしない
199
- elsif inputchars == "\x06" || inputchars == "\e[C" || inputchars == "\eOC"
200
- # Curses.right
201
- inputchars = ''
202
- elsif inputchars == "\x02" || inputchars == "\e[D" || inputchars == "\eOD"
203
- # Curses.left
204
- inputchars = ''
205
- elsif inputchars == "\x0e" || inputchars == "\e[B" || inputchars == "\eOB"
206
- Curses.down
207
- sel = (sel + 1) if sel < lines-1
208
- inputchars = ''
209
- elsif inputchars == "\x10" || inputchars == "\e[A" || inputchars == "\eOA"
210
- Curses.up
211
- sel = sel - 1 if sel > 0
212
- inputchars = ''
213
- else
214
- inputchars = ''
215
- end
216
- STDIN.flush
217
- disp(list,sel)
218
-
219
- exit if c== 'q' || c == "\x03"
220
-
221
- if c == "\r" || c == "\n"
222
- break
223
- end
224
- end
225
-
226
- desc = list[sel.to_i][0]
227
- cmd = list[sel][1]
20
+ helpline = HelpLine.new
228
21
 
229
- Curses.move(lines,0)
230
- Curses.tol
22
+ options = ARGV.getopts('utds:','update','test','source:','debug')
231
23
 
232
- #Curses.move(0,0)
233
- ##Curses.down
234
- Curses.print_inverse("「#{desc}」を実行")
235
- puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
236
- File.open("/tmp/helpline.cmd","w"){ |f|
237
- f.puts cmd
238
- }
239
- end
24
+ #
25
+ # update
26
+ #
27
+ if options['u'] || options['update'] # ~/.helpline.json更新
28
+ sources = (ARGV.length > 0 ? ARGV : ['HelpLine'])
29
+ helpline.update sources
30
+ exit
240
31
  end
241
32
 
242
- # is_repository = system 'git rev-parse --git-dir > /dev/null >& /dev/null'
243
- # unless is_repository
244
- # STDERR.puts "Gitレポジトリで実行して下さい"
245
- # exit
246
- # end
247
-
248
- options = ARGV.getopts('u')
249
-
250
- helpline = HelpLine.new
251
-
252
- if !File.exist?(helpline.datafile) && !options['u']
253
- puts "#{helpline.datafile}を作成します..."
254
- helpline.getdata
255
- end
256
-
257
- if options['u'] then
258
- helpline.getdata
259
- else
260
- helpline.helpline
33
+ if options['t'] || options['test'] # テスト
34
+ puts helpline.generate " #{ARGV.join(' ')} "
35
+ exit
261
36
  end
37
+
38
+ debug = options['d'] || options['debug']
39
+ query = " #{ARGV.join(' ').sub(/\[/,'').sub(/\]/,'')} "
40
+ helpline.run query, debug
data/index.html CHANGED
@@ -20,16 +20,13 @@
20
20
  <section class="main-content">
21
21
 
22
22
  <center>
23
- <video src="https://s3-ap-northeast-1.amazonaws.com/masui.org/d/b/db555e8535ff111e794b95e6d3d7a8f5.mp4" width=600 controls></video>
23
+ <video src="https://s3-ap-northeast-1.amazonaws.com/masui.org/b/9/b9b2ae65a3a977857b5487f280785b47.mp4" width=600 controls></video>
24
24
  </center>
25
25
 
26
- <p>
27
- 以下、GitHelpのテキストをコピペしただけなのでHelpLineの説明になってません。すみません
28
- </p>
29
-
30
- <p>
31
-  Gitのような複雑なシステムは使い方が難しい。
32
- ある程度使い方を知っている場合でも、あまり一般的でない機能を使うのは難しい。
26
+ <p></p>
27
+
28
+  コマンドラインのオプションは難しいものが多い。
29
+ Gitのような複雑なシステムの場合、概念もオプションも難しい。
33
30
  たとえば以下のような場合はどういうコマンドを使えばいいだろうか?
34
31
  </p>
35
32
 
@@ -170,19 +167,19 @@
170
167
  誰でも情報を足したり修正したりできたら嬉しいだろう。
171
168
  </p>
172
169
 
173
- <h3>GitHelpのアプローチ</h3>
170
+ <h3>HelpLineのアプローチ</h3>
174
171
 
175
172
  <p>
176
-  GitHelpは、以下のような方針で上のような課題をすべて解決しようというものである。
173
+  HelpLineは、以下のような方針で上のような課題をすべて解決しようというものである。
177
174
 
178
175
  <ul>
179
176
  <li>ユーザのあらゆる曖昧な表現にマッチするようにヘルプ文字列を正規表現で表現し、
180
- Gitコマンドに変換する</li>
177
+ コマンドに変換する</li>
181
178
  - ExpandHelp(<a href="https://github.com/masui/expand-ruby">ソース</a> /
182
179
  <a href="http://www.interaction-ipsj.org/archives/paper2012/data/Interaction2012/oral/data/pdf/12INT012.pdf">論文</a>)を利用
183
180
  <li>データをすべてクラウド上に置いて編集可能にすることにより、
184
181
  誰でもデータを追加/修正できるようにする</li>
185
- - <a href="https://Scrapbox.io/GitHelp">Scrapbox</a>を利用
182
+ - <a href="https://Scrapbox.io/HelpLine">Scrapbox</a>を利用
186
183
  <li>ユーザが指定したパラメタはそのまま利用して実行に使う</li>
187
184
  - ユーザが「4」「時間」などと指定すると「時刻を4時にセットする」のようなものを提案して実行可能にする
188
185
  <li>多少の誤入力を許す</li>
@@ -193,43 +190,48 @@
193
190
 
194
191
  <h3>利用例</h3>
195
192
 
196
- Gitに関連するタスクのキーワードやパラメタを指定して
197
- <code>githelp</code>を起動すると
198
- 候補のリストが表示され、
193
+ タスクのキーワードやパラメタを指定してCtrl-Jを押すと
194
+ <code>helpline</code>が起動して候補のリストが表示され、
199
195
  カーソルで選択すると実行される。
200
196
 
201
197
  <ul>
202
- <li><code>$ githelp 2 README</code>のように引数を指定して起動すると以下のような候補リストが提示される</li>
203
-
204
- <img src="https://gyazo.com/6cc87cef5f28185199074b61716454de.png" width=500>
198
+ <li><code>$ 2 README</code>と入力してからCtrl-Jを押すと
199
+ 以下のような候補リストが提示される</li>
205
200
 
201
+ <img src="https://gyazo.com/806cb4c2c14781465949ec3aa85d563b.png" width=500>
206
202
  <p></p>
207
203
  <li>カーソルで選択してリターンを押すと実行される</li>
208
204
 
209
- <img src="https://gyazo.com/75c14885944c33f2671474b008120262.png" width=500>
205
+ <img src="https://gyazo.com/b72f97a2664d504c5465fd11bac92184.png" width=700>
210
206
  </ul>
211
207
 
212
208
  <a name="install"><h3>インストール</h3></a>
213
-
214
- <pre>
215
- % gem install githelp </pre>
216
-
209
+
217
210
  <ul>
218
- <li>対話的処理のために<a href="https://github.com/peco/peco">peco</a>が必要</li>
219
- <ul>
220
- <li>Macだと<code>% brew install peco</code>でインストール可能</li>
221
- <li>Linuxなどの場合<a href="https://github.com/peco/peco/releases">こちら</a>のファイルからインストール (yumなどでは入らない)</li>
222
- </ul>
211
+ <li> <code>gem</code>でHelpLineをインストール
212
+ <pre>
213
+ % gem install helpline</pre>
214
+ </li>
215
+ <li> <code>~/.zshrc</code>に以下の記述を追加
216
+ <pre>
217
+ function run-help() {
218
+ helpline "${BUFFER}" < $TTY
219
+ BUFFER=$(cat /tmp/helpline.cmd)
220
+ CURSOR=${#BUFFER}
221
+ zle redisplay
222
+ }
223
+ zle -N run-help
224
+ bindkey "^j" run-help</pre>
225
+ </li>
223
226
  </ul>
224
227
 
225
228
  <h3>実装</h3>
226
-
227
229
  <ul>
228
230
  <li><a href="https://github.com/masui/expand_ruby">re_expand</a>
229
231
  という正規表現展開ライブラリを利用</li>
230
232
  <li><a href="https://Scrapbox.io/GitHelp">Scrapbox</a>にあらゆる情報を書いておく</li>
231
233
  <br>
232
- <img src="https://gyazo.com/b4ba42a96617c65db32020eb1ea19bf3.png" width=450>
234
+ <img src="https://gyazo.com/cd1529fe082c57d4295e8660ba3cb932.png" width=550>
233
235
  <li>
234
236
  様々なタスクの説明と実際の操作を組にして記述しておき、
235
237
  ユーザが与えたキーワードやパラメタにマッチするものを
@@ -259,23 +261,11 @@
259
261
  翻訳作業があまり気にならないものなのかもしれないが、
260
262
  そういう「翻訳」は少ない方が良いのは確かだろう。
261
263
  </li>
262
- <li>そういえば先日「らくらくホン」画面に出てくる鬱陶しい「羊」を消す方法が全くわからなかったのだが、
263
- あれは「マチキャラ」と呼ばれるものなので
264
- 「マチキャラ」を消すという操作が必要だった。
265
- お前はMSのイルカか。
266
- 「羊 消す」とか「消す」とかで消せるべきだろう。
267
- githelpでは <code>$ githelp 削除</code> と入力すれば削除関連で何ができるのかわかるだろうし、
268
- <code>(鬱陶しい|不快な)羊を(消す|殺す)</code>
269
- のようなエントリをユーザが足すこともできるだろう。
270
- </li>
271
- <img src="http://service.smt.docomo.ne.jp/site/iconcier/img/iconcier_ptl_cha_img01.png" width=300>
272
- <li>というわけで<b>Gitは単なる適用例であり、広い範囲で使いたいと思っている。</b></li>
273
264
  </ul>
274
265
 
275
266
  <h3> 注意</h3>
276
267
 
277
268
  <ul>
278
- <li><code>githelp</code>コマンドはGitリポジトリのディレクトリで実行する必要がある</li>
279
269
  <li><a href="https://github.com/masui/expand_ruby">re_expand</a>の実装が富豪的なので
280
270
  大きなリポジトリだと不具合があるかも</li>
281
271
  <li>データが全然足りない... 特にリモートリポジトリ関連のデータは皆無だが、