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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +17 -0
- data/lib/irb/autosuggestions/line_editor_patch.rb +16 -1
- data/lib/irb/autosuggestions/version.rb +1 -1
- data/sig/lib/irb/autosuggestions/line_editor_patch.rbs +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 02ad5c3a9b0166ac04a5ace310b88b4608ada72fa88d3d0a4f563817042db007
|
|
4
|
+
data.tar.gz: b68cd6b388fcdfb423ee895ed1758fdd4f8f878cc8c65faf4e45bfc8ffb7ccab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a16cf68316c28e28aa74993736e78eca09ad0f96fda3e0afb5acfc7c9d1a77ab7804abcc820e7e83055982677f3f2631a276ca3f1a536522b25db912a43a7b55
|
|
7
|
+
data.tar.gz: bbbc34eaf686fa8c425f83da67c337c06cae44584e2675419b2d8faee4f94859cc8edc3c4ca51f6535bc0496a8e353f744c0ef0c469941978072e04046feacd8
|
data/Gemfile.lock
CHANGED
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
|
|
@@ -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
|