helpline 0.1.2 → 0.1.7
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 +4 -4
- data/.gitignore +3 -0
- data/00README +1 -0
- data/exe/helpline +11 -10
- data/keydef.zsh +3 -2
- data/lib/helpline/curses.rb +4 -1
- data/lib/helpline/version.rb +1 -1
- metadata +2 -2
- data/helpline.rb +0 -248
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4796cced1ca30fb1effb576492307234872655a7fbc7daa4581c5f8cf3deb1c4
|
4
|
+
data.tar.gz: 9765b91769a092835c9f2c9d42fd2de068cdc9eb4119b5f0a6f08ea8bbf04d54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f2b9ea43201159fddb09c7b9b3f51f5f514037a9b9d0d6c5928f241acf4b8d11198cd9d4b9dc1fcb0bfbbe8294d9f274a78f7ae27352f57d3143dd4cd860236
|
7
|
+
data.tar.gz: a0b7b42b1b39b92a5db2025d192215af4be319b16e51386a9e75ebbe9ff078c9a02750cb91d6108f047201c1d1e556c4100e4541b9a2e6d14642fd8d86705d61
|
data/.gitignore
CHANGED
data/00README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Electron版(JS)とRuby版(gem版)が一緒になっているので良くない...
|
data/exe/helpline
CHANGED
@@ -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
|
@@ -99,15 +99,16 @@ class HelpLine
|
|
99
99
|
lines = LINES if lines > LINES
|
100
100
|
(0...lines).each { |i|
|
101
101
|
Curses.move(i,0)
|
102
|
-
s = "
|
102
|
+
s = "* #{list[i][0]}"
|
103
103
|
if i == sel
|
104
104
|
Curses.print_inverse s
|
105
105
|
else
|
106
106
|
Curses.print s
|
107
107
|
end
|
108
108
|
}
|
109
|
-
Curses.
|
110
|
-
Curses.
|
109
|
+
Curses.move(sel,0)
|
110
|
+
# Curses.down
|
111
|
+
# Curses.tol
|
111
112
|
end
|
112
113
|
|
113
114
|
def helpline
|
@@ -149,7 +150,7 @@ class HelpLine
|
|
149
150
|
|
150
151
|
if res[0].length == 0
|
151
152
|
puts "ヘルプがみつかりません"
|
152
|
-
File.open("/tmp/helpline","w"){ |f|
|
153
|
+
File.open("/tmp/helpline.cmd","w"){ |f|
|
153
154
|
f.puts ARGV.join(' ')
|
154
155
|
}
|
155
156
|
exit
|
@@ -188,17 +189,17 @@ class HelpLine
|
|
188
189
|
# process ESC
|
189
190
|
elsif inputchars[0] == "\e" && inputchars.length == 2
|
190
191
|
# 何もしない
|
191
|
-
elsif inputchars == "\x06" || inputchars == "\e[C"
|
192
|
+
elsif inputchars == "\x06" || inputchars == "\e[C" || inputchars == "\eOC"
|
192
193
|
# Curses.right
|
193
194
|
inputchars = ''
|
194
|
-
elsif inputchars == "\x02" || inputchars == "\e[D"
|
195
|
+
elsif inputchars == "\x02" || inputchars == "\e[D" || inputchars == "\eOD"
|
195
196
|
# Curses.left
|
196
197
|
inputchars = ''
|
197
|
-
elsif inputchars == "\x0e" || inputchars == "\e[B"
|
198
|
+
elsif inputchars == "\x0e" || inputchars == "\e[B" || inputchars == "\eOB"
|
198
199
|
Curses.down
|
199
200
|
sel = (sel + 1) if sel < LINES-1
|
200
201
|
inputchars = ''
|
201
|
-
elsif inputchars == "\x10" || inputchars == "\e[A"
|
202
|
+
elsif inputchars == "\x10" || inputchars == "\e[A" || inputchars == "\eOA"
|
202
203
|
Curses.up
|
203
204
|
sel = sel - 1 if sel > 0
|
204
205
|
inputchars = ''
|
@@ -220,7 +221,7 @@ class HelpLine
|
|
220
221
|
|
221
222
|
Curses.print_inverse("「#{desc}」を実行")
|
222
223
|
puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
|
223
|
-
File.open("/tmp/helpline","w"){ |f|
|
224
|
+
File.open("/tmp/helpline.cmd","w"){ |f|
|
224
225
|
f.puts cmd
|
225
226
|
}
|
226
227
|
end
|
data/keydef.zsh
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#
|
2
|
-
# Ctrl-
|
2
|
+
# Ctrl-Jでhelplineを呼ぶようにする
|
3
3
|
#
|
4
4
|
function run-help() {
|
5
|
-
|
5
|
+
/usr/local/bin/helpline "${BUFFER}" < $TTY
|
6
|
+
BUFFER=$(cat /tmp/helpline.cmd)
|
6
7
|
CURSOR=${#BUFFER}
|
7
8
|
zle redisplay
|
8
9
|
}
|
data/lib/helpline/curses.rb
CHANGED
data/lib/helpline/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.7
|
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
|
data/helpline.rb
DELETED
@@ -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
|