helpline 0.1.3 → 0.1.4

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: 5dd76874e2f807e8190fd36cee7663e1069a5a768d0c0173960e6851ab8af2e4
4
- data.tar.gz: 719d6aca5decbc28ca1090e509f382a9ffabac116e665173a4cb725688d7d6e2
3
+ metadata.gz: b0104ffa24a5e308f511265b3d573e071fa62f8a20f47395d860ccaad49c61b8
4
+ data.tar.gz: 327ed27a2cdb89ff7e3dfc1d493a30b5fdaab9ff14532217c9c2180453646d12
5
5
  SHA512:
6
- metadata.gz: a843524971789cd37936b9fe53110704851ce219f9addd944f7032a12ff767c493e57d00f84a79b39e5989b89079e9e0caf408ed380fc0122f30ce364d44af91
7
- data.tar.gz: 8a369398fc30e8f69343327c96758808f970658e9187abff97eb4f430fd3d6e869af727ac3bb9c0d47ec038b04443ca18f7177b25d6cc41a12f0f5c5e0d4b04f
6
+ metadata.gz: c62a6cebf987469aa8851ad2bf2a61bfe84727488275f1ee249b914ea57291d65c401e9bb5793b151f29c58f0206a18b7e0f8f168a1d4d345740582c44f2b4b2
7
+ data.tar.gz: de05a2efb87c6cb738b672124082097f7a49e176868575be736733cbe661c15e99d9f6ff38aba1dab21eabe54848485dfef4bdc8d74dd174ad3ff94fd21b78b3
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版)が一緒になっているので良くない...
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Helpline
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiyuki Masui
@@ -89,6 +89,7 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - 00README
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - Makefile
@@ -104,7 +105,6 @@ files:
104
105
  - helpline.gemspec
105
106
  - helpline.html
106
107
  - helpline.js
107
- - helpline.rb
108
108
  - index.html
109
109
  - keydef.zsh
110
110
  - lib/helpline.rb
@@ -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" || inputchars == "\eOC"
192
- # Curses.right
193
- inputchars = ''
194
- elsif inputchars == "\x02" || inputchars == "\e[D" || inputchars == "\eOD"
195
- # Curses.left
196
- inputchars = ''
197
- elsif inputchars == "\x0e" || inputchars == "\e[B" || inputchars == "\eOB"
198
- Curses.down
199
- sel = (sel + 1) if sel < LINES-1
200
- inputchars = ''
201
- elsif inputchars == "\x10" || inputchars == "\e[A" || inputchars == "\eOA"
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