helpline 0.1.11 → 0.1.16

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,4 +1,4 @@
1
- .PHONY: data.js glossary.js
1
+ .PHONY: data.js glossary.js test
2
2
 
3
3
  run: browserify
4
4
  npm start .
@@ -49,5 +49,8 @@ all: update build-mac
49
49
  release:
50
50
  rake release
51
51
 
52
-
53
-
52
+ #
53
+ # テスト
54
+ #
55
+ test:
56
+ ruby test/test.rb
@@ -74,7 +74,7 @@ class HelpLine
74
74
  next
75
75
  end
76
76
  end
77
- if line =~ /^\s*[\$\%]/
77
+ if line =~ /^\s*[\$\%\?]/
78
78
  puts line
79
79
  if line =~ /^\%/ && !processing_defs
80
80
  puts "'$'で始まる用例定義なしでコマンドを定義しようとしています"
@@ -98,20 +98,22 @@ class HelpLine
98
98
  lines = list.length
99
99
  lines = LINES if lines > LINES
100
100
  (0...lines).each { |i|
101
- Curses.move(i,0)
102
- s = "* #{list[i][0]}"
101
+ Curses.move(i*2,0)
102
+ s = "#{list[i][0]}"
103
103
  if i == sel
104
104
  Curses.print_inverse s
105
105
  else
106
- Curses.print s
106
+ Curses.print_bold s
107
107
  end
108
+ Curses.move(i*2+1,0)
109
+ Curses.print " % " + list[i][1]
108
110
  }
109
- Curses.move(sel,0)
111
+ Curses.move(sel*2,0)
110
112
  # Curses.down
111
113
  # Curses.tol
112
114
  end
113
115
 
114
- def helpline
116
+ def helpline(options)
115
117
  data = JSON.parse(File.read(datafile))
116
118
  unless data['pages'] # データ型式変換があったので
117
119
  getdata
@@ -130,46 +132,61 @@ class HelpLine
130
132
  #
131
133
  # HelpLineエントリ
132
134
  #
135
+
136
+ # File.open("/tmp/defs","w"){ |f| # ログを残す場合
137
+
133
138
  entries = []
134
139
  data['defs'].each { |line|
135
- if line =~ /^\s*\$\s*(.*)$/ # $....
140
+ if line =~ /^\s*[\$\?]\s*(.*)$/ # $....
136
141
  entries << $1
137
142
  elsif line =~ /^\s*\%\s*(.*)$/ # %....
138
143
  cmd = $1
139
144
  entries.each { |l|
140
145
  desc = eval('"' + l + '"')
146
+ # f.puts "desc #{desc}"
141
147
  g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
142
148
  }
143
149
  entries = []
144
150
  end
145
151
  }
146
-
147
- # puts "GENERATE #{params.split('|').join(' ')} "
152
+ # }
148
153
 
149
154
  res = g.generate " #{ARGV.join(' ').sub(/\[/,'').sub(/\]/,'')} "
150
155
 
156
+ File.open("/tmp/helpline.cmd","w"){ |f|
157
+ f.puts ARGV.join(' ')
158
+ }
159
+
151
160
  if res[0].length == 0
152
161
  puts "ヘルプがみつかりません"
153
- File.open("/tmp/helpline.cmd","w"){ |f|
154
- f.puts ARGV.join(' ')
155
- }
156
162
  exit
157
163
  end
158
164
 
165
+ git_repository = File.exist?(".git")
159
166
  listed = {}
160
167
  list = res[0].find_all { |a| # 0 ambig
161
168
  # a = ["現在の状況を表示する {56}", "git status {56}"], etc.
162
- if listed[a[1]]
169
+ if a[0] =~ /voidvoidvoid/
170
+ false
171
+ elsif a[0] =~ /^git:/ && !git_repository
163
172
  false
164
173
  else
165
- listed[a[1]] = true
174
+ if listed[a[1]]
175
+ false
176
+ else
177
+ listed[a[1]] = true
178
+ end
166
179
  end
167
180
  }
168
181
 
182
+ if options['t'] then
183
+ puts list
184
+ exit
185
+ end
186
+
169
187
  #
170
188
  # HelpLineメニュー表示し、カーソル移動で選択
171
189
  #
172
-
173
190
  help_number = {}
174
191
  list.each_with_index { |entry,ind|
175
192
  entry[0].sub!(/\s*{(\d*)}$/,'')
@@ -222,13 +239,14 @@ class HelpLine
222
239
  desc = list[sel.to_i][0]
223
240
  cmd = list[sel][1]
224
241
 
225
- Curses.move(lines,0)
242
+ Curses.move(lines*2,0)
226
243
  Curses.tol
227
244
 
228
245
  #Curses.move(0,0)
229
246
  ##Curses.down
230
- Curses.print_inverse("「#{desc}」を実行")
231
- puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
247
+
248
+ # Curses.print_inverse("「#{desc}」を実行")
249
+ # puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
232
250
  File.open("/tmp/helpline.cmd","w"){ |f|
233
251
  f.puts cmd
234
252
  }
@@ -241,7 +259,7 @@ end
241
259
  # exit
242
260
  # end
243
261
 
244
- options = ARGV.getopts('u')
262
+ options = ARGV.getopts('ut')
245
263
 
246
264
  helpline = HelpLine.new
247
265
 
@@ -249,9 +267,9 @@ if !File.exist?(helpline.datafile) && !options['u']
249
267
  puts "#{helpline.datafile}を作成します..."
250
268
  helpline.getdata
251
269
  end
252
-
270
+
253
271
  if options['u'] then
254
272
  helpline.getdata
255
- else
256
- helpline.helpline
273
+ else
274
+ helpline.helpline(options)
257
275
  end
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>データが全然足りない... 特にリモートリポジトリ関連のデータは皆無だが、
data/keydef.zsh CHANGED
@@ -2,7 +2,7 @@
2
2
  # Ctrl-Jでhelplineを呼ぶようにする
3
3
  #
4
4
  function run-help() {
5
- /usr/local/bin/helpline "${BUFFER}" < $TTY
5
+ helpline "${BUFFER}" < $TTY
6
6
  BUFFER=$(cat /tmp/helpline.cmd)
7
7
  CURSOR=${#BUFFER}
8
8
  zle redisplay
@@ -105,5 +105,12 @@ class Curses
105
105
  @x += s.length
106
106
  end
107
107
 
108
+ def Curses.print_bold(s)
109
+ print "\e[0m"
110
+ print "\e[1m"
111
+ print s
112
+ print "\e[0m"
113
+ @x += s.length
114
+ end
108
115
  end
109
116
 
@@ -1,3 +1,3 @@
1
1
  module Helpline
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.16"
3
3
  end
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.1.11
4
+ version: 0.1.16
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-03 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - ".gitignore"
92
92
  - 00README
93
93
  - Gemfile
94
+ - HelpLine.json
94
95
  - LICENSE.txt
95
96
  - Makefile
96
97
  - README.md