webri 2.1.0 → 2.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.
- checksums.yaml +4 -4
- data/exe/webri +6 -33
- data/lib/webri/version.rb +1 -1
- data/lib/webri.rb +147 -21
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba0ef2db19e442871c35e15c179f5de35941e87e5ce1a3d4afe0e1df9c6e19c0
|
|
4
|
+
data.tar.gz: 03b7f263f09d1e02e83cc0a190f47e221c5dc7e5bb1b7487149520fbbb361655
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 863c5f457150c1ac329b767e899afb41e62ea2016095e72d29efb374c080f39cab6888b01cd32132651e1ce8adba108d3deed9efb20a532873debe4c4f8d50c4
|
|
7
|
+
data.tar.gz: 3cb5a5ff87a108a4e026764add4540af14327161004bee077272f52a64a2296e5056b7bd9706d5dbac8051a68956fa4b266d7c5fa89723dc1d2c806095658c60
|
data/exe/webri
CHANGED
|
@@ -7,55 +7,28 @@ require_relative '../lib/webri/version'
|
|
|
7
7
|
require_relative '../lib/webri'
|
|
8
8
|
require_relative '../lib/scraper'
|
|
9
9
|
|
|
10
|
-
NAME = <<EOT
|
|
11
|
-
|
|
12
|
-
Name:
|
|
13
|
-
|
|
14
|
-
There are four types of names, as determined by prefixes:
|
|
15
|
-
|
|
16
|
-
- Class or module: starts with a capital letter; e.g., 'Array'.
|
|
17
|
-
- Singleton method: starts with '::'; e.g., '::new'.
|
|
18
|
-
- Instance method: starts with '#' (escaped as '\\#', if your shell requires it);
|
|
19
|
-
e.g., '#inspect'.
|
|
20
|
-
- Ruby file: starts with 'ruby:'; e.g., 'ruby:syntax_rdoc'.
|
|
21
|
-
|
|
22
|
-
Name handling:
|
|
23
|
-
|
|
24
|
-
- If name is a complete name of its type (and not also the start of other such names),
|
|
25
|
-
webri opens the page for that name.
|
|
26
|
-
- If name is incomplete, but is the start of only one name of its type,
|
|
27
|
-
webri asks whether to open the page for that name.
|
|
28
|
-
- If name is incomplete, but is the start of multiple names of its type,
|
|
29
|
-
webri displays those names and lets you choose.
|
|
30
|
-
- If name is not a valid name of its type, webri asks whether show such names.
|
|
31
|
-
- If name is not valid at all (i.e., does not start with any of the prefixes above),
|
|
32
|
-
webri prints an error message.
|
|
33
|
-
|
|
34
|
-
EOT
|
|
35
10
|
options = {}
|
|
36
11
|
|
|
37
12
|
parser = OptionParser.new
|
|
38
13
|
|
|
39
14
|
parser.version = WebRI::VERSION
|
|
40
15
|
parser.banner = <<-BANNER
|
|
41
|
-
|
|
42
|
-
|
|
16
|
+
Console application #{WebRI.webri} displays Ruby online HTML documentation
|
|
17
|
+
in the default web browser.
|
|
43
18
|
|
|
44
|
-
Usage: #{
|
|
19
|
+
Usage: #{WebRI.webri} [options] #{WebRI.variable('name')}
|
|
45
20
|
|
|
46
21
|
BANNER
|
|
47
22
|
|
|
48
23
|
RELEASES = Scraper.scrapers.keys.inspect
|
|
49
24
|
|
|
50
25
|
parser.separator("Options:")
|
|
51
|
-
release_description = <<-EOT
|
|
52
26
|
|
|
53
|
-
EOT
|
|
54
27
|
parser.on('-r', '--release RELEASE',
|
|
55
28
|
"Specify documentation release (one of #{RELEASES}).") do |value|
|
|
56
29
|
options[:release_name] = value
|
|
57
30
|
end
|
|
58
|
-
parser.on('-i', '--info',
|
|
31
|
+
parser.on('-i', '--info', "Print information about #{WebRI.webri}.") do
|
|
59
32
|
options[:info] = true
|
|
60
33
|
end
|
|
61
34
|
parser.on('--noreline', 'Do not use Reline (useful for testing).') do |value|
|
|
@@ -68,11 +41,11 @@ parser.on('-h', '--help', 'Print this help.') do
|
|
|
68
41
|
puts parser
|
|
69
42
|
exit
|
|
70
43
|
end
|
|
71
|
-
parser.on('-v', '--version',
|
|
44
|
+
parser.on('-v', '--version', "Print the version of #{WebRI.webri}.") do
|
|
72
45
|
puts WebRI::VERSION
|
|
73
46
|
exit
|
|
74
47
|
end
|
|
75
|
-
parser.separator(
|
|
48
|
+
parser.separator(WebRI::HELP)
|
|
76
49
|
|
|
77
50
|
parser.parse!
|
|
78
51
|
|
data/lib/webri/version.rb
CHANGED
data/lib/webri.rb
CHANGED
|
@@ -48,7 +48,9 @@ class WebRI
|
|
|
48
48
|
# Site of the official documentation.
|
|
49
49
|
DOC_SITE = 'https://docs.ruby-lang.org/en/'
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
def self.prompt
|
|
52
|
+
"(Type #{WebRI.tokenq('?')} for help, #{WebRI.tokenq('exit')} to exit) #{self.webri}> "
|
|
53
|
+
end
|
|
52
54
|
|
|
53
55
|
CLASS = 'class/module'
|
|
54
56
|
SINGLETON = 'singleton method'
|
|
@@ -104,7 +106,7 @@ class WebRI
|
|
|
104
106
|
|
|
105
107
|
def repl_plain # Read-evaluate-print loop, without Reline.
|
|
106
108
|
while true
|
|
107
|
-
$stdout.write(
|
|
109
|
+
$stdout.write(WebRI.prompt)
|
|
108
110
|
$stdout.flush
|
|
109
111
|
response = $stdin.gets.chomp
|
|
110
112
|
exit if response == 'exit'
|
|
@@ -132,7 +134,7 @@ class WebRI
|
|
|
132
134
|
Reline.completion_proc = proc { |word|
|
|
133
135
|
completion_words
|
|
134
136
|
}
|
|
135
|
-
while line = Reline.readline(
|
|
137
|
+
while line = Reline.readline(WebRI.prompt, true)
|
|
136
138
|
case line.chomp
|
|
137
139
|
when 'exit'
|
|
138
140
|
exit 0
|
|
@@ -420,12 +422,14 @@ class WebRI
|
|
|
420
422
|
|
|
421
423
|
# Present choices; return choice.
|
|
422
424
|
def get_choice_(choices, required: false)
|
|
425
|
+
lines = []
|
|
423
426
|
index = nil
|
|
424
427
|
range = (0..choices.size - 1)
|
|
425
428
|
until range.include?(index)
|
|
426
429
|
choices.each_with_index do |choice, i|
|
|
427
430
|
s = "%6d" % i
|
|
428
|
-
|
|
431
|
+
token = WebRI.token(choice)
|
|
432
|
+
lines << " #{s}: #{token}"
|
|
429
433
|
end
|
|
430
434
|
while true
|
|
431
435
|
message = if required
|
|
@@ -433,8 +437,24 @@ class WebRI
|
|
|
433
437
|
else
|
|
434
438
|
'Type a number to choose, or Return to skip: '
|
|
435
439
|
end
|
|
436
|
-
|
|
437
|
-
|
|
440
|
+
lines << message
|
|
441
|
+
s = lines.join("\n")
|
|
442
|
+
require "mkmf"
|
|
443
|
+
|
|
444
|
+
pager =
|
|
445
|
+
ENV["PAGER"] ||
|
|
446
|
+
if find_executable("less")
|
|
447
|
+
'less -RFX'
|
|
448
|
+
else
|
|
449
|
+
'more'
|
|
450
|
+
end
|
|
451
|
+
begin
|
|
452
|
+
IO.popen(pager, "w") do |io|
|
|
453
|
+
io.puts s
|
|
454
|
+
rescue Errno::EPIPE
|
|
455
|
+
# User exited early.
|
|
456
|
+
end
|
|
457
|
+
end
|
|
438
458
|
response = $stdin.gets
|
|
439
459
|
case response
|
|
440
460
|
when /(\d+)/
|
|
@@ -443,7 +463,7 @@ class WebRI
|
|
|
443
463
|
when "\n"
|
|
444
464
|
return nil unless required
|
|
445
465
|
else
|
|
446
|
-
|
|
466
|
+
# Continue
|
|
447
467
|
end
|
|
448
468
|
end
|
|
449
469
|
end
|
|
@@ -535,30 +555,136 @@ class WebRI
|
|
|
535
555
|
end
|
|
536
556
|
|
|
537
557
|
def help(response)
|
|
538
|
-
|
|
539
|
-
|
|
558
|
+
puts WebRI::HELP
|
|
559
|
+
return
|
|
560
|
+
puts <<HELP
|
|
540
561
|
Type:
|
|
541
|
-
- 'exit' to exit webri.
|
|
562
|
+
- #{WebRI.tokenq('exit')} to exit #{WebRI.webri}.
|
|
542
563
|
- #{CLASS.capitalize} name (full or partial) to see #{CLASS} names:
|
|
543
|
-
- 'Array' (full name, not the start of other names).
|
|
544
|
-
- 'Ar' (partial name).
|
|
564
|
+
- #{WebRI.tokenq('Array')} (full name, not the start of other names).
|
|
565
|
+
- #{WebRI.tokenq('Ar')} (partial name).
|
|
545
566
|
- #{SINGLETON.capitalize} name (full or partial) to see #{SINGLETON} names:
|
|
546
|
-
- '::tanh' (full name, not the start of other names).
|
|
547
|
-
- '::ta' (partial name).
|
|
567
|
+
- #{WebRI.tokenq('::tanh')} (full name, not the start of other names).
|
|
568
|
+
- #{WebRI.tokenq('::ta')} (partial name).
|
|
548
569
|
- #{INSTANCE.capitalize} name (full or partial) to see #{INSTANCE} names:
|
|
549
|
-
- '#query=' (full name, not the start of other names).
|
|
550
|
-
- '#qu' (partial name).
|
|
570
|
+
- #{WebRI.tokenq('#query=')} (full name, not the start of other names).
|
|
571
|
+
- #{WebRI.tokenq('#qu')} (partial name).
|
|
551
572
|
- #{FILE.capitalize}name (full or partial) to see #{FILE} names:
|
|
552
|
-
- 'ruby:syntax_rdoc' (full name, not the start of other names).
|
|
553
|
-
- 'ruby:syntax' (partial name).
|
|
573
|
+
- #{WebRI.tokenq('ruby:syntax_rdoc')} (full name, not the start of other names).
|
|
574
|
+
- #{WebRI.tokenq('ruby:syntax')} (partial name).
|
|
554
575
|
HELP
|
|
555
|
-
else
|
|
556
|
-
p response
|
|
557
|
-
end
|
|
558
576
|
end
|
|
559
577
|
|
|
560
578
|
def help_main
|
|
561
579
|
|
|
562
580
|
end
|
|
563
581
|
|
|
582
|
+
ANSI_COLOR = {
|
|
583
|
+
black: 30,
|
|
584
|
+
red: 31,
|
|
585
|
+
green: 32,
|
|
586
|
+
yellow: 33,
|
|
587
|
+
blue: 34,
|
|
588
|
+
magenta: 35,
|
|
589
|
+
cyan: 36,
|
|
590
|
+
white: 37,
|
|
591
|
+
bright_black: 90,
|
|
592
|
+
bright_red: 91,
|
|
593
|
+
bright_green: 92,
|
|
594
|
+
bright_yellow: 93,
|
|
595
|
+
bright_blue: 94,
|
|
596
|
+
bright_magenta: 95,
|
|
597
|
+
bright_cyan: 96,
|
|
598
|
+
bright_white: 97,
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
def self.ansi_color(s, color)
|
|
602
|
+
# return s unless $stdout.tty?
|
|
603
|
+
"\e[#{ANSI_COLOR[color]}m#{s}\e[0m"
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
def self.webri
|
|
607
|
+
self.ansi_color('webri', :blue)
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
def self.variable(s)
|
|
611
|
+
self.ansi_color(s, :yellow)
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
def self.string(s)
|
|
615
|
+
self.ansi_color("'#{s}'", :green)
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
def self.token(s)
|
|
619
|
+
color = case s
|
|
620
|
+
when /^[A-Z]/
|
|
621
|
+
:bright_blue
|
|
622
|
+
when /^::/
|
|
623
|
+
:bright_yellow
|
|
624
|
+
when /^#/
|
|
625
|
+
:bright_green
|
|
626
|
+
when /^ruby:/
|
|
627
|
+
:bright_red
|
|
628
|
+
else
|
|
629
|
+
:bright_cyan
|
|
630
|
+
end
|
|
631
|
+
self.ansi_color("#{s}", color)
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
def WebRI.tokenq(s)
|
|
635
|
+
"'" + WebRI.token("#{s}") + "'"
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
def self.file_name(s)
|
|
639
|
+
self.ansi_color("#{s}", :red)
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
def self.singleton_method_name(s)
|
|
643
|
+
self.ansi_color("#{s}", :magenta)
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
def self.instance_method_name(s)
|
|
647
|
+
self.ansi_color("#{s}", :cyan)
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
def self.class_name(s)
|
|
651
|
+
self.ansi_color("#{s}", :bright_blue)
|
|
652
|
+
end
|
|
653
|
+
|
|
654
|
+
HELP = <<EOT
|
|
655
|
+
|
|
656
|
+
There are four types of #{WebRI.variable('name')}, as determined by prefixes:
|
|
657
|
+
|
|
658
|
+
|------------------|----------------|--------------------|
|
|
659
|
+
| Type | Prefix | Example |
|
|
660
|
+
|------------------|----------------|--------------------|
|
|
661
|
+
| Class/module | Capital letter | #{WebRI.tokenq('Array')} |
|
|
662
|
+
| Singleton method | #{WebRI.tokenq('::')} | #{WebRI.tokenq('::new')} |
|
|
663
|
+
| Instance method | #{WebRI.tokenq('#')} | #{WebRI.tokenq('#inspect')} |
|
|
664
|
+
| Ruby file | #{WebRI.tokenq('ruby:')} | #{WebRI.tokenq('ruby:syntax_rdoc')} |
|
|
665
|
+
|------------------|----------------|--------------------|
|
|
666
|
+
|
|
667
|
+
Note: On the command-line, the instance method prefix should be escaped as #{WebRI.string('\\#')} if your shell requires it.
|
|
668
|
+
|
|
669
|
+
Name handling:
|
|
670
|
+
|
|
671
|
+
- If #{WebRI.variable('name')} is exactly a name of its type (but not the beginning of other such names),
|
|
672
|
+
#{WebRI.webri} opens the page for that name.
|
|
673
|
+
Examples: #{WebRI.tokenq('Array')}, #{WebRI.tokenq('::trap')}, #{WebRI.tokenq('#xmlschema')}, #{WebRI.tokenq('ruby:syntax_rdoc')}.
|
|
674
|
+
- If #{WebRI.variable('name')} is the beginning of exactly one name of its type,
|
|
675
|
+
#{WebRI.webri} asks whether to open the page for that name.
|
|
676
|
+
Examples: #{WebRI.tokenq('Arra')}, #{WebRI.tokenq('::tra')}, #{WebRI.tokenq('#xmlschem')}, #{WebRI.tokenq('ruby:syntax_')}.
|
|
677
|
+
- If #{WebRI.variable('name')} is the beginning of multiple names of its type,
|
|
678
|
+
#{WebRI.webri} displays those names and lets you choose.
|
|
679
|
+
Examples: #{WebRI.tokenq('A')}, #{WebRI.tokenq('::t')}, #{WebRI.tokenq('#')}, #{WebRI.tokenq('ruby:s')}.
|
|
680
|
+
- If #{WebRI.variable('name')} is not a valid name of its type,
|
|
681
|
+
#{WebRI.webri} asks whether show such names.
|
|
682
|
+
Examples: #{WebRI.tokenq('Xyzzy')}, #{WebRI.tokenq('::xyzzy')}, #{WebRI.tokenq('#xyzzy')}, #{WebRI.tokenq('ruby:xyzzy')}.
|
|
683
|
+
- If #{WebRI.variable('name')} is not valid at all (i.e., does not start with any of the prefixes above),
|
|
684
|
+
#{WebRI.webri} prints an error message.
|
|
685
|
+
Examples: #{WebRI.tokenq('nosuch')}, #{WebRI.tokenq('$foo')}, #{WebRI.tokenq('%Bar')}.
|
|
686
|
+
|
|
687
|
+
EOT
|
|
688
|
+
|
|
689
|
+
|
|
564
690
|
end
|