fancy_irb 1.4.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2983518481e3a3ea0996fa0db0b8eb01bf6a0c72072171746ff1dfe1fc4786f
4
- data.tar.gz: 44d632ee043c0751300cd7ee48fddbd03e9086084f061803c6a1764d6a3ff706
3
+ metadata.gz: 89cbb2934ed19ad839cdc15eda21b617c01eb2bd6e689a54012c8eeee98098b9
4
+ data.tar.gz: dcded533d53ac26e54bce266d2a80eea702c38b22173735b014e50b163f258c8
5
5
  SHA512:
6
- metadata.gz: 6d0b61c283bee3ccbf950c164ee96aadb8e5ff29fbc6438a2b6cd4989b7a17f8a8af244675d337a43820edca54a0eb1e0dba311308d9c59cd3abae80369ecd86
7
- data.tar.gz: d119df23b3dc249a73d5ff733dfd48c49e046c2fb932b913399412831da3e19097182b7fd1692489aeee5bb5f56927cba8f5ea6795d2bb0316d267d8abc73829
6
+ metadata.gz: ba416ba54282e7172fcd88035163fa9f809d3465c2f85f3c7fd858456d41988de8df81ec709d26ee32ed254f78d0d4429765aa561edb5cde3cbb90ba5c5ded5a
7
+ data.tar.gz: 58d7c084efe90a61fc67857c497279ada9dd739ec732bf235e21a50171624ec2f103bdda48ef33ee31f91a995af9e0969459122910398a10329696575e7d5916
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.1.0
4
+ * Refactor IRB extension to accommodate IRB 1.8.2
5
+
6
+ ## 2.0.0
7
+ * Fix core functionality for newer IRB
8
+ * Require Ruby 3.x / IRB 1.7+
9
+ * Bump display-width gem to latest version
10
+ * Remove option to disable display-width check, since it now has good performance
11
+
3
12
  ## 1.4.3
4
13
  * Fix options given to `script` so it doesn't output timing info
5
14
 
data/MIT-LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012, 2015-2021 Jan Lelis
1
+ Copyright (c) 2010-2012, 2015-2023 Jan Lelis
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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" (# =>) to display IRB results
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: Output result as comment if there is enough space left on
31
- the terminal line and `stdout` does not output more than the current terminal
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 stdin methods are patched properly to work with the rocket: The gems
47
- focuses on the often used ones
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-2021 Jan Lelis <https://janlelis.com> released under
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 = "FancyIrb makes IRB # => friendly."
12
- s.description = "A fancy IRB has a colorful input prompt and profiles rocket-style #=> return values"
13
- s.required_ruby_version = '>= 1.9.3'
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 'unicode-display_width', ">= 1.1"
18
- s.add_development_dependency 'rspec', "~> 3.2"
19
- s.add_development_dependency 'rake', "~> 10.4"
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, track_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, scanner)
88
- show_output(context.inspect_last_value, scanner)
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 = get_offset_from_irb_scanner(scanner)
94
- cols_to_show = get_cols_to_show_from_output_and_offset(output, offset)
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 get_offset_from_irb_scanner(irb_scanner)
114
- last_line = irb_scanner.instance_variable_get(:@line).split("\n").last
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_|
@@ -1,22 +1,12 @@
1
- module IRB
2
- class Irb
1
+ module FancyIrb
2
+ module IrbExtCommon
3
3
  def output_value
4
4
  FancyIrb.output_value(@context, @scanner)
5
5
  end
6
6
 
7
- alias prompt_non_fancy prompt
8
- def prompt(*args, &block)
9
- FancyIrb.handle_prompt(
10
- prompt_non_fancy(*args, &block),
11
- IRB.conf[:AUTO_INDENT] ? @scanner.instance_variable_get(:@indent) * 2 : 0,
12
- IRB.conf[:AUTO_INDENT] && IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]][:PROMPT_C] == args[0]
13
- )
14
- end
15
-
16
- alias signal_status_non_fancy signal_status
17
7
  def signal_status(name, *args, &block)
18
8
  FancyIrb.reset_line!
19
- signal_status_non_fancy(name, *args, &block)
9
+ super(name, *args, &block)
20
10
  ensure
21
11
  if name == :IN_EVAL
22
12
  FancyIrb.present_and_clear_captured_error!
@@ -24,14 +14,48 @@ module IRB
24
14
  end
25
15
  end
26
16
 
27
- class Context
28
- alias evaluate_non_fancy evaluate
17
+ module IrbExtPrompt
18
+ private def format_prompt(format, ltype, indent, line_no)
19
+ FancyIrb.handle_prompt(
20
+ super(format, ltype, indent, line_no),
21
+ IRB.conf[:AUTO_INDENT] ? indent * 2 : 0
22
+ # IRB.conf[:AUTO_INDENT] && IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]][:PROMPT_C] == format
23
+ )
24
+ end
25
+ end
26
+
27
+ module IrbExtPromptLegacy
28
+ def prompt(format, ltype, indent, line_no)
29
+ FancyIrb.handle_prompt(
30
+ super(format, ltype, indent, line_no),
31
+ IRB.conf[:AUTO_INDENT] ? indent * 2 : 0
32
+ # IRB.conf[:AUTO_INDENT] && IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]][:PROMPT_C] == format
33
+ )
34
+ end
35
+ end
29
36
 
37
+ module ContextExt
30
38
  def evaluate(*args, **kwargs)
31
- evaluate_non_fancy(*args, **kwargs)
39
+ super(*args, **kwargs)
32
40
  rescue Exception
33
41
  FancyIrb.register_error_capturer!
34
42
  raise
35
43
  end
36
44
  end
37
45
  end
46
+
47
+ module IRB
48
+ class Irb
49
+ prepend FancyIrb::IrbExtCommon
50
+
51
+ if IRB::VERSION < "1.8.2"
52
+ prepend FancyIrb::IrbExtPromptLegacy
53
+ else
54
+ prepend FancyIrb::IrbExtPrompt
55
+ end
56
+ end
57
+
58
+ class Context
59
+ prepend FancyIrb::ContextExt
60
+ end
61
+ end
@@ -3,9 +3,7 @@ module FancyIrb
3
3
  extend self
4
4
 
5
5
  def width_of(data)
6
- return 0 unless data
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FancyIrb
4
- VERSION = '1.4.3'
4
+ VERSION = '2.1.0'
5
5
  end
@@ -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: 1.4.3
4
+ version: 2.1.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: 2021-03-20 00:00:00.000000000 Z
11
+ date: 2023-10-22 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: '1.1'
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: '1.1'
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: '10.4'
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: '10.4'
75
- description: 'A fancy IRB has a colorful input prompt and profiles rocket-style #=>
76
- return values'
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: 1.9.3
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
- - 'Windows: ansicon <https://github.com/adoxa/ansicon>'
120
- rubygems_version: 3.2.3
142
+ requirements: []
143
+ rubygems_version: 3.4.21
121
144
  signing_key:
122
145
  specification_version: 4
123
- summary: 'FancyIrb makes IRB # => friendly.'
146
+ summary: Colors and rockets in IRB
124
147
  test_files: []