helpline 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 267bd0196064dc182896a4e031db4da50a354117d670459f4fd25a8f3fd966b3
4
- data.tar.gz: 50b312aa455fe920fcbb3ebbc883730dcb61776d1ddf31e696134be0c604fc40
3
+ metadata.gz: 3e2b93dc79e46d3eeb5f2867f20f42d1e188aecf6e81128b9819d01f97e65132
4
+ data.tar.gz: 18d0062e75b35b3dc88ca362818928e2ba456996fd1dd48a3383a5ba1c0a8ac4
5
5
  SHA512:
6
- metadata.gz: 7d1319a55f1202a129871688f9132ec099cf8b7ad1c4a4002f6c566cea53d9db005d2b96ca2d870a947c364fea5f58304026c52f1bf9e0d88a1f529ebc27f932
7
- data.tar.gz: 3cd64a1e71c308f4358c6ebee71101e05345c017bfcefc617bfdba92cff75213534c73cd7d42dc9702e7adc6f28359c31a62ca523880cec5cf8b4590239985b1
6
+ metadata.gz: 6610decc65beb0c5bbfd1a05075ed6e77f4f0ab18a96ae6f6c9c7584d145ce27499f1c318679a083ca1105a52d8ebac855c04398dc8f9e62722cbb940e6510d4
7
+ data.tar.gz: ae28a2b29a2aa21a06e758ecd38fa280411f3f62ea38bb070c9cc63bb3f6b3e5fbfe015fc180264666b0557978c932c210c45a34731dd50457ee6c64c88a5f8b
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 = ''
@@ -14,15 +14,6 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://masui.github.io/HelpLine/"
15
15
  spec.license = "MIT"
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- #if spec.respond_to?(:metadata)
20
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
- #else
22
- # raise "RubyGems 2.0 or newer is required to protect against " \
23
- # "public gem pushes."
24
- #end
25
-
26
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
18
  f.match(%r{^(test|spec|features)/})
28
19
  end
@@ -33,4 +24,7 @@ Gem::Specification.new do |spec|
33
24
  spec.add_development_dependency "bundler", "~> 1.15"
34
25
  spec.add_development_dependency "rake", "~> 10.0"
35
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ spec.add_runtime_dependency "re_expand"
29
+ spec.add_runtime_dependency "scrapbox"
36
30
  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.0"
2
+ VERSION = "0.1.5"
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.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiyuki Masui
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: re_expand
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: scrapbox
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: HelpLine - show command help menu from keywords, using ExpandHelp.
56
84
  email:
57
85
  - masui@pitecan.com
@@ -61,13 +89,13 @@ extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
91
  - ".gitignore"
92
+ - 00README
64
93
  - Gemfile
65
94
  - LICENSE.txt
66
95
  - Makefile
67
96
  - README.md
68
97
  - Rakefile
69
98
  - _config.yml
70
- - curses.rb
71
99
  - data.js
72
100
  - exe/helpline
73
101
  - getdata.rb
@@ -77,10 +105,10 @@ files:
77
105
  - helpline.gemspec
78
106
  - helpline.html
79
107
  - helpline.js
80
- - helpline.rb
81
108
  - index.html
82
109
  - keydef.zsh
83
110
  - lib/helpline.rb
111
+ - lib/helpline/curses.rb
84
112
  - lib/helpline/version.rb
85
113
  - main.js
86
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