helpline 0.1.1 → 0.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9be5d5fb60299740c6b404a5c4c8ee96bc7ac7f3d04cff7b1767cf5401a65e7e
4
- data.tar.gz: 4428ce8a6c43b5330f849ab2e6b1487cae8dcc204a0423d9d9612b83f8bbe25f
3
+ metadata.gz: 422af7721c5a7656876afee9d8809a445ef5cecb6f6fe6319146c972b1ceac76
4
+ data.tar.gz: 7ecbb73111d94497fad36b2c06b48b0c4edb04393d6fc6bb75d178548e2eb1c2
5
5
  SHA512:
6
- metadata.gz: 6a83d005aa1d6c169d10fa1c2f87248a4f9391e4d4933ce57d62a0300c8ef9f9f2ff8d0dcee0c5646be2c59dc1832713434826a38075788d392719195447bbf7
7
- data.tar.gz: e12209ee82036f5a1f91a19d53b8c5c487612f860ba36a70a5e8ad27639070e860c547360de14faab5f21a046cc27a749620d615c96032ce644b466da97fc691
6
+ metadata.gz: 2eb4f60cbb105f55f39e30c59b98c87f2de276389b1c3a7a0727ad8bbd2c3ea40607ad2efda38567736411943fb9f1312387d9f95c31def0199ca5e8ef7ab84c
7
+ data.tar.gz: 65c85fc591eb453afe07a053bb28573b12ff9d8919f9baa5b906a9f9ac6e05256482b38b53c0029cb220491c21832b9298355005ccd37fb75f99d7cecade0037
data/.gitignore CHANGED
@@ -5,3 +5,6 @@ build/
5
5
  package-lock.json
6
6
  *.dmg
7
7
  *_browserify.js
8
+ pkg/
9
+
10
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ Electron版(JS)とRuby版(gem版)が一緒になっているので良くない...
@@ -8,7 +8,7 @@ require 'scrapbox'
8
8
  require 're_expand'
9
9
 
10
10
  require 'io/console'
11
- require './curses'
11
+ require 'helpline/curses'
12
12
 
13
13
  puts
14
14
 
@@ -16,7 +16,7 @@ class HelpLine
16
16
  LINES = 12
17
17
 
18
18
  def datafile
19
- File.expand_path("~/.helpline")
19
+ File.expand_path("~/.helpline.json")
20
20
  end
21
21
 
22
22
  def initialize
@@ -149,7 +149,7 @@ class HelpLine
149
149
 
150
150
  if res[0].length == 0
151
151
  puts "ヘルプがみつかりません"
152
- File.open("/tmp/helpline","w"){ |f|
152
+ File.open("/tmp/helpline.cmd","w"){ |f|
153
153
  f.puts ARGV.join(' ')
154
154
  }
155
155
  exit
@@ -188,17 +188,17 @@ class HelpLine
188
188
  # process ESC
189
189
  elsif inputchars[0] == "\e" && inputchars.length == 2
190
190
  # 何もしない
191
- elsif inputchars == "\x06" || inputchars == "\e[C"
191
+ elsif inputchars == "\x06" || inputchars == "\e[C" || inputchars == "\eOC"
192
192
  # Curses.right
193
193
  inputchars = ''
194
- elsif inputchars == "\x02" || inputchars == "\e[D"
194
+ elsif inputchars == "\x02" || inputchars == "\e[D" || inputchars == "\eOD"
195
195
  # Curses.left
196
196
  inputchars = ''
197
- elsif inputchars == "\x0e" || inputchars == "\e[B"
197
+ elsif inputchars == "\x0e" || inputchars == "\e[B" || inputchars == "\eOB"
198
198
  Curses.down
199
199
  sel = (sel + 1) if sel < LINES-1
200
200
  inputchars = ''
201
- elsif inputchars == "\x10" || inputchars == "\e[A"
201
+ elsif inputchars == "\x10" || inputchars == "\e[A" || inputchars == "\eOA"
202
202
  Curses.up
203
203
  sel = sel - 1 if sel > 0
204
204
  inputchars = ''
@@ -220,7 +220,7 @@ class HelpLine
220
220
 
221
221
  Curses.print_inverse("「#{desc}」を実行")
222
222
  puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
223
- File.open("/tmp/helpline","w"){ |f|
223
+ File.open("/tmp/helpline.cmd","w"){ |f|
224
224
  f.puts cmd
225
225
  }
226
226
  end
data/keydef.zsh CHANGED
@@ -1,8 +1,9 @@
1
1
  #
2
- # Ctrl-Hでhelplineを呼ぶようにする
2
+ # Ctrl-Jでhelplineを呼ぶようにする
3
3
  #
4
4
  function run-help() {
5
- BUFFER=$(/Applications/HelpLine.app/Contents/MacOS/helpline "${BUFFER}")
5
+ /usr/local/bin/helpline "${BUFFER}" < $TTY
6
+ BUFFER=$(cat /tmp/helpline.cmd)
6
7
  CURSOR=${#BUFFER}
7
8
  zle redisplay
8
9
  }
@@ -1,4 +1,7 @@
1
-
1
+ #
2
+ # カーソル移動ライブラリ
3
+ # cursesを使うほどではないので
4
+ #
2
5
 
3
6
  # ESC [ Pl A
4
7
  # カーソルをPl行上へ移動
@@ -1,3 +1,3 @@
1
1
  module Helpline
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helpline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiyuki Masui
@@ -89,13 +89,13 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - 00README
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - Makefile
95
96
  - README.md
96
97
  - Rakefile
97
98
  - _config.yml
98
- - curses.rb
99
99
  - data.js
100
100
  - exe/helpline
101
101
  - getdata.rb
@@ -105,10 +105,10 @@ files:
105
105
  - helpline.gemspec
106
106
  - helpline.html
107
107
  - helpline.js
108
- - helpline.rb
109
108
  - index.html
110
109
  - keydef.zsh
111
110
  - lib/helpline.rb
111
+ - lib/helpline/curses.rb
112
112
  - lib/helpline/version.rb
113
113
  - main.js
114
114
  - package.json
@@ -1,248 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- ruby -*-
3
-
4
- require 'json'
5
- require 'optparse'
6
-
7
- require 'scrapbox'
8
- require 're_expand'
9
-
10
- require 'io/console'
11
- require './curses'
12
-
13
- puts
14
-
15
- class HelpLine
16
- LINES = 12
17
-
18
- def datafile
19
- File.expand_path("~/.helpline")
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 = "[#{i}] #{list[i][0]}"
103
- if i == sel
104
- Curses.print_inverse s
105
- else
106
- Curses.print s
107
- end
108
- }
109
- Curses.down
110
- Curses.tol
111
- end
112
-
113
- def helpline
114
- data = JSON.parse(File.read(datafile))
115
- unless data['pages'] # データ型式変換があったので
116
- getdata
117
- data = JSON.parse(File.read(datafile))
118
- end
119
-
120
- #
121
- # 関数定義などをeval
122
- #
123
- data['codes'].each { |code|
124
- eval code
125
- }
126
-
127
- g = ExpandRuby::Generator.new # re_expandのジェネレータ
128
-
129
- #
130
- # HelpLineエントリ
131
- #
132
- lines = []
133
- data['defs'].each { |line|
134
- if line =~ /^\s*\$\s*(.*)$/ # $....
135
- lines << $1
136
- elsif line =~ /^\s*\%\s*(.*)$/ # %....
137
- cmd = $1
138
- lines.each { |l|
139
- desc = eval('"' + l + '"')
140
- g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
141
- }
142
- lines = []
143
- end
144
- }
145
-
146
- # puts "GENERATE #{params.split('|').join(' ')} "
147
-
148
- res = g.generate " #{ARGV.join(' ').sub(/\[/,'').sub(/\]/,'')} "
149
-
150
- if res[0].length == 0
151
- puts "ヘルプがみつかりません"
152
- File.open("/tmp/helpline","w"){ |f|
153
- f.puts ARGV.join(' ')
154
- }
155
- exit
156
- end
157
-
158
- listed = {}
159
- list = res[0].find_all { |a| # 0 ambig
160
- # a = ["現在の状況を表示する {56}", "git status {56}"], etc.
161
- if listed[a[1]]
162
- false
163
- else
164
- listed[a[1]] = true
165
- end
166
- }
167
-
168
- #
169
- # HelpLineメニュー表示し、カーソル移動で選択
170
- #
171
-
172
- help_number = {}
173
- list.each_with_index { |entry,ind|
174
- entry[0].sub!(/\s*{(\d*)}$/,'')
175
- entry[1].sub!(/\s*{(\d*)}$/,'')
176
- help_number[entry[0]] = $1.to_i
177
- }
178
-
179
- sel = 0
180
- disp(list,sel)
181
-
182
- inputchars = ''
183
- while true
184
- c = STDIN.getch
185
- inputchars += c
186
-
187
- if inputchars == "\e"
188
- # process ESC
189
- elsif inputchars[0] == "\e" && inputchars.length == 2
190
- # 何もしない
191
- elsif inputchars == "\x06" || inputchars == "\e[C"
192
- # Curses.right
193
- inputchars = ''
194
- elsif inputchars == "\x02" || inputchars == "\e[D"
195
- # Curses.left
196
- inputchars = ''
197
- elsif inputchars == "\x0e" || inputchars == "\e[B"
198
- Curses.down
199
- sel = (sel + 1) if sel < LINES-1
200
- inputchars = ''
201
- elsif inputchars == "\x10" || inputchars == "\e[A"
202
- Curses.up
203
- sel = sel - 1 if sel > 0
204
- inputchars = ''
205
- else
206
- inputchars = ''
207
- end
208
- STDIN.flush
209
- disp(list,sel)
210
-
211
- exit if c== 'q' || c == "\x03"
212
-
213
- if c == "\r" || c == "\n"
214
- break
215
- end
216
- end
217
-
218
- desc = list[sel.to_i][0]
219
- cmd = list[sel][1]
220
-
221
- Curses.print_inverse("「#{desc}」を実行")
222
- puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
223
- File.open("/tmp/helpline","w"){ |f|
224
- f.puts cmd
225
- }
226
- end
227
- end
228
-
229
- # is_repository = system 'git rev-parse --git-dir > /dev/null >& /dev/null'
230
- # unless is_repository
231
- # STDERR.puts "Gitレポジトリで実行して下さい"
232
- # exit
233
- # end
234
-
235
- options = ARGV.getopts('u')
236
-
237
- helpline = HelpLine.new
238
-
239
- if !File.exist?(helpline.datafile) && !options['u']
240
- puts "#{helpline.datafile}を作成します..."
241
- helpline.getdata
242
- end
243
-
244
- if options['u'] then
245
- helpline.getdata
246
- else
247
- helpline.helpline
248
- end