rib 1.2.0 → 1.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/CHANGES.md +10 -0
- data/README.md +139 -43
- data/lib/rib.rb +1 -1
- data/lib/rib/api.rb +2 -1
- data/lib/rib/extra/paging.rb +41 -0
- data/lib/rib/more/edit.rb +7 -2
- data/lib/rib/version.rb +1 -1
- data/rib.gemspec +4 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a52587cf79d9a191c020346fa3ba53bd5fc12b2
|
4
|
+
data.tar.gz: 522742f98cf7356531ae48892815444978971b31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be4aed6f46a7a7c73f6713885903d0ed8309a6265bcece16c7dafa1539660c0571735f9b5464dc3435df5692c0a8b4c7603bace1eb7727b132d589f7443fb5f4
|
7
|
+
data.tar.gz: dcbbaadd88bed8fae8508e13840d908a82851a630d05d35e93d7d065bf698d4b5a995cec68ee940489f3e8b1e102142c61e1643cea1958441adcb35c5c4ae06b
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Rib 1.2.1 -- 2014-01-18
|
4
|
+
|
5
|
+
* Fixed a bug where it cannot properly elegantly handle errors when loading
|
6
|
+
the config file.
|
7
|
+
|
8
|
+
* [extra/paging] This plugin would try to use $PAGER and by default less to
|
9
|
+
paginate for output which cannot fit in a screen.
|
10
|
+
|
11
|
+
* [more/edit] Now by default it would pick vim if $EDITOR is not set.
|
12
|
+
|
3
13
|
## Rib 1.2.0 -- 2014-01-17
|
4
14
|
|
5
15
|
* We no longer really eval on TOPLEVEL_BINDING, but a private binding
|
data/README.md
CHANGED
@@ -100,42 +100,32 @@ with other plugins, or having strong personal tastes, so you won't want to
|
|
100
100
|
enable them all. Suppose you only want to use the core plugins and color
|
101
101
|
plugin, you'll put this into your config file:
|
102
102
|
|
103
|
-
|
104
|
-
|
103
|
+
``` ruby
|
104
|
+
require 'rib/core'
|
105
|
+
require 'rib/more/color'
|
106
|
+
```
|
105
107
|
|
106
108
|
You can also write your plugins there. Here's another example:
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
-
|
110
|
+
``` ruby
|
111
|
+
require 'rib/core'
|
112
|
+
require 'pp'
|
113
|
+
Rib.config[:prompt] = '$ '
|
111
114
|
|
112
|
-
|
113
|
-
|
115
|
+
module RibPP
|
116
|
+
Rib::Shell.send(:include, self)
|
114
117
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
118
|
+
def format_result result
|
119
|
+
result_prompt + result.pretty_inspect
|
120
|
+
end
|
121
|
+
end
|
122
|
+
```
|
119
123
|
|
120
124
|
So that we override the original format_result to pretty_inspect the result.
|
121
125
|
You can also build your own gem and then simply require it in your config
|
122
126
|
file. To see a list of overridable API, please read [api.rb][]
|
123
127
|
|
124
|
-
Currently, there are two **extra plugins**.
|
125
|
-
|
126
|
-
* `require 'rib/extra/autoindent'` This plugin is depending on:
|
127
|
-
|
128
|
-
1. [readline_buffer][]
|
129
|
-
2. readline plugin
|
130
|
-
3. multiline plugin
|
131
|
-
|
132
|
-
* `require 'rib/extra/hirb'` This plugin is depending on:
|
133
|
-
|
134
|
-
1. [hirb][]
|
135
|
-
|
136
128
|
[api.rb]: https://github.com/godfat/rib/blob/master/lib/rib/api.rb
|
137
|
-
[readline_buffer]: https://github.com/godfat/readline_buffer
|
138
|
-
[hirb]: https://github.com/cldwalker/hirb
|
139
129
|
|
140
130
|
#### Basic configuration
|
141
131
|
|
@@ -159,27 +149,129 @@ Rib.config[:history_size] | Default is 500
|
|
159
149
|
Rib.config[:color] | A hash of Class => :color mapping
|
160
150
|
Rib.config[:autoindent_spaces] | How to indent? Default is two spaces: ' '
|
161
151
|
|
152
|
+
#### List of core plugins
|
153
|
+
|
154
|
+
``` ruby
|
155
|
+
require 'rib/core' # You get all of the followings:
|
156
|
+
```
|
157
|
+
|
158
|
+
* `require 'rib/core/completion'`
|
159
|
+
|
160
|
+
Completion from [bond][].
|
161
|
+
|
162
|
+
* `require 'rib/core/history'`
|
163
|
+
|
164
|
+
Remember history in a history file.
|
165
|
+
|
166
|
+
* `require 'rib/core/strip_backtrace'`
|
167
|
+
|
168
|
+
Strip backtrace before Rib.
|
169
|
+
|
170
|
+
* `require 'rib/core/readline'`
|
171
|
+
|
172
|
+
Readline support.
|
173
|
+
|
174
|
+
* `require 'rib/core/multiline'`
|
175
|
+
|
176
|
+
You can interpret multiple lines.
|
177
|
+
|
178
|
+
* `require 'rib/core/squeeze_history'`
|
179
|
+
|
180
|
+
Remove duplicated input from history.
|
181
|
+
|
182
|
+
* `require 'rib/core/underscore'`
|
183
|
+
|
184
|
+
Save the last result in `_` and the last exception in `__`.
|
185
|
+
|
186
|
+
#### List of more plugins
|
187
|
+
|
188
|
+
``` ruby
|
189
|
+
require 'rib/more' # You get all of the followings:
|
190
|
+
```
|
191
|
+
|
192
|
+
* `require 'rib/more/multiline_history_file'`
|
193
|
+
|
194
|
+
Not only readline could have multiline history, but also the history file.
|
195
|
+
|
196
|
+
* `require 'rib/more/color'`
|
197
|
+
|
198
|
+
Class based colorizing.
|
199
|
+
|
200
|
+
* `require 'rib/more/multiline_history'`
|
201
|
+
|
202
|
+
Make readline aware of multiline history.
|
203
|
+
|
204
|
+
* `require 'rib/more/anchor'`
|
205
|
+
|
206
|
+
See _As a debugging/interacting tool_.
|
207
|
+
|
208
|
+
* `require 'rib/more/edit'`
|
209
|
+
|
210
|
+
See _In place editing_.
|
211
|
+
|
212
|
+
### List of extra plugins
|
213
|
+
|
214
|
+
There's no `require 'rib/extra'` for extra plugins because they might not
|
215
|
+
be doing what you would expect or want, or having an external dependency,
|
216
|
+
or having conflicted semantics.
|
217
|
+
|
218
|
+
* `require 'rib/extra/autoindent'` This plugin is depending on:
|
219
|
+
|
220
|
+
1. [readline_buffer][]
|
221
|
+
2. readline plugin
|
222
|
+
3. multiline plugin
|
223
|
+
|
224
|
+
Which would autoindent your input.
|
225
|
+
|
226
|
+
* `require 'rib/extra/hirb'` This plugin is depending on:
|
227
|
+
|
228
|
+
1. [hirb][]
|
229
|
+
|
230
|
+
Which would print the result with hirb.
|
231
|
+
|
232
|
+
* `require 'rib/extra/debugger'` This plugin is depending on:
|
233
|
+
|
234
|
+
1. [debugger][]
|
235
|
+
|
236
|
+
Which introduces `Rib.debug`, which would do similar things as
|
237
|
+
`Rib.anchor` but only more powerful. However, this is not well
|
238
|
+
tested and might not work well. Please let me know if you have
|
239
|
+
any issue using it, thanks!
|
240
|
+
|
241
|
+
* `require 'rib/extra/paging'` This plugin is depending on `less`.
|
242
|
+
|
243
|
+
Which would pass the result to `less` (or `$PAGER` if set) if
|
244
|
+
the result string is longer than the screen.
|
245
|
+
|
246
|
+
[readline_buffer]: https://github.com/godfat/readline_buffer
|
247
|
+
[hirb]: https://github.com/cldwalker/hirb
|
248
|
+
[debugger]: https://github.com/cldwalker/debugger
|
249
|
+
|
162
250
|
### As a debugging/interacting tool
|
163
251
|
|
164
252
|
Rib could be used as a kind of debugging tool which you can set break point
|
165
253
|
in the source program.
|
166
254
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
255
|
+
``` ruby
|
256
|
+
require 'rib/config' # This would load your Rib config
|
257
|
+
require 'rib/more/anchor'
|
258
|
+
# If you enabled anchor in config, then needed not
|
259
|
+
Rib.anchor binding # This would give you an interactive shell
|
260
|
+
# when your program has been executed here.
|
261
|
+
Rib.anchor 123 # You can also anchor on an object.
|
262
|
+
```
|
173
263
|
|
174
264
|
But this might be called in a loop, you might only want to
|
175
265
|
enter the shell under certain circumstance, then you'll do:
|
176
266
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
267
|
+
``` ruby
|
268
|
+
require 'rib/debug'
|
269
|
+
Rib.enable_anchor do
|
270
|
+
# Only `Rib.anchor` called in the block would launch a shell
|
271
|
+
end
|
181
272
|
|
182
|
-
|
273
|
+
Rib.anchor binding # No effect (no-op) outside the block
|
274
|
+
```
|
183
275
|
|
184
276
|
Anchor could also be nested. The level would be shown on the prompt,
|
185
277
|
starting from 1.
|
@@ -188,19 +280,23 @@ starting from 1.
|
|
188
280
|
|
189
281
|
Whenever you called:
|
190
282
|
|
191
|
-
|
192
|
-
|
283
|
+
``` ruby
|
284
|
+
require 'rib/more/edit'
|
285
|
+
Rib.edit
|
286
|
+
```
|
193
287
|
|
194
|
-
Rib would open an editor according to
|
195
|
-
|
196
|
-
|
197
|
-
or rib/more or rib/all.
|
288
|
+
Rib would open an editor according to `$EDITOR` (`ENV['EDITOR']`) for you.
|
289
|
+
By default it would pick vim if no `$EDITOR` was set. After save and leave
|
290
|
+
the editor, Rib would evaluate what you had input. This also works inside
|
291
|
+
an anchor. To use it, require either rib/more/edit or rib/more or rib/all.
|
198
292
|
|
199
293
|
### As a shell framework
|
200
294
|
|
201
295
|
The essence is:
|
202
296
|
|
203
|
-
|
297
|
+
``` ruby
|
298
|
+
require 'rib'
|
299
|
+
```
|
204
300
|
|
205
301
|
All others are optional. The core plugins are lying in `rib/core/*.rb`, and
|
206
302
|
more plugins are lying in `rib/more/*.rb`. You can read `rib/app/ramaze.rb`
|
data/lib/rib.rb
CHANGED
@@ -68,7 +68,7 @@ module Rib
|
|
68
68
|
result = require(config_path)
|
69
69
|
Rib.say("Config loaded from: #{config_path}") if $VERBOSE && result
|
70
70
|
result
|
71
|
-
rescue
|
71
|
+
rescue StandardError, LoadError, SyntaxError => e
|
72
72
|
Rib.warn("Error loading #{config[:config]}\n" \
|
73
73
|
" #{Rib::API.format_error(e)}")
|
74
74
|
end
|
data/lib/rib/api.rb
CHANGED
@@ -100,11 +100,12 @@ module Rib::API
|
|
100
100
|
def format_error err
|
101
101
|
"#{err.class}: #{err.message}\n #{err.backtrace.join("\n ")}"
|
102
102
|
end
|
103
|
+
module_function :format_error
|
103
104
|
|
104
105
|
private
|
105
106
|
def equal_rib_skip result
|
106
107
|
result == Rib::Skip
|
107
|
-
rescue
|
108
|
+
rescue
|
108
109
|
# do nothing, it cannot respond to == correctly, it can't be Rib::Skip
|
109
110
|
end
|
110
111
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
require 'rib'
|
3
|
+
|
4
|
+
module Rib::Paging
|
5
|
+
extend Rib::Plugin
|
6
|
+
Shell.use(self)
|
7
|
+
|
8
|
+
# --------------- Rib API ---------------
|
9
|
+
|
10
|
+
# Print result if the it fits one screen,
|
11
|
+
# paging it through a pager otherwise.
|
12
|
+
def print_result result
|
13
|
+
output = format_result(result)
|
14
|
+
if one_screen?(output)
|
15
|
+
puts output
|
16
|
+
else
|
17
|
+
page_result(output)
|
18
|
+
end
|
19
|
+
rescue StandardError, SyntaxError => e
|
20
|
+
Rib.warn("Error while printing result:\n #{format_error(e)}")
|
21
|
+
end
|
22
|
+
|
23
|
+
# `less -F` can't cat the output, so we need to detect by ourselves.
|
24
|
+
# `less -X` would mess up the buffers, so it's not desired, either.
|
25
|
+
def one_screen? output
|
26
|
+
cols, lines = `tput cols`.to_i, `tput lines`.to_i
|
27
|
+
output.count("\n") <= lines && output.size <= cols * lines
|
28
|
+
end
|
29
|
+
|
30
|
+
def page_result output
|
31
|
+
less = IO.popen(pager, 'w')
|
32
|
+
less.write(output)
|
33
|
+
less.close_write
|
34
|
+
rescue Errno::EPIPE => e
|
35
|
+
Rib.warn("Error while paging result:\n #{format_error(e)}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def pager
|
39
|
+
ENV['PAGER'] || 'less -R'
|
40
|
+
end
|
41
|
+
end
|
data/lib/rib/more/edit.rb
CHANGED
@@ -13,9 +13,10 @@ module Rib::Edit
|
|
13
13
|
file.puts(Rib.vars[:edit])
|
14
14
|
file.close
|
15
15
|
|
16
|
-
|
16
|
+
shell = Rib.shell
|
17
|
+
system("#{shell.editor} #{file.path}")
|
17
18
|
|
18
|
-
if
|
19
|
+
if shell.running?
|
19
20
|
shell.send(:multiline_buffer).pop
|
20
21
|
else
|
21
22
|
shell.before_loop
|
@@ -29,5 +30,9 @@ module Rib::Edit
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
33
|
+
def editor
|
34
|
+
ENV['EDITOR'] || 'vim'
|
35
|
+
end
|
36
|
+
|
32
37
|
Rib.extend(Imp)
|
33
38
|
end
|
data/lib/rib/version.rb
CHANGED
data/rib.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: rib 1.2.
|
2
|
+
# stub: rib 1.2.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rib"
|
6
|
-
s.version = "1.2.
|
6
|
+
s.version = "1.2.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "2014-01-
|
11
|
+
s.date = "2014-01-18"
|
12
12
|
s.description = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell\n\nRib is based on the design of [ripl][] and the work of [ripl-rc][], some of\nthe features are also inspired by [pry][]. The aim of Rib is to be fully\nfeatured and yet very easy to opt-out or opt-in other features. It shall\nbe simple, lightweight and modular so that everyone could customize Rib.\n\n[ripl]: https://github.com/cldwalker/ripl\n[ripl-rc]: https://github.com/godfat/ripl-rc\n[pry]: https://github.com/pry/pry"
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
14
14
|
s.executables = [
|
@@ -56,6 +56,7 @@ Gem::Specification.new do |s|
|
|
56
56
|
"lib/rib/extra/autoindent.rb",
|
57
57
|
"lib/rib/extra/debugger.rb",
|
58
58
|
"lib/rib/extra/hirb.rb",
|
59
|
+
"lib/rib/extra/paging.rb",
|
59
60
|
"lib/rib/more.rb",
|
60
61
|
"lib/rib/more/anchor.rb",
|
61
62
|
"lib/rib/more/color.rb",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/rib/extra/autoindent.rb
|
71
71
|
- lib/rib/extra/debugger.rb
|
72
72
|
- lib/rib/extra/hirb.rb
|
73
|
+
- lib/rib/extra/paging.rb
|
73
74
|
- lib/rib/more.rb
|
74
75
|
- lib/rib/more/anchor.rb
|
75
76
|
- lib/rib/more/color.rb
|