ribhu 0.0.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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ribhu.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rahul Kumar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Ribhu
2
+
3
+ ri browser using ncurses
4
+
5
+ Hopes to make your ruby documentation experience faster. This is a two pane application, with
6
+ Classes on the left list, and details on the right.
7
+ You may press Enter on a class to see its documention. Pressing ENTER over a method in the right will
8
+ fetch its details.
9
+
10
+ You may mark classes with an upper case alphabet (vim style) and access them directly using single-quote.
11
+ Several classes have been bookmarked such as Array, String, Hash, File.
12
+
13
+ Pressing Alt-c and type in any class or method or portion. If `ri` does not return data or returns
14
+ choices, a popup will allows selection of choices.
15
+
16
+ Browser style, one may backspace through earlier results, or use Alt-n and Alt-p to go back and forth
17
+ between previous and next pages viewed.
18
+
19
+ Please get back to me if there are cases where it's unhelpful in finding the ridocs.
20
+
21
+ ## Installation
22
+
23
+ gem install ribhu
24
+
25
+ ## Usage
26
+
27
+ Ensure you have ri documentation working. On the command line you may do, "ri String". You should get documentation for the String class. If not proceed as follows:
28
+
29
+ To get ri documentation, you would do
30
+
31
+ rvm docs generate-ri
32
+
33
+ If you use any gems for development, e.g. highline or rbcurse-core, use the `--ri` flag while installing the gem (this assumes you've switched off ri and rdocs in your .gemrc).
34
+
35
+ This gem depends on rbcurse-core
36
+
37
+ ## Gem name
38
+
39
+ rib was taken, so i took the next name that came to mind. "ri" browser.
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/ribhu ADDED
@@ -0,0 +1,337 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # NOTE: If the listbox is empty, that could mean that you have not generated
4
+ # ri documentation for this version of ruby. You can do so by doing:
5
+ # rvm docs generate-ri
6
+ # or
7
+ # rvm docs generate
8
+ # (This assumes you are using rvm)
9
+ #
10
+ # WARNING : IF THIS PROGRAM HANGS check the ri command
11
+ # Maybe your version of ri has different options and is going interactive.
12
+ # ruby 1.9.3's ri requires a -l option or else if becomes interactive.
13
+ # this program tests out a listbox
14
+ # This is written in the old style where we start and end ncurses and initiate a
15
+ # getch loop. It gives more control.
16
+ # The new style is to use App which does the ncurses setup and teardown, as well
17
+ # as manages keys. It also takes care of logger and includes major stuff.
18
+ #
19
+ #
20
+ # TODO: what about other docs such as rbcurse, highline and others
21
+ # If search fails try ::str
22
+ # Also when ENTER if class has a :: then try adding it straight to that module RubyCurses::Button
23
+ # and not RubyC::Link.Button -- keep trying options till we get something
24
+ require 'logger'
25
+ require 'rbcurse'
26
+ require 'rbcurse/core/widgets/rlist'
27
+ require 'rbcurse/core/widgets/rtextview'
28
+ require 'rbcurse/core/include/vieditable'
29
+
30
+ class RubyCurses::List
31
+ # vieditable includes listeditable which
32
+ # does bring in some functions which can crash program like x and X TODO
33
+ # also, f overrides list f mapping. TODO
34
+ include ViEditable
35
+ end
36
+ def my_help_text
37
+ <<-eos
38
+
39
+ =========================================================================
40
+ Basic Usage
41
+
42
+ Press <ENTER> on a class name on the first list, to view ri information
43
+ for it on the right.
44
+
45
+ Tab to right area, and press <ENTER> on a method name, to see its details
46
+ Press / <slash> in any box to search. e.g /String will take you to the
47
+ first occurrence of String. <n> will take you to next.
48
+
49
+ To go quickly to first class starting with 'S', type <f> followed by <S>.
50
+ Then press <n> to go to next match.
51
+
52
+ On the right window, you may press BACKSPACE to go back to earlier pages.
53
+ You may also press Alt-n and Alt-p to cycle through next and previously
54
+ viewed pages.
55
+
56
+ Press Alt-C to enter class or method name and see details. If there is
57
+ no data returned, or options returned you may have to select from a list.
58
+ e.g. entering 'flatten' may return a list of choices to select from.
59
+ Entering 'Str' returns nothing from ri, so you have to select from classes
60
+ starting with 'Str'.
61
+
62
+ =========================================================================
63
+ Bookmarks
64
+
65
+ Access bookmarks using single-quote as in vim followed by a single character.
66
+ Some have been set such as Array, String, Hash, File. To create a bookmark,
67
+ position cursor over a class in the left list, and press "m". You will be
68
+ prompted for the character to use as the mark.
69
+
70
+ =========================================================================
71
+ Buffers
72
+
73
+ Ordinary a textview contains only one buffer. However, the one on the right
74
+ is extended for multiple buffers. Pressing ENTER on the left on several
75
+ rows opens multiple buffers on the right. Use M-n (Alt-N) and M-p to navigate.
76
+ ALternatively, : maps to a menu, so :n and :p may also be used.
77
+ <BACKSPACE> will also go to previous buffer, like a browser.
78
+
79
+ =========================================================================
80
+ Press <M-n> for next help screen, or try :n
81
+
82
+ eos
83
+ end
84
+
85
+ ##
86
+ # display the ridoc for given word (class or method or part)
87
+ def display_text word
88
+ w = @form.by_name["tv"];
89
+ lines = `ri -f rdoc #{word}`.split("\n")
90
+ return if lines.nil? || lines.size == 0
91
+ # ansi can have overflow
92
+ #w.add_content(lines, :content_type => :ansi, :title => word)
93
+ w.add_content(lines, :title => word)
94
+ w.buffer_last
95
+ end
96
+
97
+ ##
98
+ # prompt user for a class name and show ri doc for same, can be method too
99
+ #
100
+ def ask_classes
101
+ format="rdoc"
102
+ str = get_string("Enter a class name: ")
103
+ if str != ""
104
+ lines = `ri -f #{format} #{str}`.split("\n")
105
+ if lines.size == 0
106
+ #alert "Nothing came through for #{str}"
107
+ ## Nothing returned, lets see if we can match something from the class list
108
+ li = @form.by_name["mylist"];
109
+ values = li.list
110
+ values = values.grep(/^#{str}/i)
111
+ if values.size > 0
112
+ ix = popuplist(values)
113
+ if ix
114
+ str = values[ix]
115
+ lines = `ri -f #{format} #{str}`.split("\n")
116
+ end
117
+ else
118
+ alert "Nothing came through for #{str}"
119
+ end
120
+ elsif lines.first.index(".#{str} not found")
121
+ ## we are returned something with some choices, lets prompt user with choices
122
+ lines.shift
123
+ lines.shift
124
+ ix = popuplist(lines)
125
+ if ix
126
+ str = lines[ix]
127
+ lines = `ri -f #{format} #{str}`.split("\n")
128
+ end
129
+ end
130
+ return if lines.size == 0
131
+ w = @form.by_name["tv"];
132
+ #w.add_content(lines, :content_type => :ansi, :title => str)
133
+ w.add_content(lines, :title => str)
134
+ w.buffer_last
135
+ end
136
+ end
137
+
138
+ # set focus in list on given string
139
+ def set_focus_on str
140
+ listb = @form.by_name["mylist"];
141
+ ix = listb.list.index(str)
142
+ if ix
143
+ listb.set_focus_on ix
144
+ end
145
+ end
146
+
147
+ ## user has pressed bokmark char, now get the mark A-Z
148
+ def ask_bookmark
149
+ ch = @window.getchar
150
+ ch = ch.chr.upcase
151
+ str = $bookmarks[ch.to_sym]
152
+ if str
153
+ display_text str
154
+ # set focus to that in the left list
155
+ set_focus_on str
156
+ else
157
+ #alert "No bookmark for #{ch}"
158
+ ## No bookmark, jumping to first char
159
+ listb = @form.by_name["mylist"];
160
+ listb.set_selection_for_char ch
161
+ end
162
+ end
163
+ def add_bookmark ch, word
164
+ $bookmarks[ch.upcase.to_sym] = word
165
+ alert "set mark for #{ch.upcase.to_sym} for #{word}"
166
+ end
167
+
168
+ ## try various options till you get something.
169
+ #
170
+ def try_ri arr
171
+ _text = nil
172
+ arr.each do |w|
173
+ _text = `ri -f rdoc #{w} 2>&1`.split("\n")
174
+ if _text.first.index("Nothing known about")
175
+ else
176
+ break
177
+ end
178
+ end
179
+ _text
180
+ end
181
+
182
+
183
+ #if $0 == __FILE__
184
+ if true
185
+ include RubyCurses
186
+
187
+ begin
188
+ # Initialize curses
189
+ VER::start_ncurses # this is initializing colors via ColorMap.setup
190
+ $log = Logger.new((File.join(ENV["LOGDIR"] || "./" ,"rbc13.log")))
191
+ $log.level = Logger::DEBUG
192
+
193
+ $bookmarks = {
194
+ :A => "Array",
195
+ :C => "Class",
196
+ :D => "Dir",
197
+ :F => "File",
198
+ :H => "Hash",
199
+ :I => "IO",
200
+ :K => "Kernel",
201
+ :R => "RubyCurses",
202
+ :L => "RubyCurses::Link",
203
+ :S => "String"
204
+ }
205
+
206
+
207
+ @window = VER::Window.root_window
208
+ $catch_alt_digits = true; # emacs like alt-1..9 numeric arguments
209
+ install_help_text my_help_text
210
+ # Initialize few color pairs
211
+ # Create the window to be associated with the form
212
+ # Un post form and free the memory
213
+
214
+ catch(:close) do
215
+ @form = Form.new @window
216
+ @form.bind_key(KEY_F1, 'help'){ display_app_help }
217
+ @form.bind_key(?\M-c, 'select class') do
218
+ ask_classes
219
+ end
220
+ @form.bind_key(?', 'select bookmark') do
221
+ ask_bookmark
222
+ end
223
+
224
+ # this is the old style of printing something directly on the window.
225
+ # The new style is to use a header
226
+ @form.window.printstring 0, 30, "ri documentation browser", $normalcolor, BOLD
227
+ r = 1; fc = 1;
228
+
229
+ # this is the old style of using a label at the screen bottom, you can use the status_line
230
+
231
+ v = "Q quit, F1 Help, ? Bindings, f<char>, /, Alt-c, ENTER on Class or Method"
232
+ var = RubyCurses::Label.new @form, { :text => v, :row => FFI::NCurses.LINES-2,
233
+ :col => fc, :display_length => 100}
234
+
235
+ h = FFI::NCurses.LINES-3
236
+ mylist = `ri -l `.split("\n")
237
+ w = 25
238
+
239
+ listb = List.new @form, :name => "mylist" ,
240
+ :row => r ,
241
+ :col => 1 ,
242
+ :width => w,
243
+ :height => h,
244
+ :list => mylist,
245
+ :selection_mode => :SINGLE,
246
+ :show_selector => true,
247
+ :title => " Ruby Classes "
248
+ #title_attrib 'reverse'
249
+ listb.one_key_selection = false # this allows us to map keys to methods
250
+ #listb.vieditable_init_listbox
251
+ # what for is Io here
252
+ include Io
253
+ listb.bind_key(32) {|l| l.scroll_forward };
254
+ listb.bind(:PRESS) {
255
+ display_text listb.text
256
+ ## select class and display riinfo for class
257
+ }
258
+ listb.bind_key(?m) {
259
+ str = listb.text
260
+ ch = get_string("Enter character as shortcut for #{str}")
261
+ if ch != ""
262
+ add_bookmark ch[0], str
263
+ end
264
+ ## select class and display riinfo for class
265
+ }
266
+ #listb.unbind_key([?', ?'])
267
+ #listb.unbind_key(["'","'"])
268
+ #listb.unbind_key("'")
269
+ listb.bind_key(?', 'select bookmark') do
270
+ ask_bookmark
271
+ end
272
+
273
+ tv = RubyCurses::TextView.new @form, :row => r, :col => w+1, :height => h, :width => FFI::NCurses.COLS-w-1,
274
+ :name => "tv", :title => "Press Enter on method"
275
+ tv.set_content ["Press Enter on list to view ri information in this area.",
276
+ "Press ENTER on method name to see details"]
277
+ require 'rbcurse/core/include/multibuffer'
278
+ tv.extend(RubyCurses::MultiBuffers)
279
+ #tv.unbind_key([?', ?'])
280
+ #tv.unbind_key(?')
281
+ tv.bind_key(?', 'select bookmark') do
282
+ ask_bookmark
283
+ end
284
+
285
+ # pressing ENTER on a method name will popup details for that method
286
+ tv.bind(:PRESS) { |ev|
287
+ w = ev.word_under_cursor.strip
288
+ # check that user did not hit enter on empty area
289
+ if w != ""
290
+ #alert "wuc:#{w}:cp=#{ev.curpos},"
291
+ #if w.index("::")
292
+ #str=w
293
+ #else
294
+ str = "#{tv.title}.#{w}"
295
+ _text = try_ri([w, "#{str}"])
296
+ #end
297
+ tt = tv.title
298
+ #_text = `ri -f rdoc #{str} 2>&1`
299
+ #_text = _text.split("\n")
300
+ if _text.first.index("Nothing known about")
301
+ $log.debug "XXXX got #{_text}"
302
+ if tt.index("::")
303
+ ix = tt.index("::")
304
+ tt = tt[0,ix]
305
+ _text = `ri -f rdoc #{tt}::#{w} 2>&1`.split("\n")
306
+ end
307
+ end
308
+ if _text && _text.size != 0
309
+ #view(_text, :content_type => :ansi)
310
+ view(_text)
311
+ end
312
+ end
313
+ }
314
+
315
+
316
+ @form.repaint
317
+ @window.wrefresh
318
+ Ncurses::Panel.update_panels
319
+ while((ch = @window.getchar()) != KEY_F10 )
320
+ break if ch == ?Q.ord
321
+ @form.handle_key(ch)
322
+ @window.wrefresh
323
+ end
324
+ end
325
+ rescue => ex
326
+ textdialog ["Error in rib: #{ex} ", *ex.backtrace], :title => "Exception"
327
+ $log.debug( ex) if ex
328
+ $log.debug(ex.backtrace.join("\n")) if ex
329
+ ensure
330
+ @window.destroy if !@window.nil?
331
+ VER::stop_ncurses
332
+ p ex if ex
333
+ p(ex.backtrace.join("\n")) if ex
334
+ end
335
+ else
336
+ puts "Error #{$0}, #{__FILE__}"
337
+ end
@@ -0,0 +1,3 @@
1
+ module Ribhu
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ribhu.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "ribhu/version"
2
+
3
+ module Ribhu
4
+ # Your code goes here...
5
+ end
data/ribhu.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ribhu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ribhu"
8
+ spec.version = Ribhu::VERSION
9
+ spec.authors = ["Rahul Kumar"]
10
+ spec.email = ["sentinel1879@gmail.com"]
11
+ spec.description = %q{ri documentation browser using ncurses}
12
+ spec.summary = %q{ri documentation browser using ncurses}
13
+ spec.homepage = "https://github.com/rkumar/ribhu"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "rbcurse-core"
24
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ribhu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rahul Kumar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rbcurse-core
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ri documentation browser using ncurses
63
+ email:
64
+ - sentinel1879@gmail.com
65
+ executables:
66
+ - ribhu
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/ribhu
76
+ - lib/ribhu.rb
77
+ - lib/ribhu/version.rb
78
+ - ribhu.gemspec
79
+ homepage: https://github.com/rkumar/ribhu
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: 2856289681820087894
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: 2856289681820087894
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.25
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: ri documentation browser using ncurses
110
+ test_files: []