ver 2009.10.14 → 2009.11.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (318) hide show
  1. data/CHANGELOG +1094 -0
  2. data/MANIFEST +227 -25
  3. data/README.textile +185 -0
  4. data/bin/ver +96 -12
  5. data/config/detect.rb +73 -21
  6. data/config/keymap/emacs.rb +66 -0
  7. data/config/keymap/vim.rb +250 -140
  8. data/config/preferences/ANTLR.json +10 -0
  9. data/config/preferences/ASP vb.NET.json +3 -0
  10. data/config/preferences/ASP.json +15 -0
  11. data/config/preferences/ActionScript.json +755 -0
  12. data/config/preferences/Active4D.json +89 -0
  13. data/config/preferences/Ada.json +23 -0
  14. data/config/preferences/Ant.json +356 -0
  15. data/config/preferences/Apache.json +644 -0
  16. data/config/preferences/AppleScript.json +92 -0
  17. data/config/preferences/Bison.json +3 -0
  18. data/config/preferences/Blogging.json +3 -0
  19. data/config/preferences/C.json +127 -0
  20. data/config/preferences/CMake.json +41 -0
  21. data/config/preferences/CSS.json +461 -0
  22. data/config/preferences/CTags.json +3 -0
  23. data/config/preferences/CVS.json +3 -0
  24. data/config/preferences/ColdFusion.json +32 -0
  25. data/config/preferences/D.json +58 -0
  26. data/config/preferences/Darcs.json +3 -0
  27. data/config/preferences/Diff.json +67 -0
  28. data/config/preferences/DokuWiki.json +19 -0
  29. data/config/preferences/Doxygen.json +3 -0
  30. data/config/preferences/Dylan.json +3 -0
  31. data/config/preferences/Eiffel.json +59 -0
  32. data/config/preferences/Erlang.json +72 -0
  33. data/config/preferences/Experimental.json +1356 -0
  34. data/config/preferences/F-Script.json +87 -0
  35. data/config/preferences/FXScript.json +78 -0
  36. data/config/preferences/FileMerge.json +3 -0
  37. data/config/preferences/Fortran.json +158 -0
  38. data/config/preferences/GTD2.json +11 -0
  39. data/config/preferences/GTDAlt.json +20 -0
  40. data/config/preferences/GetBundle.json +3 -0
  41. data/config/preferences/Gettext.json +24 -0
  42. data/config/preferences/Graphviz.json +42 -0
  43. data/config/preferences/Greasemonkey.json +3 -0
  44. data/config/preferences/Gri.json +34 -0
  45. data/config/preferences/HTML.json +492 -0
  46. data/config/preferences/Haskell.json +72 -0
  47. data/config/preferences/Hotkey.json +3 -0
  48. data/config/preferences/ImageBrowser.json +3 -0
  49. data/config/preferences/Inform.json +3 -0
  50. data/config/preferences/Ini.json +60 -0
  51. data/config/preferences/Installer.json +3 -0
  52. data/config/preferences/Io.json +64 -0
  53. data/config/preferences/JSON.json +3 -0
  54. data/config/preferences/Java.json +86 -0
  55. data/config/preferences/JavaDoc.json +3 -0
  56. data/config/preferences/JavaScript.json +76 -0
  57. data/config/preferences/LaTeX.json +267 -0
  58. data/config/preferences/Lex/Flex.json +3 -0
  59. data/config/preferences/Lighttpd.json +3 -0
  60. data/config/preferences/LilyPond.json +77 -0
  61. data/config/preferences/Lisp.json +63 -0
  62. data/config/preferences/Logo.json +58 -0
  63. data/config/preferences/Logtalk.json +236 -0
  64. data/config/preferences/Lua.json +24 -0
  65. data/config/preferences/MEL.json +19 -0
  66. data/config/preferences/MIPS Assembler.json +26 -0
  67. data/config/preferences/MacPorts.json +3 -0
  68. data/config/preferences/Mail.json +3 -0
  69. data/config/preferences/Make.json +16 -0
  70. data/config/preferences/Markdown.json +102 -0
  71. data/config/preferences/Math.json +3 -0
  72. data/config/preferences/Matlab.json +128 -0
  73. data/config/preferences/Maven.json +308 -0
  74. data/config/preferences/Mediawiki.json +73 -0
  75. data/config/preferences/Mercurial.json +3 -0
  76. data/config/preferences/Modula.json +37 -0
  77. data/config/preferences/MoinMoin.json +52 -0
  78. data/config/preferences/Navigation.json +3 -0
  79. data/config/preferences/Nemerle.json +3 -0
  80. data/config/preferences/OCaml Code Completion.json +3 -0
  81. data/config/preferences/OCaml.json +163 -0
  82. data/config/preferences/ODCompletion.json +3 -0
  83. data/config/preferences/Objective-C.json +84 -0
  84. data/config/preferences/OpenGL.json +3331 -0
  85. data/config/preferences/Outlines.json +3 -0
  86. data/config/preferences/Pascal.json +60 -0
  87. data/config/preferences/Perforce.json +3 -0
  88. data/config/preferences/Perl.json +15 -0
  89. data/config/preferences/PmWiki.json +27 -0
  90. data/config/preferences/Postscript.json +15 -0
  91. data/config/preferences/Processing.json +32 -0
  92. data/config/preferences/Prolog.json +3 -0
  93. data/config/preferences/Propel.json +3 -0
  94. data/config/preferences/Python.json +38 -0
  95. data/config/preferences/Quake.json +15 -0
  96. data/config/preferences/R.json +33 -0
  97. data/config/preferences/Ragel.json +15 -0
  98. data/config/preferences/Regular Expressions.json +3 -0
  99. data/config/preferences/Remind.json +15 -0
  100. data/config/preferences/Rez.json +46 -0
  101. data/config/preferences/Ruby.json +98 -0
  102. data/config/preferences/S5 Slide Show.json +20 -0
  103. data/config/preferences/SCons.json +3 -0
  104. data/config/preferences/SQL.json +32 -0
  105. data/config/preferences/SSH Config.json +15 -0
  106. data/config/preferences/SVK.json +3 -0
  107. data/config/preferences/SWIG.json +3 -0
  108. data/config/preferences/SWeave.json +32 -0
  109. data/config/preferences/Scheme.json +35 -0
  110. data/config/preferences/Scilab.json +15 -0
  111. data/config/preferences/Setext.json +3 -0
  112. data/config/preferences/Shell Script.json +25 -0
  113. data/config/preferences/Slate.json +113 -0
  114. data/config/preferences/Source.json +132 -0
  115. data/config/preferences/Subversion.json +10 -0
  116. data/config/preferences/TODO.json +3 -0
  117. data/config/preferences/Tabular.json +3 -0
  118. data/config/preferences/Tcl.json +82 -0
  119. data/config/preferences/TerminalMate.json +112 -0
  120. data/config/preferences/Text.json +89 -0
  121. data/config/preferences/TextMate.json +38 -0
  122. data/config/preferences/Textile.json +76 -0
  123. data/config/preferences/Thrift.json +56 -0
  124. data/config/preferences/Transmit.json +3 -0
  125. data/config/preferences/Twiki.json +51 -0
  126. data/config/preferences/Txt2tags.json +81 -0
  127. data/config/preferences/Vectorscript.json +1280 -0
  128. data/config/preferences/XML.json +60 -0
  129. data/config/preferences/Xcode.json +3 -0
  130. data/config/preferences/YAML.json +24 -0
  131. data/config/preferences/iCalendar.json +10 -0
  132. data/config/preferences/iTerm.json +36 -0
  133. data/config/preferences/reStructuredText.json +48 -0
  134. data/config/rc.rb +49 -0
  135. data/config/syntax/ANTLR.json +5 -5
  136. data/config/syntax/{ASP VB.net.json → ASP vb.NET.json } +3 -3
  137. data/config/syntax/ASP.json +1 -1
  138. data/config/syntax/ActionScript.json +6 -6
  139. data/config/syntax/Active4D Config.json +86 -0
  140. data/config/syntax/Active4D Library.json +20 -0
  141. data/config/syntax/Active4D.json +418 -0
  142. data/config/syntax/Ada.json +3 -3
  143. data/config/syntax/Ant.json +196 -0
  144. data/config/syntax/Apache.json +7 -7
  145. data/config/syntax/AppleScript.json +3 -3
  146. data/config/syntax/{Bibtex.json → BibTeX.json} +1 -1
  147. data/config/syntax/Bison.json +59 -0
  148. data/config/syntax/{Blog (HTML).json → Blog - HTML.json } +2 -2
  149. data/config/syntax/{Blog (Markdown).json → Blog - Markdown.json } +2 -2
  150. data/config/syntax/Blog (Text).json b/data/config/syntax/Blog - → Text.json +0 -0
  151. data/config/syntax/Blog (Textile).json b/data/config/syntax/Blog - → Textile.json +0 -0
  152. data/config/syntax/C++.json +3 -3
  153. data/config/syntax/C.json +13 -13
  154. data/config/syntax/CMake Listfile.json +171 -0
  155. data/config/syntax/CSS.json +6 -6
  156. data/config/syntax/CSV.json +108 -0
  157. data/config/syntax/ColdFusion.json +204 -0
  158. data/config/syntax/D.json +560 -0
  159. data/config/syntax/Diff.json +1 -1
  160. data/config/syntax/DokuWiki.json +412 -0
  161. data/config/syntax/Doxygen.json +80 -0
  162. data/config/syntax/Dylan.json +4 -4
  163. data/config/syntax/Erlang.json +5 -5
  164. data/config/syntax/F-Script.json +1 -1
  165. data/config/syntax/FXScript.json +5 -5
  166. data/config/syntax/Fortran - Modern.json +221 -0
  167. data/config/syntax/Fortran - Punchcard.json +468 -0
  168. data/config/syntax/GTD.json +39 -0
  169. data/config/syntax/GTDalt.json +233 -0
  170. data/config/syntax/Gettext.json +118 -0
  171. data/config/syntax/Go.json +555 -0
  172. data/config/syntax/{DOT.json → Graphviz (DOT).json } +3 -3
  173. data/config/syntax/Greasemonkey.json +56 -0
  174. data/config/syntax/Gri.json +4 -4
  175. data/config/syntax/{HTML-ASP.json → HTML (ASP).json } +1 -1
  176. data/config/syntax/{HTML for ASP.net.json → HTML (ASP.net).json } +19 -19
  177. data/config/syntax/HTML (Active4D).json +540 -0
  178. data/config/syntax/HTML (Erlang).json +31 -0
  179. data/config/syntax/HTML (Tcl).json +1 -1
  180. data/config/syntax/HTML.json +20 -20
  181. data/config/syntax/Haskell.json +3 -3
  182. data/config/syntax/Installer Distribution Script.json +135 -0
  183. data/config/syntax/Io.json +6 -6
  184. data/config/syntax/JSON.json +151 -0
  185. data/config/syntax/{JavaProperties.json → Java Properties.json } +2 -2
  186. data/config/syntax/Java Server Page (JSP).json +163 -0
  187. data/config/syntax/Java.json +7 -7
  188. data/config/syntax/JavaDoc.json +435 -0
  189. data/config/syntax/JavaScript.json +8 -8
  190. data/config/syntax/LaTeX Log.json +3 -3
  191. data/config/syntax/LaTeX Memoir.json +101 -0
  192. data/config/syntax/LaTeX.json +2 -2
  193. data/config/syntax/Lex-Flex.json +396 -0
  194. data/config/syntax/LilyPond.json +608 -0
  195. data/config/syntax/Logo.json +48 -0
  196. data/config/syntax/Logtalk.json +6 -6
  197. data/config/syntax/Lua.json +1 -1
  198. data/config/syntax/{M.json → MATLAB.json} +3 -3
  199. data/config/syntax/MEL.json +7 -7
  200. data/config/syntax/MIPS.json b/data/config/syntax/MIPS → Assembler.json +0 -0
  201. data/config/syntax/MacPorts Portfile.json +298 -0
  202. data/config/syntax/Mail.json +1 -1
  203. data/config/syntax/Markdown.json +6 -6
  204. data/config/syntax/Maven POM.json +774 -0
  205. data/config/syntax/Mediawiki.json +736 -0
  206. data/config/syntax/MoinMoin.json +335 -0
  207. data/config/syntax/MultiMarkdown.json +41 -0
  208. data/config/syntax/Nemerle.json +128 -0
  209. data/config/syntax/OCaml.json +4 -4
  210. data/config/syntax/OCamllex.json +307 -0
  211. data/config/syntax/OCamlyacc.json +346 -0
  212. data/config/syntax/Objective-C++.json +2 -2
  213. data/config/syntax/Objective-C.json +979 -0
  214. data/config/syntax/Octave.json +417 -0
  215. data/config/syntax/PHP.json +32 -32
  216. data/config/syntax/Pascal.json +1 -1
  217. data/config/syntax/Perl.json +8 -8
  218. data/config/syntax/{Plain text.json → Plain Text.json } +1 -1
  219. data/config/syntax/PmWiki.json +241 -0
  220. data/config/syntax/Postscript.json +206 -0
  221. data/config/syntax/Processing.json +8 -8
  222. data/config/syntax/Prolog.json +70 -0
  223. data/config/syntax/Python.json +1934 -0
  224. data/config/syntax/{Quake3 Config.json → Quake Style .cfg.json } +1 -1
  225. data/config/syntax/R.json +2 -2
  226. data/config/syntax/Ragel.json +362 -0
  227. data/config/syntax/Rd (R Documentation).json +119 -0
  228. data/config/syntax/Regular Expressions (Oniguruma).json +186 -0
  229. data/config/syntax/Regular Expressions (Python).json +188 -0
  230. data/config/syntax/Release Notes.json +78 -0
  231. data/config/syntax/Remind.json +461 -0
  232. data/config/syntax/Rez.json +5 -5
  233. data/config/syntax/Ruby Sass.json +497 -0
  234. data/config/syntax/Ruby.json +13 -13
  235. data/config/syntax/S5 Slide Show.json +85 -0
  236. data/config/syntax/SQL.json +11 -11
  237. data/config/syntax/SSH Config.json +55 -0
  238. data/config/syntax/SWIG.json +2 -2
  239. data/config/syntax/SWeave.json +139 -0
  240. data/config/syntax/Scheme.json +8 -8
  241. data/config/syntax/Scilab.json +69 -0
  242. data/config/syntax/Setext.json +247 -0
  243. data/config/syntax/{Shell-Unix-Generic.json → Shell Script (Bash).json } +4 -4
  244. data/config/syntax/Slate.json +5 -5
  245. data/config/syntax/Strings File.json +53 -0
  246. data/config/syntax/TSV.json +83 -0
  247. data/config/syntax/Tcl.json +1 -1
  248. data/config/syntax/TeX Math.json +2 -2
  249. data/config/syntax/TeX.json +2 -2
  250. data/config/syntax/Textile.json +9 -9
  251. data/config/syntax/Thrift.json +641 -0
  252. data/config/syntax/Twiki.json +1 -1
  253. data/config/syntax/Txt2tags.json +154 -0
  254. data/config/syntax/XML strict.json +4 -4
  255. data/config/syntax/XML.json +6 -6
  256. data/config/syntax/XSL.json +2 -2
  257. data/config/syntax/camlp4.json +63 -0
  258. data/config/syntax/mod_perl.json +72 -0
  259. data/config/syntax/reStructuredText.json +1 -1
  260. data/config/syntax/{Subversion commit message.json → svn-commit.tmp.json} +0 -0
  261. data/config/tutorial +23 -19
  262. data/config/welcome +3 -3
  263. data/lib/ver.rb +273 -62
  264. data/lib/ver/entry.rb +142 -26
  265. data/lib/ver/font.rb +51 -0
  266. data/lib/ver/help.rb +16 -0
  267. data/lib/ver/help/describe_key.rb +82 -0
  268. data/lib/ver/help/help_for_help.rb +39 -0
  269. data/lib/ver/hover_completion.rb +129 -0
  270. data/lib/ver/keymap.rb +95 -24
  271. data/lib/ver/layout.rb +107 -43
  272. data/lib/ver/methods.rb +24 -8
  273. data/lib/ver/methods/clipboard.rb +91 -0
  274. data/lib/ver/methods/completion.rb +146 -71
  275. data/lib/ver/methods/control.rb +203 -222
  276. data/lib/ver/methods/ctags.rb +55 -0
  277. data/lib/ver/methods/delete.rb +30 -0
  278. data/lib/ver/methods/help.rb +7 -0
  279. data/lib/ver/methods/insert.rb +233 -1
  280. data/lib/ver/methods/move.rb +181 -32
  281. data/lib/ver/methods/open.rb +208 -0
  282. data/lib/ver/methods/preview.rb +14 -0
  283. data/lib/ver/methods/save.rb +111 -0
  284. data/lib/ver/methods/search.rb +57 -7
  285. data/lib/ver/methods/select.rb +97 -17
  286. data/lib/ver/methods/shortcuts.rb +21 -0
  287. data/lib/ver/methods/views.rb +56 -1
  288. data/lib/ver/mode.rb +60 -14
  289. data/lib/ver/status.rb +97 -19
  290. data/lib/ver/syntax.rb +14 -6
  291. data/lib/ver/syntax/detector.rb +16 -5
  292. data/lib/ver/syntax/processor.rb +9 -3
  293. data/lib/ver/text.rb +258 -199
  294. data/lib/ver/text/index.rb +103 -0
  295. data/lib/ver/theme.rb +27 -16
  296. data/lib/ver/tooltip.rb +59 -0
  297. data/lib/ver/vendor/binary_search.rb +61 -0
  298. data/lib/ver/vendor/levenshtein.rb +57 -0
  299. data/lib/ver/{textpow.rb → vendor/textpow.rb} +31 -29
  300. data/lib/ver/view.rb +65 -41
  301. data/lib/ver/view/console.rb +171 -0
  302. data/lib/ver/view/entry.rb +9 -5
  303. data/lib/ver/view/list.rb +44 -29
  304. data/lib/ver/view/list/ex.rb +71 -0
  305. data/lib/ver/view/list/grep.rb +42 -0
  306. data/lib/ver/view/list/methods.rb +159 -0
  307. data/lib/ver/view/term.rb +249 -0
  308. data/tasks/syntax_list.rake +3 -2
  309. data/ver.gemspec +4 -4
  310. metadata +230 -28
  311. data/config/syntax/Bulletin Board.json +0 -428
  312. data/config/syntax/HTML (Mason).json +0 -207
  313. data/config/syntax/HTML (Rails).json +0 -52
  314. data/config/syntax/Movable Type.json +0 -348
  315. data/config/syntax/Ruby on Rails.json +0 -170
  316. data/config/syntax/SQL (Rails).json +0 -31
  317. data/config/syntax/Smarty.json +0 -110
  318. 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