ver 2009.10.14 → 2009.11.28
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1094 -0
- data/MANIFEST +227 -25
- data/README.textile +185 -0
- data/bin/ver +96 -12
- data/config/detect.rb +73 -21
- data/config/keymap/emacs.rb +66 -0
- data/config/keymap/vim.rb +250 -140
- data/config/preferences/ANTLR.json +10 -0
- data/config/preferences/ASP vb.NET.json +3 -0
- data/config/preferences/ASP.json +15 -0
- data/config/preferences/ActionScript.json +755 -0
- data/config/preferences/Active4D.json +89 -0
- data/config/preferences/Ada.json +23 -0
- data/config/preferences/Ant.json +356 -0
- data/config/preferences/Apache.json +644 -0
- data/config/preferences/AppleScript.json +92 -0
- data/config/preferences/Bison.json +3 -0
- data/config/preferences/Blogging.json +3 -0
- data/config/preferences/C.json +127 -0
- data/config/preferences/CMake.json +41 -0
- data/config/preferences/CSS.json +461 -0
- data/config/preferences/CTags.json +3 -0
- data/config/preferences/CVS.json +3 -0
- data/config/preferences/ColdFusion.json +32 -0
- data/config/preferences/D.json +58 -0
- data/config/preferences/Darcs.json +3 -0
- data/config/preferences/Diff.json +67 -0
- data/config/preferences/DokuWiki.json +19 -0
- data/config/preferences/Doxygen.json +3 -0
- data/config/preferences/Dylan.json +3 -0
- data/config/preferences/Eiffel.json +59 -0
- data/config/preferences/Erlang.json +72 -0
- data/config/preferences/Experimental.json +1356 -0
- data/config/preferences/F-Script.json +87 -0
- data/config/preferences/FXScript.json +78 -0
- data/config/preferences/FileMerge.json +3 -0
- data/config/preferences/Fortran.json +158 -0
- data/config/preferences/GTD2.json +11 -0
- data/config/preferences/GTDAlt.json +20 -0
- data/config/preferences/GetBundle.json +3 -0
- data/config/preferences/Gettext.json +24 -0
- data/config/preferences/Graphviz.json +42 -0
- data/config/preferences/Greasemonkey.json +3 -0
- data/config/preferences/Gri.json +34 -0
- data/config/preferences/HTML.json +492 -0
- data/config/preferences/Haskell.json +72 -0
- data/config/preferences/Hotkey.json +3 -0
- data/config/preferences/ImageBrowser.json +3 -0
- data/config/preferences/Inform.json +3 -0
- data/config/preferences/Ini.json +60 -0
- data/config/preferences/Installer.json +3 -0
- data/config/preferences/Io.json +64 -0
- data/config/preferences/JSON.json +3 -0
- data/config/preferences/Java.json +86 -0
- data/config/preferences/JavaDoc.json +3 -0
- data/config/preferences/JavaScript.json +76 -0
- data/config/preferences/LaTeX.json +267 -0
- data/config/preferences/Lex/Flex.json +3 -0
- data/config/preferences/Lighttpd.json +3 -0
- data/config/preferences/LilyPond.json +77 -0
- data/config/preferences/Lisp.json +63 -0
- data/config/preferences/Logo.json +58 -0
- data/config/preferences/Logtalk.json +236 -0
- data/config/preferences/Lua.json +24 -0
- data/config/preferences/MEL.json +19 -0
- data/config/preferences/MIPS Assembler.json +26 -0
- data/config/preferences/MacPorts.json +3 -0
- data/config/preferences/Mail.json +3 -0
- data/config/preferences/Make.json +16 -0
- data/config/preferences/Markdown.json +102 -0
- data/config/preferences/Math.json +3 -0
- data/config/preferences/Matlab.json +128 -0
- data/config/preferences/Maven.json +308 -0
- data/config/preferences/Mediawiki.json +73 -0
- data/config/preferences/Mercurial.json +3 -0
- data/config/preferences/Modula.json +37 -0
- data/config/preferences/MoinMoin.json +52 -0
- data/config/preferences/Navigation.json +3 -0
- data/config/preferences/Nemerle.json +3 -0
- data/config/preferences/OCaml Code Completion.json +3 -0
- data/config/preferences/OCaml.json +163 -0
- data/config/preferences/ODCompletion.json +3 -0
- data/config/preferences/Objective-C.json +84 -0
- data/config/preferences/OpenGL.json +3331 -0
- data/config/preferences/Outlines.json +3 -0
- data/config/preferences/Pascal.json +60 -0
- data/config/preferences/Perforce.json +3 -0
- data/config/preferences/Perl.json +15 -0
- data/config/preferences/PmWiki.json +27 -0
- data/config/preferences/Postscript.json +15 -0
- data/config/preferences/Processing.json +32 -0
- data/config/preferences/Prolog.json +3 -0
- data/config/preferences/Propel.json +3 -0
- data/config/preferences/Python.json +38 -0
- data/config/preferences/Quake.json +15 -0
- data/config/preferences/R.json +33 -0
- data/config/preferences/Ragel.json +15 -0
- data/config/preferences/Regular Expressions.json +3 -0
- data/config/preferences/Remind.json +15 -0
- data/config/preferences/Rez.json +46 -0
- data/config/preferences/Ruby.json +98 -0
- data/config/preferences/S5 Slide Show.json +20 -0
- data/config/preferences/SCons.json +3 -0
- data/config/preferences/SQL.json +32 -0
- data/config/preferences/SSH Config.json +15 -0
- data/config/preferences/SVK.json +3 -0
- data/config/preferences/SWIG.json +3 -0
- data/config/preferences/SWeave.json +32 -0
- data/config/preferences/Scheme.json +35 -0
- data/config/preferences/Scilab.json +15 -0
- data/config/preferences/Setext.json +3 -0
- data/config/preferences/Shell Script.json +25 -0
- data/config/preferences/Slate.json +113 -0
- data/config/preferences/Source.json +132 -0
- data/config/preferences/Subversion.json +10 -0
- data/config/preferences/TODO.json +3 -0
- data/config/preferences/Tabular.json +3 -0
- data/config/preferences/Tcl.json +82 -0
- data/config/preferences/TerminalMate.json +112 -0
- data/config/preferences/Text.json +89 -0
- data/config/preferences/TextMate.json +38 -0
- data/config/preferences/Textile.json +76 -0
- data/config/preferences/Thrift.json +56 -0
- data/config/preferences/Transmit.json +3 -0
- data/config/preferences/Twiki.json +51 -0
- data/config/preferences/Txt2tags.json +81 -0
- data/config/preferences/Vectorscript.json +1280 -0
- data/config/preferences/XML.json +60 -0
- data/config/preferences/Xcode.json +3 -0
- data/config/preferences/YAML.json +24 -0
- data/config/preferences/iCalendar.json +10 -0
- data/config/preferences/iTerm.json +36 -0
- data/config/preferences/reStructuredText.json +48 -0
- data/config/rc.rb +49 -0
- data/config/syntax/ANTLR.json +5 -5
- data/config/syntax/{ASP VB.net.json → ASP vb.NET.json } +3 -3
- data/config/syntax/ASP.json +1 -1
- data/config/syntax/ActionScript.json +6 -6
- data/config/syntax/Active4D Config.json +86 -0
- data/config/syntax/Active4D Library.json +20 -0
- data/config/syntax/Active4D.json +418 -0
- data/config/syntax/Ada.json +3 -3
- data/config/syntax/Ant.json +196 -0
- data/config/syntax/Apache.json +7 -7
- data/config/syntax/AppleScript.json +3 -3
- data/config/syntax/{Bibtex.json → BibTeX.json} +1 -1
- data/config/syntax/Bison.json +59 -0
- data/config/syntax/{Blog (HTML).json → Blog - HTML.json } +2 -2
- data/config/syntax/{Blog (Markdown).json → Blog - Markdown.json } +2 -2
- data/config/syntax/Blog (Text).json b/data/config/syntax/Blog - → Text.json +0 -0
- data/config/syntax/Blog (Textile).json b/data/config/syntax/Blog - → Textile.json +0 -0
- data/config/syntax/C++.json +3 -3
- data/config/syntax/C.json +13 -13
- data/config/syntax/CMake Listfile.json +171 -0
- data/config/syntax/CSS.json +6 -6
- data/config/syntax/CSV.json +108 -0
- data/config/syntax/ColdFusion.json +204 -0
- data/config/syntax/D.json +560 -0
- data/config/syntax/Diff.json +1 -1
- data/config/syntax/DokuWiki.json +412 -0
- data/config/syntax/Doxygen.json +80 -0
- data/config/syntax/Dylan.json +4 -4
- data/config/syntax/Erlang.json +5 -5
- data/config/syntax/F-Script.json +1 -1
- data/config/syntax/FXScript.json +5 -5
- data/config/syntax/Fortran - Modern.json +221 -0
- data/config/syntax/Fortran - Punchcard.json +468 -0
- data/config/syntax/GTD.json +39 -0
- data/config/syntax/GTDalt.json +233 -0
- data/config/syntax/Gettext.json +118 -0
- data/config/syntax/Go.json +555 -0
- data/config/syntax/{DOT.json → Graphviz (DOT).json } +3 -3
- data/config/syntax/Greasemonkey.json +56 -0
- data/config/syntax/Gri.json +4 -4
- data/config/syntax/{HTML-ASP.json → HTML (ASP).json } +1 -1
- data/config/syntax/{HTML for ASP.net.json → HTML (ASP.net).json } +19 -19
- data/config/syntax/HTML (Active4D).json +540 -0
- data/config/syntax/HTML (Erlang).json +31 -0
- data/config/syntax/HTML (Tcl).json +1 -1
- data/config/syntax/HTML.json +20 -20
- data/config/syntax/Haskell.json +3 -3
- data/config/syntax/Installer Distribution Script.json +135 -0
- data/config/syntax/Io.json +6 -6
- data/config/syntax/JSON.json +151 -0
- data/config/syntax/{JavaProperties.json → Java Properties.json } +2 -2
- data/config/syntax/Java Server Page (JSP).json +163 -0
- data/config/syntax/Java.json +7 -7
- data/config/syntax/JavaDoc.json +435 -0
- data/config/syntax/JavaScript.json +8 -8
- data/config/syntax/LaTeX Log.json +3 -3
- data/config/syntax/LaTeX Memoir.json +101 -0
- data/config/syntax/LaTeX.json +2 -2
- data/config/syntax/Lex-Flex.json +396 -0
- data/config/syntax/LilyPond.json +608 -0
- data/config/syntax/Logo.json +48 -0
- data/config/syntax/Logtalk.json +6 -6
- data/config/syntax/Lua.json +1 -1
- data/config/syntax/{M.json → MATLAB.json} +3 -3
- data/config/syntax/MEL.json +7 -7
- data/config/syntax/MIPS.json b/data/config/syntax/MIPS → Assembler.json +0 -0
- data/config/syntax/MacPorts Portfile.json +298 -0
- data/config/syntax/Mail.json +1 -1
- data/config/syntax/Markdown.json +6 -6
- data/config/syntax/Maven POM.json +774 -0
- data/config/syntax/Mediawiki.json +736 -0
- data/config/syntax/MoinMoin.json +335 -0
- data/config/syntax/MultiMarkdown.json +41 -0
- data/config/syntax/Nemerle.json +128 -0
- data/config/syntax/OCaml.json +4 -4
- data/config/syntax/OCamllex.json +307 -0
- data/config/syntax/OCamlyacc.json +346 -0
- data/config/syntax/Objective-C++.json +2 -2
- data/config/syntax/Objective-C.json +979 -0
- data/config/syntax/Octave.json +417 -0
- data/config/syntax/PHP.json +32 -32
- data/config/syntax/Pascal.json +1 -1
- data/config/syntax/Perl.json +8 -8
- data/config/syntax/{Plain text.json → Plain Text.json } +1 -1
- data/config/syntax/PmWiki.json +241 -0
- data/config/syntax/Postscript.json +206 -0
- data/config/syntax/Processing.json +8 -8
- data/config/syntax/Prolog.json +70 -0
- data/config/syntax/Python.json +1934 -0
- data/config/syntax/{Quake3 Config.json → Quake Style .cfg.json } +1 -1
- data/config/syntax/R.json +2 -2
- data/config/syntax/Ragel.json +362 -0
- data/config/syntax/Rd (R Documentation).json +119 -0
- data/config/syntax/Regular Expressions (Oniguruma).json +186 -0
- data/config/syntax/Regular Expressions (Python).json +188 -0
- data/config/syntax/Release Notes.json +78 -0
- data/config/syntax/Remind.json +461 -0
- data/config/syntax/Rez.json +5 -5
- data/config/syntax/Ruby Sass.json +497 -0
- data/config/syntax/Ruby.json +13 -13
- data/config/syntax/S5 Slide Show.json +85 -0
- data/config/syntax/SQL.json +11 -11
- data/config/syntax/SSH Config.json +55 -0
- data/config/syntax/SWIG.json +2 -2
- data/config/syntax/SWeave.json +139 -0
- data/config/syntax/Scheme.json +8 -8
- data/config/syntax/Scilab.json +69 -0
- data/config/syntax/Setext.json +247 -0
- data/config/syntax/{Shell-Unix-Generic.json → Shell Script (Bash).json } +4 -4
- data/config/syntax/Slate.json +5 -5
- data/config/syntax/Strings File.json +53 -0
- data/config/syntax/TSV.json +83 -0
- data/config/syntax/Tcl.json +1 -1
- data/config/syntax/TeX Math.json +2 -2
- data/config/syntax/TeX.json +2 -2
- data/config/syntax/Textile.json +9 -9
- data/config/syntax/Thrift.json +641 -0
- data/config/syntax/Twiki.json +1 -1
- data/config/syntax/Txt2tags.json +154 -0
- data/config/syntax/XML strict.json +4 -4
- data/config/syntax/XML.json +6 -6
- data/config/syntax/XSL.json +2 -2
- data/config/syntax/camlp4.json +63 -0
- data/config/syntax/mod_perl.json +72 -0
- data/config/syntax/reStructuredText.json +1 -1
- data/config/syntax/{Subversion commit message.json → svn-commit.tmp.json} +0 -0
- data/config/tutorial +23 -19
- data/config/welcome +3 -3
- data/lib/ver.rb +273 -62
- data/lib/ver/entry.rb +142 -26
- data/lib/ver/font.rb +51 -0
- data/lib/ver/help.rb +16 -0
- data/lib/ver/help/describe_key.rb +82 -0
- data/lib/ver/help/help_for_help.rb +39 -0
- data/lib/ver/hover_completion.rb +129 -0
- data/lib/ver/keymap.rb +95 -24
- data/lib/ver/layout.rb +107 -43
- data/lib/ver/methods.rb +24 -8
- data/lib/ver/methods/clipboard.rb +91 -0
- data/lib/ver/methods/completion.rb +146 -71
- data/lib/ver/methods/control.rb +203 -222
- data/lib/ver/methods/ctags.rb +55 -0
- data/lib/ver/methods/delete.rb +30 -0
- data/lib/ver/methods/help.rb +7 -0
- data/lib/ver/methods/insert.rb +233 -1
- data/lib/ver/methods/move.rb +181 -32
- data/lib/ver/methods/open.rb +208 -0
- data/lib/ver/methods/preview.rb +14 -0
- data/lib/ver/methods/save.rb +111 -0
- data/lib/ver/methods/search.rb +57 -7
- data/lib/ver/methods/select.rb +97 -17
- data/lib/ver/methods/shortcuts.rb +21 -0
- data/lib/ver/methods/views.rb +56 -1
- data/lib/ver/mode.rb +60 -14
- data/lib/ver/status.rb +97 -19
- data/lib/ver/syntax.rb +14 -6
- data/lib/ver/syntax/detector.rb +16 -5
- data/lib/ver/syntax/processor.rb +9 -3
- data/lib/ver/text.rb +258 -199
- data/lib/ver/text/index.rb +103 -0
- data/lib/ver/theme.rb +27 -16
- data/lib/ver/tooltip.rb +59 -0
- data/lib/ver/vendor/binary_search.rb +61 -0
- data/lib/ver/vendor/levenshtein.rb +57 -0
- data/lib/ver/{textpow.rb → vendor/textpow.rb} +31 -29
- data/lib/ver/view.rb +65 -41
- data/lib/ver/view/console.rb +171 -0
- data/lib/ver/view/entry.rb +9 -5
- data/lib/ver/view/list.rb +44 -29
- data/lib/ver/view/list/ex.rb +71 -0
- data/lib/ver/view/list/grep.rb +42 -0
- data/lib/ver/view/list/methods.rb +159 -0
- data/lib/ver/view/term.rb +249 -0
- data/tasks/syntax_list.rake +3 -2
- data/ver.gemspec +4 -4
- metadata +230 -28
- data/config/syntax/Bulletin Board.json +0 -428
- data/config/syntax/HTML (Mason).json +0 -207
- data/config/syntax/HTML (Rails).json +0 -52
- data/config/syntax/Movable Type.json +0 -348
- data/config/syntax/Ruby on Rails.json +0 -170
- data/config/syntax/SQL (Rails).json +0 -31
- data/config/syntax/Smarty.json +0 -110
- data/config/syntax/Standard ML.json +0 -322
@@ -0,0 +1,71 @@
|
|
1
|
+
module VER
|
2
|
+
class View::List::Ex < View::List
|
3
|
+
def initialize(parent, filter, &callback)
|
4
|
+
@filter = filter
|
5
|
+
@previous = ''
|
6
|
+
@propose = nil
|
7
|
+
super(parent, &callback)
|
8
|
+
end
|
9
|
+
|
10
|
+
def update
|
11
|
+
value = entry.value
|
12
|
+
|
13
|
+
if value =~ /\s/
|
14
|
+
completion
|
15
|
+
else
|
16
|
+
list.value = @filter.call(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def pick_selection
|
21
|
+
if @propose
|
22
|
+
pick_action(@command, @propose)
|
23
|
+
else
|
24
|
+
pick_action(entry.value)
|
25
|
+
end
|
26
|
+
|
27
|
+
destroy
|
28
|
+
end
|
29
|
+
|
30
|
+
def completion
|
31
|
+
value = entry.value
|
32
|
+
command, arg = value.split(' ', 2)
|
33
|
+
complete_command(command, arg)
|
34
|
+
end
|
35
|
+
|
36
|
+
def complete_command(command, arg)
|
37
|
+
name = "complete_#{command}"
|
38
|
+
|
39
|
+
if respond_to?(name)
|
40
|
+
possible = send(name, arg)
|
41
|
+
list.value = possible
|
42
|
+
completed = complete_arg(arg, possible)
|
43
|
+
@command, @propose = command, completed
|
44
|
+
entry.value = "#{command} #{completed}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def complete_arg(arg, possible)
|
49
|
+
case possible.size
|
50
|
+
when 0
|
51
|
+
return arg
|
52
|
+
when 1
|
53
|
+
return possible.first
|
54
|
+
else
|
55
|
+
require 'abbrev'
|
56
|
+
abbrev = possible.abbrev
|
57
|
+
|
58
|
+
if found = abbrev[arg]
|
59
|
+
return found
|
60
|
+
else
|
61
|
+
return abbrev.keys.sort_by{|k| k.size }.first[0..-2]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def complete_e(value)
|
67
|
+
Dir["#{value}*"].map{|f| File.directory?(f) ? "#{f}/" : f }
|
68
|
+
end
|
69
|
+
alias complete_o complete_e
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module VER
|
2
|
+
class View::List::Grep < View::List
|
3
|
+
def update
|
4
|
+
list.clear
|
5
|
+
|
6
|
+
grep(entry.value).each do |choice|
|
7
|
+
list.insert(:end, "#{choice[:match]} -- #{choice[:file]} +#{choice[:line]}")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def pick_action(entry)
|
12
|
+
index = list.curselection.first
|
13
|
+
choice = @choices[index]
|
14
|
+
callback.call(*choice.values_at(:file, :line))
|
15
|
+
end
|
16
|
+
|
17
|
+
def grep(input)
|
18
|
+
@choices = []
|
19
|
+
|
20
|
+
input, query = input.split(/ /, 2)
|
21
|
+
input, query = nil, input unless query
|
22
|
+
input ||= '*'
|
23
|
+
|
24
|
+
return [] if !query || query.size < 3 # protect a little
|
25
|
+
|
26
|
+
regex = /#{Regexp.escape(query)}/
|
27
|
+
|
28
|
+
Dir.glob input do |file|
|
29
|
+
next unless ::File.file?(file)
|
30
|
+
|
31
|
+
File.open file do |io|
|
32
|
+
io.each_line.with_index do |line, idx|
|
33
|
+
next unless line =~ regex
|
34
|
+
@choices << {file: file, line: idx, match: line.strip}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return @choices
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'ver/vendor/levenshtein'
|
2
|
+
|
3
|
+
module VER
|
4
|
+
# Show methods based on patterns.
|
5
|
+
#
|
6
|
+
# TODO: Handle C and evaled methods.
|
7
|
+
# Once 1.9.2 is out, use Method#parameters.
|
8
|
+
class View::List::Methods < View::List
|
9
|
+
def update
|
10
|
+
list.value = update_choices.map{|choice|
|
11
|
+
method, score = choice.values_at(:method, :score)
|
12
|
+
" #{score} #{method.owner}.#{method.name}"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def pick_action(entry)
|
17
|
+
index = list.curselection.first
|
18
|
+
choice = @choices[index]
|
19
|
+
|
20
|
+
return unless method = choice[:method]
|
21
|
+
|
22
|
+
if location = method.source_location
|
23
|
+
filename, line = location
|
24
|
+
|
25
|
+
if ::File.file?(filename)
|
26
|
+
callback.call(filename, line)
|
27
|
+
else
|
28
|
+
# defined by clumsy eval
|
29
|
+
end
|
30
|
+
else
|
31
|
+
# C method?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def insert_choice(choice)
|
36
|
+
method, score = choice.values_at(:method, :score)
|
37
|
+
owner, name = method.owner, method.name
|
38
|
+
|
39
|
+
list.insert :end, " #{score} #{owner}.#{name}"
|
40
|
+
return
|
41
|
+
|
42
|
+
owner, name, parameters = method.owner, method.name, method.parameters
|
43
|
+
|
44
|
+
params = []
|
45
|
+
|
46
|
+
method.parameters.each do |param|
|
47
|
+
case param.first
|
48
|
+
when :req
|
49
|
+
params << param.last
|
50
|
+
when :opt
|
51
|
+
params << "?#{param.last}"
|
52
|
+
when :block
|
53
|
+
params << "&#{param.last}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
params = params.join(', ')
|
58
|
+
|
59
|
+
list.insert :end, " #{score} #{owner}.#{name}(#{params})"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Intelligent method grepper, tries to find matching methods for a wide
|
63
|
+
# range of input, by distributing scores.
|
64
|
+
#
|
65
|
+
# Possible input might be:
|
66
|
+
#
|
67
|
+
# Window.y
|
68
|
+
# Window y
|
69
|
+
# Window::y
|
70
|
+
# Window#y
|
71
|
+
# VER y
|
72
|
+
# VER::View::File#copy
|
73
|
+
# VER::View::File.copy
|
74
|
+
# VER::View::File::copy
|
75
|
+
#
|
76
|
+
# The matching is very tolerant, so you can search for methods in
|
77
|
+
# completely different namespaces but still get good results:
|
78
|
+
#
|
79
|
+
# VER.delta
|
80
|
+
# # => VER::Buffer.apply_delta
|
81
|
+
# # => VER::Buffer.apply_deltas
|
82
|
+
# # => VER::Cursor.delta
|
83
|
+
#
|
84
|
+
# sort
|
85
|
+
# # => VER::Cursor.boundary_sort
|
86
|
+
#
|
87
|
+
# VER.ask
|
88
|
+
# # => #<Class:VER>.ask
|
89
|
+
# # => VER::View::File::Methods.buffer_ask
|
90
|
+
# # => VER::View::File::Methods.execute_ask
|
91
|
+
# # => VER::View::File::Methods.execute_ask_context
|
92
|
+
# # => VER::View::File::Methods.filter_selection_ask
|
93
|
+
# # => VER::View::File::Methods.goto_line_ask
|
94
|
+
# # => #<Class:FFI::NCurses>.mousemask
|
95
|
+
# # => VER::View::File::Methods.save_as_ask
|
96
|
+
# # => VER::View::File::Methods.search_ask
|
97
|
+
# # => VER::View::File::Methods.search_ask_context
|
98
|
+
#
|
99
|
+
# We are only using string comparisions to find matches, so input is
|
100
|
+
# never interpreted as a regular expression and can include anything
|
101
|
+
# without having to worry about special meaning within a regexp.
|
102
|
+
#
|
103
|
+
# There are some improvments possible (as usual).
|
104
|
+
# In particular the scoring should become more accurate for short
|
105
|
+
# methods, for example making adjustments when a method starts or ends
|
106
|
+
# with the search string.
|
107
|
+
def update_choices
|
108
|
+
@choices = []
|
109
|
+
|
110
|
+
needle = entry.value.split(/::|[#.\s]+/)
|
111
|
+
owner = needle.join('::')
|
112
|
+
name = needle.last.to_s
|
113
|
+
|
114
|
+
methods_of VER do |namespace, method|
|
115
|
+
mnamespace = namespace.to_s
|
116
|
+
mowner, mname = method.owner.to_s, method.name.to_s
|
117
|
+
smowner = mowner.split('::')
|
118
|
+
|
119
|
+
score = 0
|
120
|
+
score += (needle & smowner).size
|
121
|
+
if mname.include?(name)
|
122
|
+
distance = Levenshtein.distance(mname, name)
|
123
|
+
score += ([mname, name].max_by{|n| n.size }.size - distance)
|
124
|
+
end
|
125
|
+
|
126
|
+
next if score == 0
|
127
|
+
|
128
|
+
@choices << {namespace: namespace, method: method, score: score}
|
129
|
+
end
|
130
|
+
|
131
|
+
@choices = @choices.sort_by{|hash| [-hash[:score], hash[:method].name] }
|
132
|
+
end
|
133
|
+
|
134
|
+
def methods_of(namespace, seen = [], &block)
|
135
|
+
return if seen.include?(namespace)
|
136
|
+
seen << namespace
|
137
|
+
|
138
|
+
if namespace.respond_to?(:instance_methods)
|
139
|
+
namespace.instance_methods(false).each do |name|
|
140
|
+
yield namespace, namespace.instance_method(name)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
if namespace.respond_to?(:singleton_methods)
|
145
|
+
namespace.singleton_methods(false).each do |name|
|
146
|
+
yield namespace, namespace.method(name)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if namespace.respond_to?(:constants)
|
151
|
+
namespace.constants.each do |name|
|
152
|
+
methods_of(namespace.const_get(name), seen, &block)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
require 'thread'
|
2
|
+
require 'strscan'
|
3
|
+
require 'pty'
|
4
|
+
|
5
|
+
class VER::View::Terminal
|
6
|
+
def initialize(parent)
|
7
|
+
@parent = parent
|
8
|
+
setup_widgets
|
9
|
+
pty
|
10
|
+
end
|
11
|
+
|
12
|
+
def bench(name, &block)
|
13
|
+
require 'benchmark'
|
14
|
+
p name => Benchmark.realtime(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup_widgets
|
18
|
+
Tk.set_palette('black') # maybe use themes instead?
|
19
|
+
|
20
|
+
@option_cache ||= {}
|
21
|
+
@font ||= VER.options[:font]
|
22
|
+
@font_actual ||= @font.actual_hash
|
23
|
+
|
24
|
+
@text = Tk::Text.new(font: @font, insertofftime: 1)
|
25
|
+
@text.pack expand: true, fill: :both
|
26
|
+
@text.focus
|
27
|
+
|
28
|
+
@text.bind('<Key>'){|event|
|
29
|
+
@pty_queue << event.unicode
|
30
|
+
Tk.callback_break
|
31
|
+
}
|
32
|
+
|
33
|
+
@text.bind('<Return>'){|event|
|
34
|
+
@pty_queue << event.unicode
|
35
|
+
# Tk.callback_break
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
@text.destroy
|
41
|
+
@parent.focus
|
42
|
+
end
|
43
|
+
|
44
|
+
def pty
|
45
|
+
@pty_queue = queue = Queue.new
|
46
|
+
|
47
|
+
Thread.new do
|
48
|
+
shell = ENV['SHELL'] || 'bash'
|
49
|
+
|
50
|
+
PTY.spawn(shell) do |r_pty, w_pty, pid|
|
51
|
+
Thread.new do
|
52
|
+
while chunk = queue.shift
|
53
|
+
w_pty.print chunk
|
54
|
+
w_pty.flush
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
loop do
|
59
|
+
c = r_pty.sysread(1 << 15)
|
60
|
+
on_chunk(c) if c
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
rescue Errno::EIO, PTY::ChildExited
|
65
|
+
destroy
|
66
|
+
end
|
67
|
+
|
68
|
+
ANSI_CODES = []
|
69
|
+
ANSI_CODES[0] = :reset
|
70
|
+
ANSI_CODES[1] = :bold
|
71
|
+
ANSI_CODES[2] = :dark
|
72
|
+
ANSI_CODES[3] = :italic
|
73
|
+
ANSI_CODES[4] = :underline
|
74
|
+
ANSI_CODES[5] = :blink
|
75
|
+
ANSI_CODES[6] = :rapid_blink
|
76
|
+
ANSI_CODES[7] = :reverse
|
77
|
+
ANSI_CODES[8] = :concealed
|
78
|
+
ANSI_CODES[9] = :strikethrough
|
79
|
+
ANSI_CODES[30] = :black
|
80
|
+
ANSI_CODES[31] = :red
|
81
|
+
ANSI_CODES[32] = :green
|
82
|
+
ANSI_CODES[33] = :yellow
|
83
|
+
ANSI_CODES[34] = :blue
|
84
|
+
ANSI_CODES[35] = :magenta
|
85
|
+
ANSI_CODES[36] = :cyan
|
86
|
+
ANSI_CODES[37] = :white
|
87
|
+
ANSI_CODES[40] = :on_black
|
88
|
+
ANSI_CODES[41] = :on_red
|
89
|
+
ANSI_CODES[42] = :on_green
|
90
|
+
ANSI_CODES[43] = :on_yellow
|
91
|
+
ANSI_CODES[44] = :on_blue
|
92
|
+
ANSI_CODES[45] = :on_magenta
|
93
|
+
ANSI_CODES[46] = :on_cyan
|
94
|
+
ANSI_CODES[47] = :on_white
|
95
|
+
|
96
|
+
# Trying to build a little dictionary of escape sequences:
|
97
|
+
#
|
98
|
+
# | Sequence | Meaning |
|
99
|
+
# | \e]0; | reset fg/bg |
|
100
|
+
# | \e[?1034h | ??? |
|
101
|
+
# | \e[01;34mbin\e | fg: 1, bg: 34 |
|
102
|
+
|
103
|
+
def on_chunk(chunk)
|
104
|
+
@buffer ||= ''
|
105
|
+
@buffer << chunk
|
106
|
+
s = StringScanner.new(@buffer)
|
107
|
+
|
108
|
+
until s.eos?
|
109
|
+
pos = s.pos
|
110
|
+
|
111
|
+
case s.peek(1)
|
112
|
+
when "\e"
|
113
|
+
if s.scan(/\e\](\d+);/)
|
114
|
+
color s[1]
|
115
|
+
elsif s.scan(/\e\[(\d+)([A-Z])/)
|
116
|
+
color s[1]
|
117
|
+
elsif s.scan(/\e\[\?(\d+h)/)
|
118
|
+
color s[1]
|
119
|
+
elsif s.scan(/\e\[(\d+);(\d+)m/) # \e[01;34m
|
120
|
+
color s[1], s[2]
|
121
|
+
elsif s.scan(/\e\[(\d+)m/)
|
122
|
+
color s[1]
|
123
|
+
elsif s.scan(/\e\[([A-Z])/)
|
124
|
+
color s[1]
|
125
|
+
elsif s.scan(/\e\[m/)
|
126
|
+
# nothing?
|
127
|
+
elsif s.scan(/\e=\r/)
|
128
|
+
delete 'insert linestart', 'insert lineend'
|
129
|
+
else
|
130
|
+
p s.rest
|
131
|
+
end
|
132
|
+
when "\r"
|
133
|
+
if s.scan(/\r\n/)
|
134
|
+
insert :end, "\n"
|
135
|
+
elsif s.scan(/\r\r/)
|
136
|
+
delete 'insert linestart', 'insert lineend'
|
137
|
+
elsif s.scan(/\r[^\n\r]/)
|
138
|
+
p :no_rn => s.matched
|
139
|
+
else
|
140
|
+
p :r_fail => s.rest
|
141
|
+
end
|
142
|
+
when "\x07"
|
143
|
+
s.pos += 1
|
144
|
+
delete 'insert linestart', 'insert lineend'
|
145
|
+
when "\x08"
|
146
|
+
s.pos += 1
|
147
|
+
delete 'insert - 1 chars'
|
148
|
+
else
|
149
|
+
if s.scan(/\A[^\e\r\x08\x07]+/)
|
150
|
+
insert :end, s.matched
|
151
|
+
end
|
152
|
+
end
|
153
|
+
# p s.matched
|
154
|
+
|
155
|
+
if s.pos == pos
|
156
|
+
warn("Scanner stopped at: %p" % [s])
|
157
|
+
@buffer = s.rest
|
158
|
+
return
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
@buffer = ''
|
163
|
+
@text.see :end
|
164
|
+
rescue StringScanner::Error => ex
|
165
|
+
VER.error(ex)
|
166
|
+
rescue => ex
|
167
|
+
puts "#{ex.class}: #{ex}", *ex.backtrace
|
168
|
+
@buffer = ''
|
169
|
+
destroy
|
170
|
+
end
|
171
|
+
|
172
|
+
def color(fg, bg = nil)
|
173
|
+
if bg
|
174
|
+
fg, bg = ANSI_CODES[fg.to_i], ANSI_CODES[bg.to_i]
|
175
|
+
|
176
|
+
@tag = [:ansi, fg, bg].join('_')
|
177
|
+
@text.tag_configure @tag, options_for(@tag, fg, bg)
|
178
|
+
else
|
179
|
+
fg = ANSI_CODES[fg.to_i]
|
180
|
+
|
181
|
+
@tag = [:ansi, fg].join('_')
|
182
|
+
@text.tag_configure @tag, options_for(@tag, fg)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
FG_COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
|
187
|
+
BG_COLORS = [:on_black, :on_red, :on_green, :on_yellow, :on_blue, :on_magenta, :on_cyan, :on_white]
|
188
|
+
|
189
|
+
def options_for(tag, fg, bg = nil)
|
190
|
+
|
191
|
+
if found = @option_cache[tag]
|
192
|
+
return found
|
193
|
+
end
|
194
|
+
|
195
|
+
options = {}
|
196
|
+
|
197
|
+
case fg
|
198
|
+
when nil
|
199
|
+
when :reset
|
200
|
+
options[:font] = @font
|
201
|
+
options[:background] = nil
|
202
|
+
options[:foreground] = nil
|
203
|
+
when :bold
|
204
|
+
options[:font] = font_for(@font_actual.merge(weight: :bold))
|
205
|
+
when *FG_COLORS
|
206
|
+
options[:foreground] = fg
|
207
|
+
when *BG_COLORS
|
208
|
+
options[:background] = bg.to_s.sub(/on_/, '')
|
209
|
+
else
|
210
|
+
p fg: fg
|
211
|
+
end
|
212
|
+
|
213
|
+
case bg
|
214
|
+
when nil
|
215
|
+
when :reset
|
216
|
+
options[:font] = @font
|
217
|
+
options[:background] = nil
|
218
|
+
options[:foreground] = nil
|
219
|
+
when *FG_COLORS
|
220
|
+
options[:foreground] = bg
|
221
|
+
when *BG_COLORS
|
222
|
+
options[:background] = bg.to_s.sub(/on_/, '')
|
223
|
+
else
|
224
|
+
p bg: bg
|
225
|
+
end
|
226
|
+
|
227
|
+
@option_cache[options] = options
|
228
|
+
options
|
229
|
+
end
|
230
|
+
|
231
|
+
def font_for(options)
|
232
|
+
@fonts ||= {}
|
233
|
+
@fonts[options] ||= Tk::Font.new(options)
|
234
|
+
end
|
235
|
+
|
236
|
+
def ansi2sym(ansi)
|
237
|
+
COLORS[ansi.to_i]
|
238
|
+
end
|
239
|
+
|
240
|
+
def insert(index, chars)
|
241
|
+
# p insert: [index, chars]
|
242
|
+
@text.insert(index, chars, @tag)
|
243
|
+
end
|
244
|
+
|
245
|
+
def delete(*indices)
|
246
|
+
# p delete: indices
|
247
|
+
@text.delete(*indices)
|
248
|
+
end
|
249
|
+
end
|