fancy_irb 1.4.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/MIT-LICENSE.txt +1 -1
- data/README.md +12 -16
- data/fancy_irb.gemspec +8 -7
- data/lib/fancy_irb/implementation.rb +10 -21
- data/lib/fancy_irb/irb_ext.rb +4 -4
- data/lib/fancy_irb/size_detector.rb +1 -3
- data/lib/fancy_irb/version.rb +1 -1
- data/spec/size_detector_spec.rb +0 -14
- metadata +37 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 420f2bb457ec0eab47d8b118dc0579cc010060338406972fe53e9339411988ff
|
4
|
+
data.tar.gz: 7a6adaf799dd94809ed4c8c998827983a2d7105a22b42449fc3f7ffdff6c2a05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e61b4ad622dce35fccbfdb7f47beaa3aeed028d08aacbb051bb8d48b2a1140e1cc22686805fbab831968d09519947e0b9215686acc37fef495cb2d8ac8cc3b82
|
7
|
+
data.tar.gz: 89a2464bb36c7385792f3cb7dc7e9a3336c81249c9f07b80060dbf9248abc85ad97a21d35a050679107dd53b0899d029796c650d979a328b037c33777d4ee279
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.0.0
|
4
|
+
* Fix core functionality for newer IRB
|
5
|
+
* Require Ruby 3.x / IRB 1.7+
|
6
|
+
* Bump display-width gem to latest version
|
7
|
+
* Remove option to disable display-width check, since it now has good performance
|
8
|
+
|
3
9
|
## 1.4.3
|
4
10
|
* Fix options given to `script` so it doesn't output timing info
|
5
11
|
|
data/MIT-LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
# FancyIrb [![version](https://badge.fury.io/rb/fancy_irb.svg)](https://badge.fury.io/rb/fancy_irb) [![[ci]](https://github.com/janlelis/fancy_irb/workflows/Test/badge.svg)](https://github.com/janlelis/fancy_irb/actions?query=workflow%3ATest)
|
2
2
|
|
3
3
|
* Colorizes IRB prompts, errors, `$stderr` and `$stdout`
|
4
|
-
* Uses "Hash Rockets" (
|
4
|
+
* Uses "Hash Rockets" (#=>) to display IRB results
|
5
|
+
|
6
|
+
## Version 2.0 for Modern IRB
|
7
|
+
|
8
|
+
**Please note:** Version 2.0 of this gem requires Ruby 3 and IRB 1.7+
|
5
9
|
|
6
10
|
## Usage
|
7
11
|
|
8
12
|
require 'fancy_irb'
|
9
13
|
FancyIrb.start
|
10
14
|
|
11
|
-
You can pass an options hash. These are the default values:
|
15
|
+
You can pass an options hash as argument. These are the default values:
|
12
16
|
|
13
17
|
DEFAULT_OPTIONS = {
|
14
18
|
:rocket_mode => true, # activate or deactivate #=> rocket
|
15
19
|
:rocket_prompt => '#=> ', # prompt to use for the rocket
|
16
20
|
:result_prompt => '=> ', # prompt to use for normal output
|
17
|
-
:unicode_display_width => true, # set to false if you don't want to check for proper
|
18
|
-
# string width for better performance
|
19
21
|
:colorize => { # colors hash. Set to nil to deactivate colors
|
20
22
|
:rocket_prompt => [:blue],
|
21
23
|
:result_prompt => [:blue],
|
@@ -27,27 +29,21 @@ You can pass an options hash. These are the default values:
|
|
27
29
|
},
|
28
30
|
}
|
29
31
|
|
30
|
-
Rocket mode means:
|
31
|
-
the
|
32
|
-
height.
|
32
|
+
Rocket mode means: Instead of displaying the result on the next line, show it
|
33
|
+
on the same line (if there is enough space)
|
33
34
|
|
34
35
|
For more information on which colors can be used, see the [paint documentation](https://github.com/janlelis/paint).
|
35
36
|
|
36
37
|
## Troubleshooting
|
37
38
|
### Windows Support
|
38
|
-
You will need [ansicon](https://github.com/adoxa/ansicon) or [ConEmu](https://code.google.com/p/conemu-maximus5/).
|
39
|
-
|
40
|
-
### Need More Performance?
|
41
|
-
The gem checks for the Unicode display width of characters, which requires a
|
42
|
-
lookup of every character. You can deactivate this check by setting
|
43
|
-
`:unicode_display_width` to `false`.
|
39
|
+
You will need [ansicon](https://github.com/adoxa/ansicon) or [ConEmu](https://code.google.com/p/conemu-maximus5/) or [WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
|
44
40
|
|
45
41
|
### Known Bugs
|
46
|
-
Not all
|
47
|
-
focuses on the
|
42
|
+
Not all methods dealing with input data are patched properly to work with the rocket,
|
43
|
+
the gem focuses on the commonly used ones, like `gets` or `getc`.
|
48
44
|
|
49
45
|
## J-_-L
|
50
46
|
Inspired by the irb_rocket gem by genki.
|
51
47
|
|
52
|
-
Copyright (c) 2010-2012, 2015-
|
48
|
+
Copyright (c) 2010-2012, 2015-2023 Jan Lelis <https://janlelis.com> released under
|
53
49
|
the MIT license.
|
data/fancy_irb.gemspec
CHANGED
@@ -8,15 +8,16 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Jan Lelis"]
|
9
9
|
s.email = ["hi@ruby.consulting"]
|
10
10
|
s.homepage = "https://github.com/janlelis/fancy_irb"
|
11
|
-
s.summary = "
|
12
|
-
s.description = "A fancy IRB has
|
13
|
-
s.required_ruby_version = '>=
|
11
|
+
s.summary = "Colors and rockets in IRB"
|
12
|
+
s.description = "A fancy IRB has rocket-style #=> return values and colorful prompts and streams."
|
13
|
+
s.required_ruby_version = '>= 3.0', '< 4.0'
|
14
|
+
s.metadata = { "rubygems_mfa_required" => "true" }
|
14
15
|
s.license = 'MIT'
|
15
|
-
s.requirements = ['Windows: ansicon <https://github.com/adoxa/ansicon>']
|
16
16
|
s.add_dependency 'paint', '>= 0.9', '< 3.0'
|
17
|
-
s.add_dependency '
|
18
|
-
s.
|
19
|
-
s.add_development_dependency '
|
17
|
+
s.add_dependency 'irb', '>= 1.7', '< 2.0'
|
18
|
+
s.add_dependency 'unicode-display_width', '>= 2.5'
|
19
|
+
s.add_development_dependency 'rspec', '~> 3.2'
|
20
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
20
21
|
s.files = [
|
21
22
|
"MIT-LICENSE.txt",
|
22
23
|
"README.md",
|
@@ -50,19 +50,14 @@ module FancyIrb
|
|
50
50
|
}
|
51
51
|
end
|
52
52
|
|
53
|
-
def unicode_display_width?
|
54
|
-
@options[:unicode_display_width] || @options[:east_asian_width]
|
55
|
-
end
|
56
|
-
alias east_asian_width? unicode_display_width?
|
57
|
-
|
58
53
|
def reset_line!
|
59
54
|
@tracked_height = 0
|
60
55
|
@tracked_indent = 0
|
61
56
|
end
|
62
57
|
|
63
|
-
def handle_prompt(prompt, scanner_indent
|
64
|
-
@tracked_indent = 2 if track_indent
|
65
|
-
@current_indent = width_of(prompt) + scanner_indent + @tracked_indent
|
58
|
+
def handle_prompt(prompt, scanner_indent)#, track_indent)
|
59
|
+
# @tracked_indent = 2 if track_indent
|
60
|
+
@current_indent = width_of(prompt) + scanner_indent# + @tracked_indent
|
66
61
|
|
67
62
|
append_input_color colorize(prompt, :input_prompt)
|
68
63
|
end
|
@@ -84,14 +79,11 @@ module FancyIrb
|
|
84
79
|
end
|
85
80
|
end
|
86
81
|
|
87
|
-
def output_value(context,
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
def show_output(output, scanner)
|
82
|
+
def output_value(context, _scanner)
|
83
|
+
output = context.inspect_last_value
|
92
84
|
if @options[:rocket_mode] && !@skip_next_rocket && !output.include?("\n")
|
93
|
-
offset =
|
94
|
-
cols_to_show =
|
85
|
+
offset = get_offset_from_reline
|
86
|
+
cols_to_show = offset + width_of(@options[:rocket_prompt] + output)
|
95
87
|
lines_to_show = 1 + @tracked_height
|
96
88
|
|
97
89
|
if TerminalInfo.lines > lines_to_show && TerminalInfo.cols > cols_to_show
|
@@ -110,15 +102,12 @@ module FancyIrb
|
|
110
102
|
puts colorize(@options[:result_prompt], :result_prompt) + output
|
111
103
|
end
|
112
104
|
|
113
|
-
def
|
114
|
-
|
105
|
+
def get_offset_from_reline
|
106
|
+
last_buffer = (Reline::HISTORY || [])[-1] || ""
|
107
|
+
last_line = last_buffer.split("\n").last
|
115
108
|
1 + @current_indent + width_of(last_line)
|
116
109
|
end
|
117
110
|
|
118
|
-
def get_cols_to_show_from_output_and_offset(output, offset)
|
119
|
-
offset + width_of(@options[:rocket_prompt] + output)
|
120
|
-
end
|
121
|
-
|
122
111
|
# TODO testing and improving, e.g. getc does not contain "\n"
|
123
112
|
def register_height_trackers(object, methods_)
|
124
113
|
methods_.each{ |method_|
|
data/lib/fancy_irb/irb_ext.rb
CHANGED
@@ -5,11 +5,11 @@ module IRB
|
|
5
5
|
end
|
6
6
|
|
7
7
|
alias prompt_non_fancy prompt
|
8
|
-
def prompt(
|
8
|
+
def prompt(prompt_arg, ltype, indent, line_no)
|
9
9
|
FancyIrb.handle_prompt(
|
10
|
-
prompt_non_fancy(
|
11
|
-
IRB.conf[:AUTO_INDENT] ?
|
12
|
-
IRB.conf[:AUTO_INDENT] && IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]][:PROMPT_C] ==
|
10
|
+
prompt_non_fancy(prompt_arg, ltype, indent, line_no),
|
11
|
+
IRB.conf[:AUTO_INDENT] ? indent * 2 : 0
|
12
|
+
# IRB.conf[:AUTO_INDENT] && IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]][:PROMPT_C] == prompt_arg
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
@@ -3,9 +3,7 @@ module FancyIrb
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def width_of(data)
|
6
|
-
|
7
|
-
data = Paint.unpaint data.to_s
|
8
|
-
FancyIrb.unicode_display_width? ? Unicode::DisplayWidth.of(data) : data.length
|
6
|
+
Unicode::DisplayWidth.of(Paint.unpaint(data.to_s))
|
9
7
|
end
|
10
8
|
|
11
9
|
def height_of(data, width)
|
data/lib/fancy_irb/version.rb
CHANGED
data/spec/size_detector_spec.rb
CHANGED
@@ -4,10 +4,6 @@ require_relative 'fixtures'
|
|
4
4
|
describe FancyIrb::SizeDetector do
|
5
5
|
include FancyIrb::SizeDetector
|
6
6
|
|
7
|
-
before do
|
8
|
-
FancyIrb.instance_variable_set(:@options, { unicode_display_width: true })
|
9
|
-
end
|
10
|
-
|
11
7
|
describe ".width_of" do
|
12
8
|
it "returns 0 when no data given" do
|
13
9
|
expect( width_of(nil) ).to eq 0
|
@@ -24,16 +20,6 @@ describe FancyIrb::SizeDetector do
|
|
24
20
|
it "respects double-width chars by default" do
|
25
21
|
expect( width_of('一') ).to eq 2
|
26
22
|
end
|
27
|
-
|
28
|
-
context "unicode_display_width? false" do
|
29
|
-
before do
|
30
|
-
FancyIrb.instance_variable_set(:@options, { unicode_display_width: false })
|
31
|
-
end
|
32
|
-
|
33
|
-
it "does not respect double-width chars" do
|
34
|
-
expect( width_of('一') ).to eq 1
|
35
|
-
end
|
36
|
-
end
|
37
23
|
end
|
38
24
|
|
39
25
|
describe ".height_of" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancy_irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paint
|
@@ -30,20 +30,40 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: irb
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.7'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.7'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.0'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: unicode-display_width
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|
36
56
|
requirements:
|
37
57
|
- - ">="
|
38
58
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
59
|
+
version: '2.5'
|
40
60
|
type: :runtime
|
41
61
|
prerelease: false
|
42
62
|
version_requirements: !ruby/object:Gem::Requirement
|
43
63
|
requirements:
|
44
64
|
- - ">="
|
45
65
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
66
|
+
version: '2.5'
|
47
67
|
- !ruby/object:Gem::Dependency
|
48
68
|
name: rspec
|
49
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,16 +84,16 @@ dependencies:
|
|
64
84
|
requirements:
|
65
85
|
- - "~>"
|
66
86
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
87
|
+
version: '13.0'
|
68
88
|
type: :development
|
69
89
|
prerelease: false
|
70
90
|
version_requirements: !ruby/object:Gem::Requirement
|
71
91
|
requirements:
|
72
92
|
- - "~>"
|
73
93
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
75
|
-
description: 'A fancy IRB has
|
76
|
-
|
94
|
+
version: '13.0'
|
95
|
+
description: 'A fancy IRB has rocket-style #=> return values and colorful prompts
|
96
|
+
and streams.'
|
77
97
|
email:
|
78
98
|
- hi@ruby.consulting
|
79
99
|
executables: []
|
@@ -100,7 +120,8 @@ files:
|
|
100
120
|
homepage: https://github.com/janlelis/fancy_irb
|
101
121
|
licenses:
|
102
122
|
- MIT
|
103
|
-
metadata:
|
123
|
+
metadata:
|
124
|
+
rubygems_mfa_required: 'true'
|
104
125
|
post_install_message:
|
105
126
|
rdoc_options: []
|
106
127
|
require_paths:
|
@@ -109,16 +130,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
130
|
requirements:
|
110
131
|
- - ">="
|
111
132
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
133
|
+
version: '3.0'
|
134
|
+
- - "<"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '4.0'
|
113
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
138
|
requirements:
|
115
139
|
- - ">="
|
116
140
|
- !ruby/object:Gem::Version
|
117
141
|
version: '0'
|
118
|
-
requirements:
|
119
|
-
|
120
|
-
rubygems_version: 3.2.3
|
142
|
+
requirements: []
|
143
|
+
rubygems_version: 3.4.4
|
121
144
|
signing_key:
|
122
145
|
specification_version: 4
|
123
|
-
summary:
|
146
|
+
summary: Colors and rockets in IRB
|
124
147
|
test_files: []
|