rib 0.1.0 → 0.9.0
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 +0 -4
- data/CHANGES.md +6 -0
- data/README +107 -113
- data/README.md +107 -113
- data/Rakefile +5 -3
- data/TODO.md +6 -0
- data/bin/rib-all +5 -0
- data/bin/rib-auto +9 -0
- data/bin/rib-min +5 -0
- data/bin/rib-rails +9 -0
- data/bin/rib-ramaze +9 -0
- data/lib/rib.rb +70 -6
- data/lib/rib/all.rb +0 -1
- data/lib/rib/api.rb +60 -64
- data/lib/rib/app/auto.rb +25 -0
- data/lib/rib/app/rails.rb +41 -0
- data/lib/rib/app/ramaze.rb +25 -0
- data/lib/rib/config.rb +3 -0
- data/lib/rib/core.rb +13 -1
- data/lib/rib/core/completion.rb +15 -3
- data/lib/rib/core/history.rb +56 -0
- data/lib/rib/core/multiline.rb +104 -0
- data/lib/rib/core/readline.rb +3 -1
- data/lib/rib/core/squeeze_history.rb +45 -0
- data/lib/rib/core/strip_backtrace.rb +45 -0
- data/lib/rib/core/underscore.rb +17 -8
- data/lib/rib/debug.rb +2 -1
- data/lib/rib/dep/hirb.rb +24 -0
- data/lib/rib/more.rb +4 -3
- data/lib/rib/more/anchor.rb +85 -0
- data/lib/rib/more/color.rb +44 -43
- data/lib/rib/{zore → more}/edit.rb +3 -3
- data/lib/rib/more/multiline_history.rb +24 -12
- data/lib/rib/more/multiline_history_file.rb +7 -3
- data/lib/rib/plugin.rb +2 -4
- data/lib/rib/runner.rb +84 -49
- data/lib/rib/shell.rb +4 -2
- data/lib/rib/test.rb +55 -2
- data/lib/rib/test/multiline.rb +140 -0
- data/lib/rib/version.rb +1 -1
- data/rib.gemspec +54 -22
- data/screenshot.png +0 -0
- data/task/gemgem.rb +3 -1
- data/test/core/{test_history_file.rb → test_history.rb} +29 -19
- data/test/core/test_multiline.rb +22 -0
- data/test/core/test_readline.rb +13 -8
- data/test/{more → core}/test_squeeze_history.rb +24 -18
- data/test/core/test_underscore.rb +32 -21
- data/test/more/test_multiline_history.rb +42 -0
- data/test/test_shell.rb +13 -8
- metadata +72 -27
- data/2011-02-28.md +0 -203
- data/CHANGES +0 -86
- data/TODO +0 -6
- data/lib/rib/core/history_file.rb +0 -38
- data/lib/rib/more/multiline.rb +0 -77
- data/lib/rib/more/squeeze_history.rb +0 -37
- data/lib/rib/more/strip_backtrace.rb +0 -43
- data/lib/rib/zore.rb +0 -3
- data/lib/rib/zore/anchor.rb +0 -69
data/Rakefile
CHANGED
@@ -10,10 +10,12 @@ task 'gem:spec' do
|
|
10
10
|
require 'rib/version'
|
11
11
|
s.name = 'rib'
|
12
12
|
s.version = Rib::VERSION
|
13
|
-
s.executables = [s.name]
|
14
13
|
|
15
|
-
%w[
|
16
|
-
%w[
|
14
|
+
%w[].each{ |g| s.add_runtime_dependency(g) }
|
15
|
+
%w[bond
|
16
|
+
hirb
|
17
|
+
bacon
|
18
|
+
rr] .each{ |g| s.add_development_dependency(g) }
|
17
19
|
end
|
18
20
|
|
19
21
|
Gemgem.write
|
data/TODO.md
ADDED
data/bin/rib-all
ADDED
data/bin/rib-auto
ADDED
data/bin/rib-min
ADDED
data/bin/rib-rails
ADDED
data/bin/rib-ramaze
ADDED
data/lib/rib.rb
CHANGED
@@ -3,40 +3,104 @@ require 'rib/shell'
|
|
3
3
|
|
4
4
|
module Rib
|
5
5
|
module_function
|
6
|
+
# All default Rib configs, would be passed to Shell.new in Rib.shell,
|
7
|
+
# but calling Shell.new directly won't bring this in.
|
6
8
|
def config
|
7
|
-
@config ||= {:config => '~/.config/rib/config.rb'}
|
9
|
+
@config ||= {:config => '~/.config/rib/config.rb', :name => 'rib'}
|
8
10
|
end
|
9
11
|
|
12
|
+
# All shells in the memory
|
10
13
|
def shells
|
11
14
|
@shells ||= []
|
12
15
|
end
|
13
16
|
|
17
|
+
# All shared variables for all shells
|
14
18
|
def vars
|
15
19
|
@vars ||= {}
|
16
20
|
end
|
17
21
|
|
22
|
+
# Convenient shell accessor, which would just give you current last shell
|
23
|
+
# or create one and load ~/.config/rib/config.rb if non has existed. If you
|
24
|
+
# need a clean shell which does not load rc file, use Shell.new instead.
|
18
25
|
def shell
|
19
26
|
shells.last || begin
|
20
|
-
|
27
|
+
if config_path
|
28
|
+
require_config
|
29
|
+
else # for those who don't have a config, we use core plugins
|
30
|
+
require 'rib/core'
|
31
|
+
end
|
21
32
|
(shells << Shell.new(config)).last
|
22
33
|
end
|
23
34
|
end
|
24
35
|
|
36
|
+
# All plugins which have been loaded into the memory regardless
|
37
|
+
# it's enabled or not.
|
25
38
|
def plugins
|
26
39
|
Shell.ancestors[1..-1].select{ |a| a < Plugin }
|
27
40
|
end
|
28
41
|
|
42
|
+
# Convenient way to disable all plugins in the memory.
|
43
|
+
# This could also take a list of plugins and disable them.
|
29
44
|
def disable_plugins plugs=plugins
|
30
45
|
plugs.each(&:disable)
|
31
46
|
end
|
32
47
|
|
48
|
+
# Convenient way to enable all plugins in the memory.
|
49
|
+
# This could also take a list of plugins and enable them.
|
33
50
|
def enable_plugins plugs=plugins
|
34
51
|
plugs.each(&:enable)
|
35
52
|
end
|
36
53
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
54
|
+
# Load (actually require) ~/.config/rib/config.rb if exists.
|
55
|
+
# This might emit warnings if there's some error while loading it.
|
56
|
+
def require_config
|
57
|
+
config_path && require(config_path)
|
58
|
+
rescue Exception => e
|
59
|
+
Rib.warn("Error loading #{config[:config]}\n" \
|
60
|
+
" #{Rib::API.format_error(e)}")
|
61
|
+
end
|
62
|
+
|
63
|
+
# The config path where Rib tries to load upon Rib.shell
|
64
|
+
def config_path
|
65
|
+
return nil unless config[:config]
|
66
|
+
path = File.expand_path(config[:config])
|
67
|
+
if File.exist?(path)
|
68
|
+
path
|
69
|
+
else
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Say (print to $stdout, with colors in the future, maybe)
|
75
|
+
# something by the name of Rib
|
76
|
+
def say *words
|
77
|
+
$stdout.puts(Rib.prepare(words))
|
78
|
+
end
|
79
|
+
|
80
|
+
# Warn (print to $stderr, with colors in the future, maybe)
|
81
|
+
# something by the name of Rib
|
82
|
+
def warn *words
|
83
|
+
$stderr.puts(Rib.prepare(words))
|
84
|
+
end
|
85
|
+
|
86
|
+
# Warn (print to $stderr, with colors in the future, maybe)
|
87
|
+
# something by the name of Rib and then exit(1)
|
88
|
+
def abort *words
|
89
|
+
warn(words)
|
90
|
+
exit(1)
|
91
|
+
end
|
92
|
+
|
93
|
+
def silence
|
94
|
+
w, v = $-w, $VERBOSE
|
95
|
+
$-w, $VERBOSE = false, false
|
96
|
+
yield
|
97
|
+
ensure
|
98
|
+
$-w, $VERBOSE = w, v
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def self.prepare words
|
103
|
+
name = config[:name]
|
104
|
+
"#{name}: #{words.join("\n#{' '*(name.size+2)}")}"
|
41
105
|
end
|
42
106
|
end
|
data/lib/rib/all.rb
CHANGED
data/lib/rib/api.rb
CHANGED
@@ -1,46 +1,57 @@
|
|
1
1
|
|
2
2
|
module Rib; end
|
3
3
|
module Rib::API
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# Called before shell starts looping
|
4
7
|
def before_loop
|
5
|
-
read_history
|
6
8
|
self
|
7
9
|
end
|
8
10
|
|
11
|
+
# Called after shell finishes looping
|
12
|
+
def after_loop
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
# Handle interrupt (control-c)
|
17
|
+
def handle_interrupt; puts ; end
|
18
|
+
# The prompt string of this shell
|
19
|
+
def prompt ; config[:prompt] ; end
|
20
|
+
# The result prompt string of this shell
|
21
|
+
def result_prompt; config[:result_prompt] ; end
|
22
|
+
# The name of this shell
|
23
|
+
def name ; config[:name] ; end
|
24
|
+
# The binding for evaluation
|
25
|
+
def eval_binding ; config[:binding] ; end
|
26
|
+
# The line number for next evaluation
|
27
|
+
def line ; config[:line] ; end
|
28
|
+
|
29
|
+
# Main loop
|
9
30
|
def in_loop
|
10
31
|
input = catch(:rib_exit){ loop_once while true }
|
11
32
|
puts if input == nil
|
12
33
|
end
|
13
34
|
|
14
|
-
#
|
35
|
+
# Loop iteration: REPL
|
15
36
|
def loop_once
|
16
|
-
|
17
|
-
input = get_input
|
37
|
+
input, result, err = get_input, nil, nil
|
18
38
|
throw(:rib_exit, input) if config[:exit].include?(input)
|
19
|
-
|
20
|
-
eval_input(input)
|
21
|
-
|
22
|
-
|
39
|
+
catch(:rib_skip) do
|
40
|
+
result, err = eval_input(input)
|
41
|
+
if err
|
42
|
+
print_eval_error(err)
|
43
|
+
elsif input.strip != ''
|
44
|
+
print_result(result)
|
45
|
+
else
|
46
|
+
# print nothing for blank input
|
47
|
+
end
|
23
48
|
end
|
49
|
+
[result, err]
|
24
50
|
rescue Interrupt
|
25
51
|
handle_interrupt
|
26
52
|
end
|
27
53
|
|
28
|
-
#
|
29
|
-
def handle_interrupt() puts end
|
30
|
-
|
31
|
-
# Sets @result to result of evaling input and print unexpected errors
|
32
|
-
def eval_input(input)
|
33
|
-
loop_eval(input)
|
34
|
-
rescue Exception => e
|
35
|
-
self.error_raised = true
|
36
|
-
print_eval_error(e)
|
37
|
-
ensure
|
38
|
-
config[:line] += 1
|
39
|
-
end
|
40
|
-
|
41
|
-
# When extending this method, ensure your plugin disables readline:
|
42
|
-
# Readline.config[:readline] = false.
|
43
|
-
# @return [String, nil] Prints #prompt and returns input given by user
|
54
|
+
# Get user input. This is most likely overrided in Readline plugin
|
44
55
|
def get_input
|
45
56
|
print(prompt)
|
46
57
|
if input = $stdin.gets
|
@@ -50,56 +61,41 @@ module Rib::API
|
|
50
61
|
end
|
51
62
|
end
|
52
63
|
|
53
|
-
#
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def write_history
|
62
|
-
end
|
63
|
-
|
64
|
-
def history
|
65
|
-
@history ||= []
|
66
|
-
end
|
67
|
-
|
68
|
-
# Evals user input using @binding, @name and @line
|
69
|
-
def loop_eval(input)
|
70
|
-
config[:binding].eval(input, "(#{config[:name]})", config[:line])
|
64
|
+
# Evaluate the input using #loop_eval and handle it
|
65
|
+
def eval_input input
|
66
|
+
[loop_eval(input), nil]
|
67
|
+
rescue Exception => e
|
68
|
+
[nil, e]
|
69
|
+
ensure
|
70
|
+
config[:line] += 1
|
71
71
|
end
|
72
72
|
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
def print_eval_error(err)
|
77
|
-
warn format_error(err)
|
73
|
+
# Evaluate user input with #eval_binding, name and line
|
74
|
+
def loop_eval input
|
75
|
+
eval_binding.eval(input, "(#{name})", line)
|
78
76
|
end
|
79
77
|
|
80
|
-
#
|
81
|
-
def print_result
|
82
|
-
puts(format_result(result))
|
78
|
+
# Print result using #format_result
|
79
|
+
def print_result result
|
80
|
+
puts(format_result(result))
|
83
81
|
rescue StandardError, SyntaxError => e
|
84
|
-
warn
|
85
|
-
"#{format_error(e)}"
|
82
|
+
Rib.warn("Error while printing result:\n #{format_error(e)}")
|
86
83
|
end
|
87
84
|
|
88
|
-
#
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
"
|
85
|
+
# Print evaluated error using #format_error
|
86
|
+
def print_eval_error err
|
87
|
+
puts(format_error(err))
|
88
|
+
rescue StandardError, SyntaxError => e
|
89
|
+
Rib.warn("Error while printing error:\n #{format_error(e)}")
|
93
90
|
end
|
94
91
|
|
95
|
-
#
|
96
|
-
def format_result
|
97
|
-
|
92
|
+
# Format result using #result_prompt
|
93
|
+
def format_result result
|
94
|
+
result_prompt + result.inspect
|
98
95
|
end
|
99
96
|
|
100
|
-
#
|
101
|
-
def
|
102
|
-
|
103
|
-
self
|
97
|
+
# Format error raised in #loop_eval
|
98
|
+
def format_error err
|
99
|
+
"#{err.class}: #{err.message}\n #{err.backtrace.join("\n ")}"
|
104
100
|
end
|
105
101
|
end
|
data/lib/rib/app/auto.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module Rib; end
|
3
|
+
module Rib::Auto
|
4
|
+
module_function
|
5
|
+
def load
|
6
|
+
app, name = %w[ramaze rails].find{ |name|
|
7
|
+
require "rib/app/#{name}"
|
8
|
+
app = Rib.const_get(name.capitalize)
|
9
|
+
if app.send("#{name}?")
|
10
|
+
break app, name
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
if app
|
15
|
+
Rib.say("Found #{name.capitalize}, loading it...")
|
16
|
+
begin
|
17
|
+
app.load
|
18
|
+
rescue LoadError => e
|
19
|
+
Rib.warn("Is this a #{app} app?\n #{e}")
|
20
|
+
end
|
21
|
+
else
|
22
|
+
Rib.warn("No app found")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
module Rib; end
|
3
|
+
module Rib::Rails
|
4
|
+
module_function
|
5
|
+
def load
|
6
|
+
load_rails
|
7
|
+
rescue LoadError => e
|
8
|
+
Rib.abort("Is this a Rails app?\n #{e}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_rails
|
12
|
+
require './config/boot'
|
13
|
+
|
14
|
+
if File.exist?('./config/application.rb')
|
15
|
+
Rib::Rails.load_rails3
|
16
|
+
else
|
17
|
+
Rib::Rails.load_rails2
|
18
|
+
end
|
19
|
+
|
20
|
+
puts("Loading #{::Rails.env} environment (Rails #{::Rails.version})")
|
21
|
+
end
|
22
|
+
|
23
|
+
def load_rails2
|
24
|
+
['./config/environment',
|
25
|
+
'console_app' ,
|
26
|
+
'console_with_helpers'].each{ |f| require f }
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_rails3
|
30
|
+
['./config/application',
|
31
|
+
'rails/console/app' ,
|
32
|
+
'rails/console/helpers'].each{ |f| require f }
|
33
|
+
|
34
|
+
::Rails.application.require_environment!
|
35
|
+
end
|
36
|
+
|
37
|
+
def rails?
|
38
|
+
File.exist?('./config/boot.rb') &&
|
39
|
+
File.exist?('./config/environment.rb')
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module Rib; end
|
3
|
+
module Rib::Ramaze
|
4
|
+
module_function
|
5
|
+
def load
|
6
|
+
load_ramaze
|
7
|
+
rescue LoadError => e
|
8
|
+
Rib.abort("Is this a Ramaze app?\n #{e}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_ramaze
|
12
|
+
# try to produce consistent error message, and yet lazy loading ramaze
|
13
|
+
require './start' unless ramaze?
|
14
|
+
|
15
|
+
require 'ramaze'
|
16
|
+
::Ramaze.options.started = true
|
17
|
+
|
18
|
+
require './start'
|
19
|
+
at_exit{ puts('Ramazement has ended, go in peace.') }
|
20
|
+
end
|
21
|
+
|
22
|
+
def ramaze?
|
23
|
+
File.exist?('./start.rb')
|
24
|
+
end
|
25
|
+
end
|