helpline 0.1.14 → 0.2.1

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/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
 
@@ -0,0 +1,76 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # * datafileを読み、引数とマッチするものをリストする
4
+ # 引数はARGVに入っている
5
+ #
6
+
7
+ require 'json'
8
+ require 're_expand'
9
+
10
+ class HelpLine
11
+ def generate(query,debug=nil)
12
+ data = JSON.parse(File.read(datafile))
13
+
14
+ #
15
+ # 関数定義などをeval
16
+ #
17
+ data['codes'].each { |code|
18
+ eval code
19
+ }
20
+
21
+ g = ExpandRuby::Generator.new # re_expandのジェネレータ
22
+
23
+ #
24
+ # HelpLineエントリ
25
+ #
26
+
27
+ logfile = (debug ? "/tmp/helpline-defs" : "/dev/null")
28
+ File.open(logfile,"w"){ |f| # ログを残す場合
29
+ entries = []
30
+ data['defs'].each { |line|
31
+ if line =~ /^[\$\?]\s*(.*)$/ # $....
32
+ entries << $1
33
+ elsif line =~ /^\%\s*(.*)$/ # %....
34
+ cmd = $1
35
+ entries.each { |l|
36
+ desc = eval('"' + l + '"')
37
+ f.puts "desc: #{desc}"
38
+ g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
39
+ }
40
+ f.puts "cmd: #{cmd}"
41
+ entries = []
42
+ end
43
+ }
44
+ }
45
+
46
+ res = g.generate query
47
+
48
+ File.open("/tmp/helpline.cmd","w"){ |f|
49
+ f.puts ARGV.join(' ')
50
+ }
51
+
52
+ if res[0].length == 0
53
+ puts "ヘルプがみつかりません"
54
+ exit
55
+ end
56
+
57
+ git_repository = File.exist?(".git")
58
+ listed = {}
59
+ list = res[0].find_all { |a| # 0 ambig
60
+ # a = ["現在の状況を表示する {56}", "git status {56}"], etc.
61
+ if a[0] =~ /voidvoidvoid/
62
+ false
63
+ elsif a[0] =~ /^git:/ && !git_repository
64
+ false
65
+ else
66
+ if listed[a[1]]
67
+ false
68
+ else
69
+ listed[a[1]] = true
70
+ end
71
+ end
72
+ }
73
+
74
+ list
75
+ end
76
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+
4
+ class HelpLine
5
+ def datafile
6
+ File.expand_path("~/.helpline.json")
7
+ end
8
+ end
@@ -0,0 +1,97 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # * HelpLineのメインルーチン
4
+ # * datafileを読み、引数とマッチするものをリストする
5
+ # 引数はARGVに入っている
6
+ #
7
+
8
+ require 'io/console'
9
+ require 'helpline/curses'
10
+
11
+ class HelpLine
12
+ LINES = 12
13
+
14
+ def disp(list,sel)
15
+ Curses.move(0,0)
16
+ lines = list.length
17
+ lines = LINES if lines > LINES
18
+ (0...lines).each { |i|
19
+ Curses.move(i*2,0)
20
+ s = "#{list[i][0]}"
21
+ if i == sel
22
+ Curses.print_inverse s
23
+ else
24
+ Curses.print_bold s
25
+ end
26
+ Curses.move(i*2+1,0)
27
+ Curses.print " % " + list[i][1]
28
+ }
29
+ Curses.move(sel*2,0)
30
+ end
31
+
32
+ def run(query,debug=nil)
33
+ puts
34
+
35
+ list = generate(query,debug)
36
+ #
37
+ # HelpLineメニュー表示し、カーソル移動で選択
38
+ #
39
+ help_number = {}
40
+ list.each_with_index { |entry,ind|
41
+ entry[0].sub!(/\s*{(\d*)}$/,'')
42
+ entry[1].sub!(/\s*{(\d*)}$/,'')
43
+ help_number[entry[0]] = $1.to_i
44
+ }
45
+
46
+ sel = 0
47
+ disp(list,sel)
48
+
49
+ lines = list.length
50
+ lines = LINES if lines > LINES
51
+
52
+ inputchars = ''
53
+ while true
54
+ c = STDIN.getch
55
+ inputchars += c
56
+
57
+ if inputchars == "\e"
58
+ # process ESC
59
+ elsif inputchars[0] == "\e" && inputchars.length == 2
60
+ # 何もしない
61
+ elsif inputchars == "\x0e" || inputchars == "\e[B" || inputchars == "\eOB"
62
+ Curses.down
63
+ sel = (sel + 1) if sel < lines-1
64
+ inputchars = ''
65
+ elsif inputchars == "\x10" || inputchars == "\e[A" || inputchars == "\eOA"
66
+ Curses.up
67
+ sel = sel - 1 if sel > 0
68
+ inputchars = ''
69
+ else
70
+ inputchars = ''
71
+ end
72
+ STDIN.flush
73
+ disp(list,sel)
74
+
75
+ exit if c== 'q' || c == "\x03"
76
+
77
+ if c == "\r" || c == "\n"
78
+ break
79
+ end
80
+ end
81
+
82
+ desc = list[sel.to_i][0]
83
+ cmd = list[sel][1]
84
+
85
+ Curses.move(lines*2,0)
86
+ Curses.tol
87
+
88
+ #Curses.move(0,0)
89
+ ##Curses.down
90
+
91
+ # Curses.print_inverse("「#{desc}」を実行")
92
+ # puts " (ソース: http://scrapbox.io/HelpLine/#{data['pages'][help_number[desc]]})"
93
+ File.open("/tmp/helpline.cmd","w"){ |f|
94
+ f.puts cmd
95
+ }
96
+ end
97
+ end
@@ -0,0 +1,111 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # HelpLineデータを読み込んでdatafileにセーブする
4
+ #
5
+
6
+ require 'json'
7
+ require 'scrapbox'
8
+
9
+ class HelpLine
10
+ def update(sources) # sources = ['HelpLine', '~/ScrapboxData/masui.json', ...]
11
+ dumpdata = {}
12
+ dumpdata['codes'] = []
13
+ dumpdata['defs'] = []
14
+ dumpdata['pages'] = []
15
+
16
+ sources.each { |source|
17
+ pagedata = {}
18
+ if File.exist?(source)
19
+ puts "-----------------ページデータをJSONデータ(#{source})から取得"
20
+ data = JSON.parse(File.read(source))
21
+ data['pages'].each { |page|
22
+ title = page['title']
23
+ puts "...#{title}"
24
+ pagedata[title] = page['lines']
25
+ }
26
+ elsif source =~ /^[a-zA-Z\-]+$/ # たぶんHelpLineプロジェクト
27
+ puts "-----------------ページデータをScrapbox(#{source})から取得"
28
+ project = Scrapbox::Project.new(source)
29
+ project.pages.each { |title,page|
30
+ puts "...#{title}"
31
+ pagedata[title] = page.text.split(/\n/)
32
+ }
33
+ else
34
+ next
35
+ end
36
+
37
+ #
38
+ # 関数/定数を評価"
39
+ #
40
+ puts "-----------------関数/定数を取得"
41
+ src = nil
42
+ code = []
43
+ pagedata.each { |title,lines|
44
+ # puts "...#{title}"
45
+ lines.each { |line|
46
+ if src && line =~ /^\s+/ then
47
+ code << line
48
+ elsif line =~ /^code:(.*\.rb)$/ then
49
+ if code.length > 0
50
+ puts "...#{title}"
51
+ puts code[0]
52
+ dumpdata['codes'] << code.join("\n")
53
+ end
54
+ src = $1
55
+ code = []
56
+ elsif src then
57
+ puts "...#{title}"
58
+ puts code[0]
59
+ dumpdata['codes'] << code.join("\n")
60
+ src = nil
61
+ code = []
62
+ else
63
+ end
64
+ }
65
+ if code.length > 0
66
+ puts "...#{title}"
67
+ puts code[0]
68
+ dumpdata['codes'] << code.join("\n")
69
+ src = nil
70
+ code = []
71
+ end
72
+ }
73
+ puts "-----------------HelpLineデータを検出"
74
+ pagedata.each { |title,pagedata|
75
+ # puts "...#{title}"
76
+ dumpdata['pages'] << title
77
+ processing_defs = false
78
+ codeindent = nil
79
+ pagedata.each { |line|
80
+ if !codeindent
81
+ if line =~ /^code:/
82
+ codeindent = 0
83
+ next
84
+ end
85
+ else
86
+ line =~ /^(\s*)/
87
+ if $1.length < codeindent + 1
88
+ codeindent = nil
89
+ else
90
+ next
91
+ end
92
+ end
93
+ if line =~ /^[\$\%\?]/
94
+ if line =~ /^\%/ && !processing_defs
95
+ puts "'$'で始まる用例定義なしでコマンドを定義しようとしています"
96
+ exit
97
+ end
98
+ dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
99
+ processing_defs = true
100
+ else
101
+ processing_defs = false
102
+ end
103
+ }
104
+ }
105
+ }
106
+
107
+ File.open(datafile,"w"){ |f|
108
+ f.puts dumpdata.to_json
109
+ }
110
+ end
111
+ end
@@ -1,3 +1,3 @@
1
1
  module Helpline
2
- VERSION = "0.1.14"
2
+ VERSION = "0.2.1"
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.14
4
+ version: 0.2.1
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-04 00:00:00.000000000 Z
11
+ date: 2020-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,8 +91,10 @@ files:
91
91
  - ".gitignore"
92
92
  - 00README
93
93
  - Gemfile
94
+ - HelpLine.json
94
95
  - LICENSE.txt
95
96
  - Makefile
97
+ - Makefile.electron
96
98
  - README.md
97
99
  - Rakefile
98
100
  - _config.yml
@@ -109,6 +111,10 @@ files:
109
111
  - keydef.zsh
110
112
  - lib/helpline.rb
111
113
  - lib/helpline/curses.rb
114
+ - lib/helpline/generate.rb
115
+ - lib/helpline/helpline.rb
116
+ - lib/helpline/run.rb
117
+ - lib/helpline/update.rb
112
118
  - lib/helpline/version.rb
113
119
  - main.js
114
120
  - package.json