irb-autosuggestions 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e1ec7a3ce26018f3370e751867a4c0b949978ed1642609f737686c56a7c52ec
4
- data.tar.gz: c0cdc0ec34d660207c7541f0f2b36eea14bbc316f1e8d5eb6f6127c029a862f2
3
+ metadata.gz: 02ad5c3a9b0166ac04a5ace310b88b4608ada72fa88d3d0a4f563817042db007
4
+ data.tar.gz: b68cd6b388fcdfb423ee895ed1758fdd4f8f878cc8c65faf4e45bfc8ffb7ccab
5
5
  SHA512:
6
- metadata.gz: e41c47949a5d0016e8417aa49e29f86fb8406ba634e59b7972dd287396d523fb9d8094b318ba0d6a0941b45c11618aefdc81234298edbb8a8e5180002f5d3e82
7
- data.tar.gz: 587fab5c5988e9ba7387f691d8c8a48adabb081d5be751f09b13f847a581bafed98d8f988d0e7827ce2f297c6d1c6247f7ade5b3b6470b780c2b6d7a6a9a2083
6
+ metadata.gz: a16cf68316c28e28aa74993736e78eca09ad0f96fda3e0afb5acfc7c9d1a77ab7804abcc820e7e83055982677f3f2631a276ca3f1a536522b25db912a43a7b55
7
+ data.tar.gz: bbbc34eaf686fa8c425f83da67c337c06cae44584e2675419b2d8faee4f94859cc8edc3c4ca51f6535bc0496a8e353f744c0ef0c469941978072e04046feacd8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- irb-autosuggestions (0.1.0)
4
+ irb-autosuggestions (0.1.1)
5
5
  reline
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -13,6 +13,7 @@ No need to explain. Fish-like autosuggestions for IRB — ghost text from histor
13
13
  * [Contents](#contents)
14
14
  * [Installation](#installation)
15
15
  * [Usage](#usage)
16
+ * [Configuration](#configuration)
16
17
  * [How it works](#how-it-works)
17
18
  * [Development](#development)
18
19
  * [License](#license)
@@ -43,6 +44,22 @@ irb(main):003> end <- "d" in gray
43
44
 
44
45
  Press **right arrow** (`->`) to accept the full multiline suggestion.
45
46
 
47
+ ## Configuration
48
+
49
+ Autosuggestions are enabled by default. To disable:
50
+
51
+ `~/.irbrc`:
52
+
53
+ ```ruby
54
+ IRB.conf[:USE_AUTOSUGGESTIONS] = false
55
+ ```
56
+
57
+ Or via environment variable:
58
+
59
+ ```sh
60
+ export IRB_AUTOSUGGESTIONS=0
61
+ ```
62
+
46
63
  ### How it works
47
64
 
48
65
  - Each keystroke queries `Reline::HISTORY` for the most recent entry whose prefix matches the current buffer.
@@ -6,13 +6,15 @@ module Irb
6
6
  module LineEditorPatch
7
7
  GRAY = "\e[90m"
8
8
  RESET = "\e[0m"
9
+ CONFIG_KEY = :USE_AUTOSUGGESTIONS
10
+ ENV_KEY = 'IRB_AUTOSUGGESTIONS'
9
11
 
10
12
  # Intercepts key input to accept autosuggestions on right arrow.
11
13
  #
12
14
  # @param [Object] key A Reline key event.
13
15
  # @return [Object] Returns +super+ for non-right-arrow keys, +nil+ after accept.
14
16
  def input_key(key)
15
- if right_arrow?(key)
17
+ if enabled? && right_arrow?(key)
16
18
  buffer = whole_buffer
17
19
  suggestion = find_suggestion(buffer)
18
20
 
@@ -34,6 +36,7 @@ module Irb
34
36
  def render(...)
35
37
  result = super
36
38
  Reline.core.instance_variable_get(:@output).write("\e[J")
39
+ return result unless enabled?
37
40
 
38
41
  buffer = whole_buffer
39
42
  return result if buffer.empty?
@@ -45,6 +48,18 @@ module Irb
45
48
  result
46
49
  end
47
50
 
51
+ # Checks whether autosuggestions are enabled via IRB.conf or env var.
52
+ #
53
+ # @private
54
+ # @return [Boolean]
55
+ def enabled?
56
+ case ENV.fetch(ENV_KEY, nil)
57
+ when '0' then false
58
+ when '1' then true
59
+ else IRB.conf.fetch(CONFIG_KEY, true)
60
+ end
61
+ end
62
+
48
63
  # Checks if a key event is a right arrow press.
49
64
  #
50
65
  # @private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Irb
4
4
  module Autosuggestions
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
@@ -3,6 +3,8 @@ module Irb
3
3
  module LineEditorPatch
4
4
  GRAY: String
5
5
  RESET: String
6
+ CONFIG_KEY: Symbol
7
+ ENV_KEY: String
6
8
 
7
9
  @buffer_of_lines: Array[String]
8
10
  @byte_pointer: Integer
@@ -10,6 +12,7 @@ module Irb
10
12
 
11
13
  def input_key: (untyped key) -> untyped
12
14
  def render: (*untyped) -> untyped
15
+ def enabled?: () -> bool
13
16
  def right_arrow?: (untyped key) -> bool
14
17
  def ghost_for: (String buffer) -> (String | nil)
15
18
  def render_ghost: (String ghost) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb-autosuggestions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - unurgunite