Module: Irb::Autosuggestions::LineEditorPatch

Defined in:
lib/irb/autosuggestions/line_editor_patch.rb

Overview

Patches Reline::LineEditor to display fish-like autosuggestions from history.

Constant Summary collapse

GRAY =
"\e[90m"
RESET =
"\e[0m"

Instance Method Summary collapse

Instance Method Details

#input_key(key) ⇒ Object

Intercepts key input to accept autosuggestions on right arrow.

Parameters:

  • key (Object)

    A Reline key event.

Returns:

  • (Object)

    Returns super for non-right-arrow keys, nil after accept.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/irb/autosuggestions/line_editor_patch.rb', line 14

def input_key(key)
  if right_arrow?(key)
    buffer = whole_buffer
    suggestion = find_suggestion(buffer)

    if suggestion && suggestion != buffer
      accept_suggestion(suggestion)
      return
    end
  end

  super
end